INFORMAZIONI SU QUESTO ARTICOLO

Cita

Introduction

In recent years, with the rapid development of China's industry, intelligent agricultural greenhouses have introduced advanced modern industrial technology. The farming methods in rural areas have been greatly improved from the original pure human labor to today's semi mechanized farming. Farmers can work more labor-saving and obtain more benefits at the same time. China is a large agricultural country. It can be learned from the seventh national census that China's current population is about 1.41 billion. Therefore, China has great pressure on agriculture. Through continuous research and development, the hardware quality level and supporting capacity of intelligent agricultural greenhouses are improved [1].

According to the status of the development of China's intelligent agricultural greenhouse and China's agricultural personalized form of expression, have a higher degree of integration, a wider range of application of intelligent agricultural greenhouse system is more conducive to promote the development of China's intelligent agricultural greenhouse [23].

Intelligent agriculture has created opportunities for the development of agriculture in China. The intelligent agricultural technology will rely on the interconnection of all things under 5G to diagnose the crop growth environment and growth conditions, such as detecting the environmental temperature, humidity, light intensity and other information, and then put forward strategies to make the intelligent agricultural system adjust a more appropriate temperature and let unmanned aerial vehicles spray fertilizers and pesticides.

Overall scheme design

The STM32F407 system uses DHT11 module, 2 million-pixel OV2640 module, photosensitive sensor, 4.3-inch TFTLCD screen, SD card, ATK-ESP8266 serial port to WiFi module, infrared detection module, light source adjustment circuit and buzzer in hardware [4].

Under normal conditions, DHT11 collects temperature and humidity, the photosensitive sensor collects light intensity, updates the display on the LCD screen in real time, and sends the data to the server through serial port 3 to WiFi [5]. When it is detected that the light intensity is less than a certain threshold, the light source adjustment circuit is called to automatically adjust the light source to improve the light intensity. When other people or animals break into the greenhouse, the infrared module monitors, transmits the detected signal to the STM32 development board, which responds, calls the active buzzer for alarm, OV2640 captures this image for storage, displays the latest captured image on the LCD screen, and finally sends the alarm signal to the server through serial port 3 to WiFi [6].

System hardware design
Information Collection Module
DHT11 sensor

DHT11 sensor is a temperature and humidity composite sensor with calibrated digital signal output [7]. Its features include low cost, good stability, can also be used in harsh environment, fast response to these aspects. DHT11 adopts the serial mechanism. The circuit design of DHT11 module is shown in Figure 1.

Figure 1

Circuit design of DHT11 module

Optical intensity module

This part uses the photosensitive sensor to form the light intensity module. Photosensitive sensors convert the optical signals into electrical signals by using the characteristics of photosensitive elements, and their response wavelengths are near visible wavelengths.

Generally, when detecting light intensity, photosensitive sensor is also often used as a device. If other signals are converted into optical signals and then through the photosensitive sensor, the parameter values of other signals can also be obtained. The photosensitive sensor used in this design is a photosensitive diode, whose structure is similar to the semiconductor structure, with a PN junction inside, so the photosensitive sensor also has one-way conductivity. Schematic diagram of optical intensity module is shown in Figure 2. LS1 is a photodiode and R58 provides it with a reverse voltage. When the light intensity changes, the voltage at both ends of LS1 will also change. The stronger the light intensity is, the lower the corresponding voltage will be; otherwise, the higher the light intensity is, the higher the corresponding voltage will be. The LIGHT SENSOR connects to the PF7 pin of the development board and uses the analog input function of the pin. At the same time, the onboard ADC3 channel is used to convert the collected analog signal into digital signal.

Figure 2

Schematic diagram of optical intensity module

Infrared detection module

Infrared detection module HC-SR501 is an automatic control module using infrared technology [8]. This module works in the dc voltage range of 4.5–20V and can output TTL level. It has a working range of 7 m. It has two triggering modes: Non-triggering mode and repeatable trigger mode.

This module has inductive blocking time, that is, when the inductive output high level becomes low level, the developer can manually set a blocking time, during the blocking time, the infrared sensor does not receive any inductive signal. Therefore, it plays an important role in interval detection and effective suppression of various interferences in the process of load switching.

Camera module

The OV2640 offers a single UXGA camera. Generally, OV2640 module is controlled by SCCB bus. The OV2640 can achieve a maximum frame rate of 15 frames per second if in output UXGA image mode. If through SCCB interface programming can achieve any image processing process [9]. The OV2640 module consists of the following modules: photosensitive array, analog signal processing, 10-bit A/D conversion, 8-bit microprocessor [10].

Information Transmission and Display
ESP8266 module

Because ESP8266 module supports TTL serial port, if the TTL level of MCU is 3.3V or 5V, this module can be used. After firmware burning, the module can support three connection modes to realize data transmission, which are: serial port to WIFI STA mode, serial port to AP mode, serial port to STA+AP mode [11].

TFTLCD screen

This part is mainly used for the display of the intelligent agricultural greenhouse system. It can refresh the information of temperature, humidity and light intensity in real time under normal circumstances, display the normal operation of the camera module during the capture, capture the picture and keep the latest capture on the screen.

TFTLCD screen is different from the simple matrix of passive TNLCD and STNLCD. Each pixel of TFTLCD corresponds to a thin film transistor. Therefore, the crosstalk of TFTLCD screen can be eliminated, and the static characteristics of the LCD screen can be independent of the number of scan lines, which greatly improves the image quality of the display.

Information Storage and Processing
SD module

This module is mainly used to store images taken. Considering to support SPI/SDIO driver, and large storage capacity, THE selection of SD card, and its MCU system used to do external memory is very convenient. Use the development board PC8, PC9, PC10, PC11, PC12, PD2 pins [1213].

The SDIO interface has the advantage of being compatible with various memory cards. The SDIO controller of STM32F4 consists of SDIO adapter module and APB2 bus interface connecting CPU. The block diagram of its functional parts is shown in Figure 3. In general, SDIO_D0 is used for data transfer, and after initialization the host can be used to change the width of the data bus. If the memory card of multimedia type is connected to the bus, SDIO_D0, SDIO_D[3:0] or SDIO_DO, SDIO_D[7:0] can be used for data transmission. If the SD card is connected to the bus, the host is configured with SDIO_D0/SDIO_D[3:0] for data transmission. If you initialize, SDIO_CMD needs to be set to open mode; For command transfer, SDIO_CMD needs to be set to push-pull mode.

Figure 3

Circuit diagram of light source module

Light source module:

The light source module automatically adds light intensity according to the change of light intensity, and is connected with the PA2 pin of the development board for multiplexing function. Multiplexing is the output comparison function of timer 9 to control the intensity of light source. [14] This part of external circuit is composed of light-emitting diode in series with a pull-up resistor, and its circuit diagram is shown in Fig. 4.

Figure 4

Light source module circuit diagram

Alarm module

The alarm module mainly uses STM32 to control the buzzer to send sound alarm and WiFi module to send alarm signal to the server. For details about how to send alarm signals, see 3.2.1ESP8266. The buzzer alarm is also relatively simple. It is connected to the PF8 pin of the development board for general output function, and its schematic diagram is shown in Figure 5.

Figure 5

Schematic diagram of buzzer alarm module

System software design

The system software design mainly introduces the code analysis of each function, including initialization setting of hardware, code analysis of abstraction layer, analysis of important functions and code explanation of specific functions. The following is mainly a flow chart + description.

Collection, Display and Transmission
Collection of the data

Write the temperature and humidity collection code dht11.c according to the working time sequence diagram of DHT11 temperature and humidity sensor. DHT11_Rst() is used to reset the DHT11, DHT11_Check() is used to wait for the DHT11 response, and DHT11_Read_Data() is used to read the temperature and humidity data. In addition, it is also important to initialize the PG9 pin to pull up, normal output mode.

Lsens.c and adc3.c files are written according to the working principle of photosensitive sensor to complete the acquisition of light intensity. [15] Since ADC channel is used here to obtain the analog value, the configuration function of ADC initialization is first written, and the function of AD converter Adc3_Init() is turned on. Then write the Get_Adc3() function to obtain the value of the seventh channel of ADC3, then initialize the photosensitive sensor to set PA7 as the analog input function, and write Lsens_Get_Val() to complete the acquisition of light intensity value.

After writing functional functions, we can call DHT11_Read_Data() and Lsens_Get_Val() to complete the collection of temperature, humidity and light intensity.

Display of the data

Temperature and humidity light intensity display will mainly use TFTLCD screen, here need to write the screen driver and Chinese characters display function.lcd.c is used to drive the screen and text.c is used to display Chinese characters.

First, write lcd.c according to LCD usage flow chart (Fig. 6). Initialize the required pins to drive the FSMC interface, initialize the LCD screen by using the initialization series in the screen's data manual, and finally set the coordinates and write GRAM to display characters or numbers.

Figure 6

LCD usage flow chart

Text.c is written to make it easier to display text content, Get_HzMat() is used to find a font from a font library, Show_Font() is used to display characters of a specified size, and Show_Str() is used to display a string.

At the same time, in order to update the temperature and humidity and light intensity in real time without interfering the operation of the main program, timer 4 is started in this design, and TIM4_Int_Init() is written to initialize timer 4 and enable the NVIC interruption of timer 4.

Write timer 4 interrupt service program TIM4_IRQHandler() to obtain real-time temperature and humidity, light intensity information in real time and display it on LCD screen.

Show_Str() and LCD_ShowNum() are used to display the temperature, humidity, and light intensity. Their code in the program is as follows:

Show_Str(30,90,400,24,"LSENS_VAL:",24,0);

LCD_ShowNum(30+10*12,90,adcx,3,24);

//Displays light intensity

Show_Str(30,130,300,24,"Temp: C",24,0);

LCD_ShowNum(30+60,130,temperature,2,24);

//Display the temperature

Show_Str(30,170,300,24,"Humi: %",24,0);

LCD_ShowNum(30+60,170,humidity,2,24);

//Display the humidity

Transmission of the data

Transmission is the key and difficult point in this design. In this part, esp8266. c is mainly written to establish the connection, usart.c is used to send data through the serial port. In short, this part is to control WiFi module to send and receive data through TCP/IP protocol in wireless local area network through AT instruction set.

In common AT instruction sets, "AT+WAMODE=Y" indicates setting the working mode of WiFi module. At present, there are three working modes of WiFi module, which are as follows: Y equals 1 indicates that the module is in STA mode, and the function of the module is to connect to the wireless network as a wireless WiFi STA. Y = 2 means that the WiFi module is set in AP mode. At this time, the module can act as a WiFi hot spot and allow other WiFi to connect to the module. Y = 3 means that the WiFi module is set to STA+AP mode. At this time, the WIFI module has two functions at the same time. It can be used as a hot spot for the connection of other WiFi devices, and can also be added to other WiFi hot spots. One pattern corresponds to three sub-patterns. This design uses STA mode in which the module connects to other WiFi hot spots. Next, the three modes under STA are introduced in detail, and the sub-modes of the other two modes are similar. The WiFi module can be set as TCP server, TCP client and UDP in STA mode, and the corresponding upper computer is set as TCP client, TCP server and UDP respectively. In this design, WiFi module in STA mode is used as TCP client and configured as TCP server in the upper computer software. Table 4.1 shows the configuration in TCP client mode.

STA and TCP client configuration

Instructions Functions
AT+CWMODE=1 Set the WiFi module to STA mode
AT+RST Restart the WiFi module to take effect
AT+CWJAP="xx", "xxxxxxx" Add a WiFi hot spot: xx, the password is xxxxxxxx
AT+CIPMUX=0 Enabling single connection
AT+CIPSTART="TCP","192.168.1.XXX",8000 Establish a TCP connection to 192.168.1.xxx,8000
AT+CIPMODE=1 Enable transparent transmission
AT+CIPSEND Begin to transport

After mastering the AT instruction, it is necessary to write the WiFi module function, write esp8266_start_trans () to connect the hot spot and establish the connection with the server software of the upper computer, send data to the upper computer using esp8266_send_data (), Exit transparent transmission and close the connection with the server through the esp8266_quit_trans() function after the data is sent.

As the serial port to WiFi module is used, the process of data transmission is that MCU sends data to serial port 3, and then serial port 3 receives data and sends it to the upper computer server through WiFi module.

The function of using serial port 3 also needs to be configured. Write usart3_init() with the corresponding pin initialization and NVIC interrupt Settings.

To ensure that the transmission is not disturbed, the NVIC interrupt here should be set to have a high preemption priority. To ensure the correctness of received data, the serial port needs to invoke timer 7 to initialize the serial port, and use the timer 7 interrupt service function to clear data before receiving. Set the interrupt service function USART3_IRQHandler() to receive data after serial port 3 is initialized. Write the u3_printf() function to send data, which is used in writing the esp8266.c data send function, or to send data directly after the ESP8266 module has established a connection to the server.

Monitoring and Storage
Infrared detection and alarm

This part of the function is mainly realized by writing dt.c. The PA3 pin is first configured to initialize it, and the PA3 pin is set to normal input and drop-down mode. Through PA3 pin to infrared detection module output level detection, detection of rising edge trigger interrupt. External interrupts are implemented on interrupt line 3 and need to be configured for interrupt initialization. Configuration interrupt initialization includes initializing PA3, enabling interrupt clock configuration interrupt, connecting PA3 pins to interrupt line 3, and configuring NVIC interrupts for interrupt line 3 and interrupt line 3.

Capture and storage

This part of the software is designed to capture and store images. malloc.c is the memory management driver code. The FATFS file system code is open source and only needs to be ported for use on the development board. sdio_sdcard.c is the code for storing data to an SD card. sccb.c, ov2640.c, and photo.c are used to capture JPG images. dcmi.c is used to transfer captured image data to SD card. The process flow chart of capturing process is shown in Figure 7.

Figure 7

Flowchart of program realization of capture

To accomplish this function, the driver code of SCCB interface should be written first. The second step is to write the OV2640.c code to turn on the OV2640 module. The OV2640 uses OV_SCL and OV_SDA to configure registers, as well as signals such as OV_PWDN and OV_RESET. Configure OV2640 initialization as shown in Figure 8. Another important function here is to set the image output window function OV2640_Window_Set(), set the image output size function OV2640_OutSize_Set(), set the window function OV2640_ImageWin_Set(), set the image resolution size function OV2640_ImageSize_Set ().

Figure 8

OV2640 initial configuration flowchart

The third step is to compile dcmi.c which mainly completes four functions. The first is to enable the clock, configure the mode of the required pins and set the reuse function. Then complete the configuration of the DCMI. In this step, important parameters such as HSPOL/PCKPOL/VSPOL data width in the DCMI_CR register need to be configured. When frame interrupt is enabled, DCMI interrupt service function is written for data processing.

Automatic Adjustment of Light Intensity

In the program prepared pwm.c to control the intensity of the light source to achieve this function. Initialize timer 9PWM, define the structure variable required by timer 9, enable TIM9 clock and port A clock, reuse PA2 pin to timer 9, initialize PA2 pin, and then initialize timer 9, because the PWM mode of timer 9 channel 1 is used here, Therefore, it is very important to initialize the channel. Finally, enable timer 9 to complete the setting of timer 9PWM wave.

Then we set the comparison value of PWM wave according to the obtained light intensity value, so as to modify the duty cycle to achieve the purpose of adjusting the light source. The larger the intensity value, the smaller the comparison value and the weaker the light source. This process is shown in Table 2.

Automatic adjustment of light source

Light intensity values (adcx) Comparing values (ledpwm val)
adcx>50 0
30<adcx⩽50 100
20<adcx⩽30 300
adcx⩽20 500
Function implementation and testing

The physical picture of the system is shown in Figure 9. And the system startup interface is shown in Figure 10. After entering the startup interface, you can get the function introduction of the system, the name of the system, the model of the development board used, and the department of the system.

Figure 9

System physical drawing

Figure 10

System startup interface

Measurement of the Data

The test here is mainly on the screen and the upper computer temperature and humidity size, light intensity size test. The test environment was 8 a.m., 13 p.m., and 20 p.m. Figure 11 (a) and Figure 11 (b) respectively show the display of temperature, humidity and light intensity on LCD screen and upper computer at 8:00 in the morning. Table 3 shows the measured temperature, humidity and light intensity.

Figure 11

(a) Screen display at 8:00, (b) Upper computer display at 8:00

Test results at 8:00

Time Light intensity Temperature Humidity
8:00 67 27°C 41%

Figure 12 (a) and (b) respectively show the display of temperature, humidity and light intensity by LCD screen and upper computer at 13:00 at noon. Table 4 shows the specific temperature, humidity and light intensity measured at this time.

Figure 12

(a) Screen display at 13:00; (b) Display of upper computer at 13:00

Test results at 13:00

Time Light intensity Temperature Humidity
13:00 98 28°C 41%

Figure 13 (a) and (b) respectively show the display of temperature, humidity and light intensity by LCD screen and upper computer at 20:00. Table 5. Shows the specific temperature, humidity and light intensity measured at this time.

Figure 13

(a) Screen display at 20:00; (b) Upper computer display at 20:00

TTest results at 20:00

Time Light intensity Temperature Humidity
20:00 2 26°C 30%

The tests in three time periods verified the correctness of temperature, humidity and light intensity test results, as well as the correctness of data display on LCD screen and transmission through ESP8266WiFi module.

Automatic Adjustment of Light Source Measurement

In this part, we observe the light source module by changing the light intensity. Under normal circumstances, the light source is usually warm color light, but here, in order to make the test results more obvious, red LED is selected for testing. In the first set of data, if the light intensity is greater than 50, it can be seen that the light source does not emit light, as shown in Figure 14.

Figure 14

The first group of auto-adjusting light source

The second set of data makes the light intensity within the range of 20–30, and it can be seen that the light source is shining, but not particularly bright, as shown in Figure 15.

Figure 15

The second group of test pictures of automatic adjusting light source

The third group of data makes the light intensity less than 20. It can be seen that the light source is the brightest at this time, as shown in Figure 16. The light source module is located at the lower right corner of Figure 14–16.

Figure 16

The third group of test pictures of automatic adjusting light source

At this point, the automatic adjustment of the light source to complete the test, the test results are normal.

Infrared Monitoring

This part of the function needs to detect animals or people can be captured. In this part, two groups of tests were conducted, each of which tested the following five indicators:

1) Captured image information;

2) Whether the system can return to normal state after capturing (that is, temperature, humidity and light intensity are displayed and the next capturing can be carried out);

3) Keep the latest snapshot images on the screen;

4) Verify whether the captured image is stored on the SD card;

5) Whether the buzzer sends sound alarm and whether the upper computer receives the alarm signal “Warning!”.

According to these 5 indicators, the first group of images obtained after testing are shown in Figure 17–20.

Figure 17

Capture group 1 (1)

Figure 18

Capture group 1 (2)

Figure 19

Capture group 1 (3)

Figure 20

Capture group 1 (4)

Figure 17 is the original image captured. Figure 18 shows the image of screen retention and return to normal state after capturing. From here, we can also get the location information of the saved image after capturing: PHOTO/PIC00027.jpg; Figure 19 shows the image information stored on the SD card. The realization of capturing and storage functions can be verified through Figure 19 and Figure 20 is the alarm signal sent to the upward machine after monitoring.

Figure 21–24 shows capturing the second group of images.

Figure 21

Capture group 2 (1)

Figure 22

Capture group 2 (2)

Figure 23

Capture group 2 (3)

Figure 24

Capture group 2 (4)

The second set of tests was conducted mainly for further verification. Figure 21 shows the original image captured for the second time. Figure 22 shows the image of screen retention and return to normal state after the second capture. From here, we can also get the location information of the saved image after capturing: PHOTO/PIC00034.jpg; Figure 23 shows the image information stored on the SD card. The realization of capturing and storing functions can be verified again through Figure 23 and Figure 24 is the alarm signal sent to the computer again after infrared detection.

By comparing the two captured images with the test indexes, the infrared monitoring alarm and storage functions have been verified.

From here, we can also get the location information of the saved image after capturing: PHOTO/PIC00027.jpg; By comparing the two captured images with the test indexes, the infrared monitoring alarm and storage functions have been verified.

eISSN:
2470-8038
Lingua:
Inglese
Frequenza di pubblicazione:
4 volte all'anno
Argomenti della rivista:
Computer Sciences, other