When I first asked why I wanted to do this project, in fact, this project was not in my existing development plan. A group friend just talked to me about it:
At that time, I had not decided what solution to use for the MCU. It happened that Lichuang recently had a Renesas MCU cooperation training camp, so I chose Renesas MCU as the slave master.
After in-depth research, it is believed that the MCU and RTC clocks can be canceled on the host side, and the slave LDO can be replaced with a low-voltage difference LDO of TPS79333, which will save more power.
Based on Renesas' R7FA2E1A72DFL as a slave MCU, it collects the soil humidity, air temperature, air humidity, air rain volume, atmospheric pressure, altitude, and PM2.5 of the farm environment, and can pass these collected data through LC12S (100 meters ) or Ling TR (1000 meters) is transmitted to the host. The host can view the current (data is tentatively scheduled to be transmitted once every 30 seconds) environmental data through the data collection application developed by LabView, and make a trend chart, with water pump irrigation. , has a solar charging circuit, which can achieve self-discipline and unmanned management, without the need for external power supply and external transmission cables. It can be used for weather forecasting of small weather stations, agricultural irrigation and other purposes.
I drew a block diagram by hand before, and the project was huge. The actual block diagram is as follows:
The entire system is planned to be divided into three boards. One core board is the smallest system board with RA core MCU and comes with a USB to UART download circuit. A receiving board, plugged into the host computer, is used to receive data. A base plate on which the system power supply and sockets are located. The advantage of splitting the board is that even if the base board is drawn wrong or the IO needs to be replaced, it is more convenient. The core board can be moved to the next base board.
The 18V solar panel is directly connected to the solar charging chip. The solar charging chip charges a 18650. From the battery diagram, I know that I used two TPS79333, one is dedicated to the MCU and LC12S (100 meters) or Ling TR (1000 meters). The power supply is 3.3V, one is used to power the sensor, so that the sensor is powered only when the sensor is needed, saving power. It is worth noting that the PM2.5 sensor requires 5V power supply. It and the water pump share the 5V from the SX1308 boost chip. The buzzer directly uses the 18650 power supply.
The core board is relatively simple and is the smallest system of RA. It mainly consists of download circuit, power supply, reset circuit, crystal oscillator, USB to serial port circuit and derived pins.
The pins can be yellow like mine for ordinary IO, black for GND, and red for VCC, which is easier to distinguish and looks better.
Two line caps are also required when burning.
One is the startup pin P201, which is connected to pull-up during normal operation and pull-down during downloading.
One is the VCC (MCU power supply) voltage selection, generally 3.3 is sufficient.
The receiving board is also very simple, with only a USB to serial port circuit and a 5V to 3.3V LDO, mainly with reserved jumpers.
The CS pin works at low level, and is in sleep mode when it is at high level or floating.
SET pin low level configuration mode, high level working mode
How to configure it is described below.
The receiving module has reserved pads for direct soldering and 2.0mm HDR mother pads. It is recommended to solder 2.0mm HDR.
USB-C is reserved and does not need to be soldered.
The receiving board also requires 3 strip line caps for configuring the working/configuration mode and working/sleep mode, as well as the power supply of the transceiver module
The base plate integrates solar charging circuit, boost circuit, buck circuit, MCU base, sensor socket, buzzer, antenna, etc.
Since the solar panel uses 18V, the wiring of the charging circuit should be as thick as possible, or copper should be laid directly. Note that the larger capacitor comes first, and the smaller capacitor is closer to the chip.
The soil sensor, rain sensor, and PM2.5VOUT terminal are all analog signals, so ensure that these three signals are laid out first. Try not to drill holes for these three signals, and it is best to wrap these three signals with ground. Reduce distractions.
The two lead-out pins on the core board must be of correct size and should not be misaligned.
Other signals are less important as long as they are not shorted.
If you need to use an external antenna, solder the antenna pin to the external antenna solder joint.
LC12-S comes with an onboard antenna. If you need an external antenna, you need to disconnect the magnetic beads connected to the antenna.
Only one solder is required for the inductor and current sensing resistor at the solar power station.
It is recommended to use white for PCB color. It not only looks good, but also does not absorb heat when used outdoors. The core board can also be replaced with black.
In this project, the e2 studio environment is used to write and compile the code. The code is burned using RA's serial port burning tool. For specific operations, please see the attachment: RA2E1RA2L1 Getting Started Guide.pdf
No need to go into details here!
Please see the attachment for the code source code: code.zip
See the attachment for code burning: PRO.hex
The IOs that will be used are basically marked on the base board.
There is an LED light controlled by P104 GPIO on the core board
P212 P213 is used as the charging and charging completion detection pin of the solar charging chip.
P207 is used as GPIO to control the enable of 5V boost.
P206 is used as a GPIO to control the switch enable of the water pump MOS tube.
P201 is used as GPIO to control the buzzer sound.
P208 is used as a GPIO to control the 3.3V power supply enable of the sensor.
P100 P101 communicates as a serial port and wireless transmission module
P409 is used as a GPIO to control the sleep low power consumption and working mode of the wireless transmission chip.
P001 serves as an ADC to detect the voltage of the soil moisture sensor.
P000 is used as ADC to detect the voltage of the rain sensor.
P015 is used as ADC to detect the voltage output from the photovoltaic panel.
P400 P401 as IIC communication with GY-39 all-in-one sensor
P500 is used as a GPIO to control the built-in LED light enable of the PM2.5 sensor, and P002 is used as an ADC to detect the output voltage of the VOUT pin of the PM2.5 sensor.
P014 is used as ADC to detect the voltage output by the battery.
The above configuration needs to be configured in the e2 studio pin settings:
All GPIOs are configured with low level default by default
Among them, the P212 and P213 pin input modes for reading the solar charging status need to configure the input internal pull-up.
LED is connected to P104.
The buzzer is connected to P201.
Simple IO control can be encapsulated into functions.
First of all, know that the hardware has two resistor voltage detection, otherwise the MCU will be damaged if a large voltage is connected to the ADC.
These two resistors have been calculated
Take an example, the maximum voltage of the battery is 4.2V, then the maximum voltage calculated by dividing the voltage is only 3.26V, then the minimum voltage is 2.489V at 3.2V
Then you can use these two voltage differences to back-calculate the battery voltage:
(Current ADC voltage * battery full voltage 4.2) / ADC voltage at full voltage.
However, this calculation is linear. The actual battery power calculation is not linear. Generally, the front 4.2~3.7V is more durable, and the back 3.7V loses power quickly. Therefore, only the voltage is calculated here and the battery power prediction is not written.
The same goes for solar panels.
GP2Y1010AUOF是日本夏普公司开发的一款光学灰尘浓度检测传感器。此传感器内部成对角分布的红外发光二极管和光电晶体管,利用光敏原理来工作。用于检测特别细微的颗粒,如香烟颗粒、细微灰尘。依靠输出脉冲的高度来判断颗粒浓度。
就是说给LED亮,然后AD值返回MCU用AD值检测粉尘大小,这么个原理。
夏普GP2Y1010AU0F灰尘传感器价格较便宜,只能检测出室内空气中的灰尘和烟尘含量.并不能测出所谓的PM2.5浓度,然而现在市面上有好多红外发光二极管的传感器都称自己是PM2.5传感器,能测PM2.5的值,其实并不是,真正能测PM2.5浓度的是那种上百的激光传感器,这种红外的连PM10都测不了,只能用来玩玩,或者大概描述空气质量的等级而已,经我多次实验,发现这传感器显示的灰尘浓度与网上公布的AQI空气质量指数比较接近,跟真实的PM2.5浓度有很大的区别,这测出的灰尘浓度其实就是所有不同直径的颗粒物总和,里面包含了PM1.0,PM2.5,PM10。
不过这里呢就当PM2.5传感器使用了,下次升级版搞个真正的PM2.5传感器。
主要我们需要了解传感器内部的结构:
然后是传感器的引脚:
接着是输出电压对应的颗粒物浓度:
还有一个电路参考图:
这个电路图要求V-LED 即1脚,需要在VCC中串一个150欧电阻以及一个220uF的电容。
脉冲时间0.32ms的要求,以及0.28ms后数值读取才会稳定,读取最小周期是10ms。
那么查看我们底板PM2.5部分电路图中便是如下:
其中需要注意的是第三脚的LED脚,在内部是这样接的:
因此我们需要给一个低电平,内部的PNP管才会导通,内部LED才会亮,而我们外部接了一个SS8050PNP二极管到地,并且加了上拉10k,那么我们在P500口的时候,实际上只需要给高电平,LED就会亮
理清楚关系后就可以写代码了。
还是比较简单的,首先我们把P500拉高,那么LED就是亮了,等待280us,等待VOUT数值稳定,然后启动ADC去读取VOUT电压值,等待一段时间后关闭P500,然后进行AD读取数值与颗粒物数值换算。
这两个传感器类似,原理就是带有一系列裸露铜走线的感应垫一起用作可变电阻器(就像电位计一样),其电阻值根据其表面的水量而变化。
当没遇到水的时候,他们是3.3V的高电压,有水接触后会慢慢电压变小
实际上就是读取ADC 然后判断是否有雨,土壤是否干燥等,比较简单
资料查看附件GY39使用说明v1.pdf
GY-39 是一款低成本,气压,温湿度,光强度传感器模块。工作电压 3-5v,功耗小,安装方便。其工作原理是,MCU 收集各种传感器数据,统一处理,直接输出计算后的结果,此模块,有两种方式读取数据,即串口 UART(TTL 电平)或者IIC(2 线)。串口的波特率有 9600bps 与115200bps,可配置,有连续,询问输出两种方式,可掉电保存设置。
我们用的是IIC模式,因此需要图中间的跳线设置:
IIC协议的信息如下
我们配置IIC地址如下
另外还需要注意,此模块速率不能超过40khz,因此还需要到IIC配置代码中设置:
把速度降到40khz或以下,模块才能正常工作。
IIC通讯较简单,就是发送IIC寄存器,然后要读取的位数,这里分开两部分,因为光照的长度较长。
发送0x04,读取10位,返回数值后换算出压强温湿度海拔,发送0x00,读取4位换算出光照
对应的电源IC的IO
注意的是PM2.5也是用5V,使用5V建议加延迟以等电源稳定
使用传感器前开启电源即可
控制逻辑是:当我们雨水传感器检测到有雨就不浇水,没有雨并且土壤干燥,那么就浇水。
浇水前先打开5V电源,并且蜂鸣器提示,以免被溅湿
浇水的时候会每隔一秒检测一次土壤的ADC,如果土壤ADC值低于某一个电压(这里是1.5V),即水已经湿润土壤了,那么就停止水泵,关闭5V电源,并且跳出这个循环,那么浇水就完成了。
串口输出按照规定格式输出,见10.2章节中上位机的匹配字符
参数 = 数值 单位
注意空格
串口不建议发送中文,否则上位机会乱码
GY-302实际上是BH1750FVI芯片集成的传感器模块。
BH1750FVI是一种用于两线式串行总线接口的数字型光强度传感器集成电路。这种集成电路可以根据收集的光线强度数据来调整液品或者键盘背景灯的亮度。利用它的高分辨 率可以探测较大范围的光强度变化。(1lx~65535lx)。
具体查看附件:BH1750FVI.pdf
这颗芯片最核心的内容如下三张表
我们可以看出,当ADDR高电平时,IIC地址(7bit)为1011100(0x5c),低电平为0100011(0x23),我这里使用低电平。
那么master1配置为0x23。
IIC指令中,我们需要了解一个是开机指令00000001(0x01),还有一个是一次性高精度模式00100000(0x20),此模式下看表二知道,读取数据时间需要120ms,精度为1个lx。
那么我们就知道我们的代码怎么写了。
打开IIC总线后先开机写入0x01,然后写入0x20模式,等待120ms后再写入0x47读取地址,然后马上读取返回的数据。
数据处理如下
则代码如上。
接线一览
亚克力另需六角铜柱 M3*25 4个
直接插入pin对pin
18650锂电池,左负右正
GY-39 pin对pin
pm2.5传感器杜邦线连接
雨水和土壤传感器杜邦线+301座连接,不分正负
外置天线SMA-KE座连接,无线模块插入2.0mm母座或直接焊接(推荐母座,方便拆卸)
天线焊盘需要连接到模块上
上负下正,注意电源不要接反
301座连接,上正下负,不要接反
本章是LC12S 100米 通讯(2.4G)的设置方法,与灵TR 1000米 通讯(433Mhz)二选一即可
首先把收发模组插上接收器
插上后电脑设备管理器中会多出一个COM口,点击工具的打开端口,如上图
我这里是COM10,因此选中COM10,确保波特率9600,USB模式A,再点击上方的【打开端口】按钮
打开可以点击【查询设置】和【版本读取】,下方出现设置参数即证明可以通讯了。
右边设置如上参数,组网ID和RF信道两张模块需要相同才能互通,这里我默认设置就好了,波特率要选择9600。
选择好参数后点击右边生成命令字后下方会生成发出命令
点击右边【发送】后会返回消息,即表示设置成功,然后可以拔掉接收板了。
以上是配置一个的方法,需要两个模组都要配置。
本章是灵TR 1000米 通讯(433Mhz)的设置方法,与LC12S 100米 通讯(2.4G)二选一即可
首先把收发模组插上接收器
根据规格书,附件:灵-TR无线收发模块V1.7.pdf
CS跳线接工作,SET跳线先不接,VCC跳线接3.3V
然后插上计算机
然后再把SET跳线接到配置脚
打开附件:灵-TR指令生成助手.exe
点击打开端口出现COM后再点一次打开端口,点击读取设置和版本,然后设置两片灵TR的组网ID和RF信道即可,波特率9600.
灵TR和LC12-S不一样,没有板载天线,因此需要手动焊上去。
推荐一种大长天线
还有官方的弹簧天线(会送)
以及官方的PCB天线
上位机本来想使用LabWindows设计,不过看到B站@今天烧板子了吗 上恰好有LabView现成的串口工程,开源地址点我
因此正好拿这位UP的工程魔改一下。
工程在哪?
附件:LabView农田数据无线采集系统(瑞萨MCU版).zip
工程项目名为:农田数据无线采集系统(瑞萨MCU版).lvproj
程序框图名为:__Aknice.vi
串口接收框图如上图
串口选择
在端口接收到字节大于等1,即有接收到字节
或者可以用不等于0代替
接收到第一个字节开始,延迟200ms,以接收剩下的所有字节
实际上可以计算出来,9600波特率接收这么多字节需要多少时间,这里200ms是肯定能接收完的时间,实际还可以缩短此时间。
数据接收后存在读取缓冲区
缓冲区输出到显示控件
将输出到显示控件的字符串进行字符串匹配
使用匹配字符串控件,路径如下
字符串匹配内容为正则表达式内内容,此处为 【PM2.5 = 】,注意空格
匹配到字符串后输出字符串后数值,即为子字符串之后,并输出到显示控件
然后把读取到的数值输出到图表显示控件
在如上路径中找到 【分数/指数字符串至数值转换】
这样转出来的数值才是浮点形式,选择其他转换出来是整形。
如上重复把所有接收数据整理
制作完后可以测试数据,上图为测试数据,不是实际在板上的收集数据。
打开工程项目后右击程序生产规范–>>新建–>>应用程序(EXE)
选择类别框中的信息,右侧红圈处为将要生产的exe的文件夹名和文件名。
选择类别框中的源文件,将软件打开的默认界面添加到启动VI项,其余添加到始终包括项。一般默认始终包括下的非VI文件会生成到data文件夹下。
这里只要把.vi文件添加到这里即可,因为只有一个vi项目。
上面的启动VI指:启动exe的时候vi会立即打开的界面。
下面的始终包括指:exe打开后该区域文件不会自动打开,需要其他vi调用才能打开。
这里可以选择生成的图标,需要.ico格式
点击右下角生成即可生成.exe可执行文件
由于附件巨多,因此需要找到:农田数据无线采集系统(瑞萨MCU版)上位机.rar
解压后打开【__Aknice.exe】即可。
系统对接收数据有上电顺序要求以及前期配置要求。
使用上位机前需要确认在8章节中接线正确以及9章节中无线通讯配置正确,并且RA MCU已经烧录了代码。
使用前确认发射端数据底板+核心板和接收板目视距离(中间无障碍物)不得超过LC12S(100米)或灵TR(1000米)。
确认以上步骤后请先打开底板主供电开关,此时核心板上LED灯有闪烁,证明数据底板正常工作。
接着将接收板插入计算机USB接口,此时打开计算机管理中设备管理器的端口选项卡,找到刚刚插入的接收板(如果不确定上哪个COM口可以拔掉后看看哪个COM没了再插上)
例如本人的是COM11
选择好后选择9600波特率,然后点击打开串口
上位机正常使用如下图,设计有能显示出接收板LC12S(100米)或灵TR(1000米)的串口接收数据的显示窗口、把接收的数据分类成当前(30秒内)的显示控件、能选择接收板的串口选择选项卡、选择波特率的选项卡、串口打开按钮以及各个环境变量的波形图标,可以查看变化趋势和历史记录。
数据底板外壳使用立创EDA专业版绘制
只有一个底壳,请查看附件:3DShell_数据采集底板_B.stl
3D打印自己打印
打印外壳实物如上
数据底板面板使用立创EDA专业版绘制
面板打印选择嘉立创面板打印服务
面板实物图如上
裸板
外壳+亚克力+所有元件接入
自律条件为:
只要在太阳下山前,太阳能充电能把电池充满即自律
测试前电池电压:3.26V 几乎没电状态
充电时电流:0.584A 检流电阻为0.06欧,因此充电电路配置的充电电流为 Ich=0.12/0.06=2A
太阳能板输出电压为:19.67V
因此可以算出电池充电功率约为10W,那么与电池端配置的充电电流2A接近
充电时,电池,充电芯片,充电电路电感,太阳能板发烫,注意散热。
约3小时后充满,此时电池电压为4.16V。
如果早上出太阳开始充,应该不到中午都可以充满了。
测试结果:系统自律。
如果想要电池充快点,把太阳能板吃满,可以再加一路检流电阻和电感,可以去到4A 20W
LC12S(100米)测试就不测了,直接上大家伙(1000米)把。
放在我家阳台外测试,接上所有传感器和外接设备
为保护隐私就不拍小区和自己家了
为方便分析数据,不用上位机,用串口工具查看,这里直接用arduino的串口工具了
上图1楼(阳台底下)测试数据,无遮挡30米:
无问题
上图小区某路口测试数据,树木遮挡100米:
无问题
上图小区门口,无遮挡250米:
无问题
上图小区门外江边,隔了一条马路,树木遮挡400米:
无问题
上图小区门外江边,隔了两条马路,树木、建筑、电网变压器遮挡500米:
能接收,但乱码
见视频
16.2是有障碍500米,视频是无障碍目视1000米
测试结果:PASS
见视频
见视频
工程内容丰富充实,手把手教学,总结就是上面我写的的东西。
It is my biggest project in the first half of 2022. I received the task from April 11 to May 6 and needed to complete it all. The time is tight and the task is heavy. Having never used Renesas MCU, I ( They?) The task force (only me...) overcame difficulties and faced them head on. From GPIO to IIC, I provided a solid guarantee for my own development project.
Hardware is also an important part of it. After I (hardware) received my own (software) demand, I quickly implemented it, practiced self-discipline (referring to playing CSGO before the express delivery), and cooperated with me (software) to modify it. (Hardware) and I (Structural) are satisfied with the appearance and software architecture.
Liu Gong fully affirmed the progress of his development in the past half month and unswervingly used jlc's PCB and panel printing coupons, and achieved new results in appearance (referring to the acrylic panel)
It's like writing an essay. . .
GY-39 is a very powerful sensor that can measure humidity, atmospheric pressure, etc.
Currently, the time axis of the host computer is not added. When receiving a piece of data, it will be +1.
But it can be made to do the x-axis based on time
In addition, soil, rainwater and charging status can only be seen through the serial port. Can an LED light or display window be made to display the current charging status, rain status (we can put weather pictures), etc. to intuitively display the current status.
The function is easy to implement, and this should be the simplest one.
The current code uses the front-end and back-end sequential execution method, which while(1){}
continuously loops its own functions and basically does not consider the time required to execute each function. In most cases, there is more or less millisecond-level delay waiting in the function.
For example, this code uses the front-end and back-end sequential execution method. The code is as shown above.
Advantages: For beginners, this is the easiest and most intuitive program structure, the logic is simple and clear
Disadvantages: Low real-time performance. Since each function has a delay of more or less milliseconds, even if it is 1ms, it will cause different execution intervals of other functions. When the complexity of the program logic increases, it will cause confusion in the brains of subsequent maintenance personnel, making it difficult to understand the running status of the program.
Therefore, it is necessary to introduce the time slice theory
Advantages: The task function does not need to be executed all the time, and there is an interval (such as button presses). Generally, software anti-shake is required. Beginners usually delay about 10ms before making a judgment, but 10ms is a huge waste of CPU resources. The CPU can handle many other things during this time)
Reference (no pointers):
Sometimes, after it rains, there are still raindrops on the raindrop sensor, which will not dry out immediately, but the presence of raindrops will affect our judgment of the current rainfall. Although it is only drizzling, there are many raindrops accumulated on the raindrop sensor. , so a cleaning function is needed to clean the raindrop sensor regularly.
This project can only transmit data up to 1000m without obstacles, but using LoRa to transmit data can transmit data further. LoRa can transmit 10km+ when there are obstacles. Try changing the wireless module to LoRa.
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet