【RVB2601 Creative Application Development】Environmental Monitoring Terminal 08-Work Submission
[Copy link]
Distributed environmental monitoring terminal based on CH2601
Author: sipower
- 1. Project Background ( 100-200 words )
With the development of industry, environmental problems are becoming increasingly serious. In addition to conventional governance methods, real-time monitoring of the environment is also a necessary means of managing the environment. This creative work uses the RVB2601 development board to implement an IoT terminal for environmental monitoring . The terminal is deployed at multiple points in public places such as roads, communities, and parks to form a distributed monitoring network. The test results are uploaded to the cloud server via WiFi , which can be used by the environmental department for big data statistics and provide support for environmental governance .
- 2. Brief introduction of the work ( 100-200 words) + photos of the work
This work uses the microphone on the RVB2601 development board to collect noise data, which is quantified and converted into real-time noise levels. A temperature and humidity acquisition module is connected to the serial port to read temperature and humidity data in real time. The collected data can be displayed on the OLED screen, and a horizontal dynamic indicator bar is designed to intuitively display the real-time data of the noise. Connect to Alibaba Cloud Internet of Things through the onboard WiFi module to enable real-time viewing of monitoring data on the web. A special indicator port is designed, which can be controlled through the cloud. In practical applications, this module can be installed in existing street lights, and the street light switch can be controlled through the indicator port to achieve cloud-based intelligent control.
Figure 1. Photo of the work
- 3. System Block Diagram (Combined Graphics and Text)
The entire system block diagram of the terminal is as follows . The basic functions include: noise collection , temperature and humidity collection , OLED display results, WiFi upload and download , cloud management, remote light switch . The reserved extended functions include: light intensity detection, air quality detection, satellite positioning data analysis.
Figure 2. System Block Diagram
- 4. Functional description and analysis of each part (combined with pictures and text)
The functions currently implemented in this work mainly include: noise collection, temperature and humidity collection, OLED display, cloud connection, and web interface monitoring. The following are detailed introductions.
1. Noise collection
Noise collection uses the microphone on the RVB2601 development board to collect surrounding sounds, record the maximum value per unit time, and use the quantified data to represent the environmental noise level.
In terms of hardware principle , RVB2601 connects to ES7210 ADC chip through I2S and I2C bus to realize audio signal sampling of silicon microphone. The configuration of ES7210 is completed by I2C interface , and the conversion data of ES7210 is read by I2S interface .
Figure 3. Noise collection circuit
The software driver design uses the CODEC codec library, mainly using the AD input channel. Based on the official routine ch2601_ft_demo , the recording code is intercepted. Because this application only needs the sound amplitude, the code is greatly deleted and modified, the cache is reduced, and only one sampling cycle is retained. After each sampling is completed, the maximum value of the audio data within this cycle is calculated, and this result is used as the real-time volume data to be output. This data also needs to be calibrated and quantized into the final decibel value. It is a pity that the decibel meter was not borrowed, and the final data quantization was not achieved. It can only be simply divided by a coefficient to show the effect. The noise value collected from the serial port output is as shown in the figure below.
Figure 4 , serial port output volume
2. Temperature and humidity collection
The RVB2601 development board used this time does not have a temperature and humidity sensor. To obtain these two parameters, an external detection module is required. After checking the resources at hand, I found that the module I collected from the previous review of "Anxinke UWB Indoor Positioning Module" can output temperature and humidity data through the serial port, and the software interface is relatively simple, so I selected this module as the data source.
Figure 5. UWB module
From the GPIO multiplexing table of CH2601 , we can see that almost every IO port is used. After careful study of the OLED program, we found that the driver code did not use the SPI interface, but directly used the SPI bus simulated by the IO . This gave me the opportunity to replace the occupied serial port pins with other IO ports. Considering that my work basically does not use RGB tri-color lights, I decided to transfer two of the IO ports of this light to OLED , so that the transmit and receive pins of UART1 can be vacated .
Figure 6 , Schematic diagram after transformation
In terms of software design, the first thing was to change the OLED driver, reset the pin definition, recompile and download the code after changing it, and the program worked without any problems. Then I wrote the UART1 driver. I encountered many problems in the process, but finally used the interrupt collection timeout mechanism of the HAL library to achieve the expected goal.
3. OLED display
The RVB2601 development board has a built-in monochrome OLED display with a resolution of 128*64 , and the open source LVGL GUI library has been ported to this platform. I have never used the LVGL GUI library before, so I will learn and use it this time, so I will give it a try.
First, I drafted the interface. I plan to display 5 lines of information on the screen . The first line is the title, which can be displayed directly using labels. The second line is the temperature. The left field does not need to be updated, and the right field needs to be refreshed regularly. All of them are also displayed using labels. The third and fourth lines are humidity and noise levels, respectively, and the same method is used to display temperature. The fifth line plans to make an indicator bar to dynamically indicate the real-time amplitude of the noise, which is more intuitive to view.
Figure 7 , interface draft
I encountered various problems during the actual design. The first was how to display Chinese characters. After searching, I learned that I had to make and add built-in fonts myself. I read several tutorials and found that it was very complicated. In order to speed up, I decided to skip the Chinese display and use English instead.
The next problem is that the default English font is " LV_FONT_MONTSERRAT_14 ", which is relatively large. If it is displayed in 5 lines, it looks too crowded. By changing the configuration item, the font " LV_FONT_MONTSERRAT_12 " is relatively better. I also tried to change it to a smaller font, which was a bit horrible and could not be distinguished. It looked a bit like the Martian language in the movie.
When I was making the title display, I saw that LVGL supports scrolling display. In order to reflect my learning results, I changed the originally planned two-word title into a sentence, let it scroll at the top and display more information.
When setting the temperature display, I need to display floating point numbers. I wrote the code in the usual way and found that it could not be displayed normally. Then I checked the information and found that it was set to not support floating point mode by default in order to improve efficiency. I originally wanted to check the manual to change it to support floating point mode, but later I saw someone used a better method to solve it. That is, format the floating point number into a string first, and then display it as a string. I followed this method and successfully solved the problem.
The last thing to be implemented is the noise indicator bar. After repeatedly consulting the manual, I finally decided to use the progress bar " LV_BAR " control design. After directly following the simple routine in the manual, I found that both ends were rounded, which was not the type I liked. Then after a long search, I found a solution. After repeated modifications and debugging, I finally built the interface framework.
Figure 8 , display effect diagram
4. Cloud connection
The RVB2601 development board is equipped with the high-performance and secure WiFi4 chip W800 from Lianshengde . W800 is connected to CH2601 via the SPI port . W800 has been burned with AT -based WiFi transparent transmission firmware by default and supports the Alibaba Cloud platform. Developers can quickly implement IoT application scenarios based on AT network commands.
First, prepare the Alibaba Cloud IoT platform. Log in to the Alibaba Cloud IoT Studio platform. The address is as follows.
https://account.aliyun.com/login/login.htm?qrCodeFirst=false&oauth_callback=https%3A%2F%2Fstudio.iot.aliyun.com%2Fproject%2Fa123jX2VXQqAfhnk%2Fdevices%2Fa1iO8mTqhOz%2Fdev_001%2F1
Click the "Product" column on the homepage to enter the product list, then click "Create Product", enter the information you want, click the confirmation at the bottom, and the product is created. Enter the product management interface and add product attributes. The identifier is an important handshake information for the communication between the microcontroller and Alibaba Cloud. It is best to set it to be concise and easy to remember for easy debugging during programming. My product mainly collects three parameters: temperature, humidity, and noise level, and sets an indicator light, with a total of four attributes. The data types and data definitions of these parameters must also be consistent with those in the microcontroller program. After the product is set up, add the device. After completion, you can view the relevant certificate key in the device information interface, as shown in the figure below. This will be used to connect the microcontroller and Alibaba Cloud.
Figure 9. Device information
At this point, the settings of Alibaba Cloud are complete. You can view various configurations through different interfaces. You can become proficient in using them after getting familiar with them. The entire operation interface is very user-friendly.
Then comes the microcontroller program writing. I made the changes based on the ch2601_webplayer_demo sample project. By adding the control function of connecting to the cloud platform in the w800_api.c file, the callback function of receiving data can realize the IoT connection and data transmission and reception. For details, please refer to the code in the attachment, which will not be repeated here. Here is a special note, because the information sent back by the cloud is in JSON format, it is necessary to add the cJSON library in the project for decoding. The following figure shows that the connection to Alibaba Cloud is successful and the data is updated from the cloud.
Figure 10. Cloud connection successful
5. Web interface monitoring
To demonstrate the effect of environmental monitoring, I designed a web application on the Alibaba Cloud IoT Studio platform to display temperature, humidity, and noise levels using dashboards and line charts. I designed a button and status indicator for the indicator light so that it can be turned on and off in the cloud.
The specific development process is as follows: Log in to the Alibaba Cloud IoT Studio platform at the following address.
https://account.aliyun.com/login/login.htm?qrCodeFirst=false&oauth_callback=https%3A%2F%2Fstudio.iot.aliyun.com%2Fproject%2Fa123jX2VXQqAfhnk%2Fdevices%2Fa1iO8mTqhOz%2Fdev_001%2F1
Click " New Web Application " on the homepage , fill in the required information in the pop-up dialog box, and click the confirmation button at the bottom to create the application. After the application is created, enter the editing interface. The specific functions of each part are shown in the figure. Design the page according to your needs.
Figure 11. Page design
If you are not familiar with this design rule, the official also has a detailed guidance tutorial, see the link below.
https://help.aliyun.com/document_detail/141613.html
Add components as needed, and manually fill in the coordinates and size of each component to make the arrangement more neat. I set up dashboards for temperature, humidity, and noise level to display real-time data, and set up line charts to show the data changes in the last hour. Set up a button to turn the indicator light on and off, and use an icon to show the status of the indicator light.
Figure 12. The set interface
Next, configure the data source for each component . Take the temperature dashboard as an example, select it, then click Configure Data Source on the right, select the target product, device, and attribute in the pop-up dialog box, and you can associate the component with the specific device parameters . During the configuration process, you can click the preview button in the upper right corner at any time to view the design effect. After configuring all components, you can choose to publish. The effect of my application page is as shown below, and all parameters are displayed.
Figure 13 , page rendering
If there are multiple monitoring terminals, you can group them together and display the groups side by side, which is a distributed monitoring system.
The links are as follows:
https://download.eeworld.com.cn/detail/sipower/623518
- 6. Video Demonstration (Video Introduction + Link)
This work shows several different videos of the results during the design process, which are linked below.
1. The effect of colorful breathing light
https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/3890563388320980992/1649070469990/f4ee2f8055053c901c341b0b137ae8ee.mp4
2. Cloud control development board LED light switch
https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/3890563388320980992/1649159094646/6492d5b42765f70bb8422b9e510771c8.mp4
3. Dynamic display effect of the interface
https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/3890563388320980992/1649592613590/6fc5b63d2371cd9ad821bc7efc3eb63d.mp4
4. Music light bar effect
https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/3890563388320980992/1650183724917/398df15910dd3e353262460f73a36173.mp4
5. Display volume changes in LVGL
https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/3890563388320980992/1650183742370/83e0fe35d8b0d7b46ca455feaa5f3993.mp4
6. Data collection and display of temperature and humidity
https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/3890563388320980992/1650647426254/1c18d9ea0e2063c1da4d5ff9fb17f08e.mp4
7. Display of completed works
https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/userFiles/3890563388320980992/1650900845446/8f34e6a49992ecda1979a2433c647019.mp4
- 7. Project Summary (Project Text Summary + Post Sharing Link Summary)
This work took about a month of spare time to design. Thanks to Pingtouge for providing the development board and enthusiastic technical support, and thanks to EEWORLD for providing the display platform. Through the design of this work, I learned about RISC-V and felt the progress of domestic chips and development platforms. I believe that one day, we will make domestic chips play an irreplaceable role in various parts of the world .
During the design process, I posted on Pingtou Ge and EEWorld to share my experience summary. The links are summarized as follows:
Environmental Monitoring Terminal 01- Unboxing and Design of Colorful Breathing Light
https://occ.t-head.cn/community/post/detail?id=4031491954960900096
https://en.eeworld.com/bbs/thread-1198865-1-1.html
Environmental Monitoring Terminal 02- Connect to Alibaba Cloud to control LED lights
https://occ.t-head.cn/community/post/detail?id=4031864498838708224
https://en.eeworld.com/bbs/thread-1198899-1-1.html
Environmental Monitoring Terminal 03- Using LVGL to Design Interface
https://occ.t-head.cn/community/post/detail?id=4033682146182443008
https://en.eeworld.com/bbs/thread-1199385-1-1.html
Environmental monitoring terminal 04- sound collection and dynamic light bar display
https://occ.t-head.cn/community/post/detail?id=4036161692982980608
https://en.eeworld.com/bbs/thread-1200134-1-1.html
Environmental Monitoring Terminal 05- Temperature and Humidity Collection and Display
https://occ.t-head.cn/community/post/detail?id=4038106809214054400
https://en.eeworld.com/bbs/thread-1200906-1-1.html
Environmental Monitoring Terminal 06- Synchronize data to Alibaba Cloud
https://occ.t-head.cn/community/post/detail?id=4038813387730259968
https://en.eeworld.com/bbs/thread-1201066-1-1.html
Environmental Monitoring Terminal 07-Web Application Design
https://occ.t-head.cn/community/post/detail?id=4039168982010368000
https://en.eeworld.com/bbs/thread-1201211-1-1.html
Here I share some experience gained in the design process, hoping it will be helpful to everyone.
1. Insufficient code capacity
When I added the lvgl library and the wifi library to the project at the same time, the compiler would prompt that the compiled code was out of range, which means that the user code space was insufficient. I carefully studied the default configuration of the flash and found that out of a total of 512KB of capacity, only 256KB was allocated to the user program , leaving a lot of space for the upgrade cache. In my work, there is no plan to do OTA upgrades, so the user space can be expanded. The specific operation is shown in the figure below.
Figure 14. Modify the partition table
Open the config.yaml partition table file, expand the prim user space, and change the specific amount according to your needs, just don't exceed the effective range of flash . I changed it to 384KB . misc is to upgrade the cache space, and the starting address should also be changed to the corresponding new address. Remember to save after changing. Open the gcc_flash.ld file, change the flash length to the same as config.yaml , and save. After changing these two files, we have more space to store code.
2. The function definition cannot be viewed in CDK
In CDK , right-click a function and select " goto declaration " to view the function definition. If you cannot jump after clicking, it is generally because the project is not automatically parsed. You can do it manually:
Click the menu bar Project -> parse all project , wait for the progress bar in the Project View to end, use the " goto declaration " function again, and then you can view the function normally.
3. How to obtain the cJSON library officially provided by Pingtou Ge
When connecting to the Internet of Things, since the information sent back by the cloud is in JSON format, the cJSON library is needed to decode it. I recommend a very easy way to obtain the cJSON library officially provided by Pingtou Ge . On the CDK welcome page, the first example is the " WiFi Smart Light Control" example. Download it without compiling, and you will find that there is a cJSON library in the " __workspace_pack__ " folder . Then add the cJSON library to the project in the library management .
4. Displaying floating point numbers in LVGL
When setting the temperature display, I need to display floating point numbers. I wrote the code in the usual way and found that it could not be displayed normally. Then I checked the information and found that in order to improve efficiency, the default setting of LVGL transplanted by Pingtou Ge was not to support floating point mode. I originally wanted to check the manual to change it to support floating point mode, but later I saw someone used a better method to solve it. That is, format the floating point number into a string first, and then display it as a string. I followed this method and successfully solved the problem.
5. Pay attention to the number of " \ " in the edited report string .
When editing a cJSON string, one of the messages is:
snprintf(msg_buf,80,"{\\\"temp\\\":%.1f,\\\"humi\\\":%.1f,\\\"noise\\\":%d,\ \\"led\\\":%d}",res_data.temp,res_data.humi,res_data.noise,res_data.led);
I didn't pay attention at first and typed one less key, which resulted in an error in data upload. It took me a long time to find the answer.
环境监测终端_作品提交.docx
(1.84 MB, downloads: 4)
|