蓝猫淘气

#The7thLiChuangDianJiang#Smart Flower Pot

 
Overview
Adopt N32L403KBQ7 master control, ESP8266 as networking device, can choose to use it without networking or networking, and can adjust control parameters when not connected to the network
Update:
1.Bug: ESP8266 does not work, it may be a problem of hardware reset circuit not being done well, so the networking part may have to be suspended for a while.
2. BH1750 ADI is not pulled up to VCC (fixed)
3. There is a little bug in the battery power detection.
The functional block diagram is as follows.
Beautiful picture appreciation .
Shell initial makeup
 
. I. Introduction to the functions of each module
1. Master control
  In order to improve the battery life without connecting to the power supply, the low-power N32L403KBQ7 master control is adopted. The main functions are: collect and process data, process images, send data to ESP8266, and detect battery power. Remember! BOOT0 is not brought out, and can only be downloaded through SWD.
 
2. Soil humidity module
  Use the soil humidity module from Youxin. It is recommended to buy the gold-immersed model. The ordinary model is easy to rust in a high humidity environment, resulting in inaccurate measurement and other problems. Because it is detected by contacting the soil, it must be inserted in a place where the soil is relatively compact, and the drop arrow (the water pipe inserted into the soil) and the soil humidity module must be close, otherwise it will cause excessive water input.
3. Temperature and humidity module
  SHT30 is a commonly used temperature and humidity module. Although a single bus communication module like DHT22 can be used, this solution is abandoned due to volume issues. In addition, SHT30 has the advantages of low power consumption, fast response, and strong anti-interference ability.
4. Wireless module
  This wireless and networking device uses the old friend ESP8266. The original plan was to use ESP32-C3 with lower power consumption at the same frequency as the networking device. The MCU sends data to ESP8266 through the serial port, and ESP8266 sends data to the device through MQTT. The terminal can also send information to ESP8266, and ESP8266 sends it to the main control to set environmental parameters or generate corresponding actions.
5. The light sensor module
  uses BH1750. This is to help students from other colleges to conduct research on the impact of light on plants' demand for soil moisture (the part I am responsible for), but it was abandoned and placed on the back, so it is too insensitive to light. The relevant driver code has been written, and students in need can pick it up by themselves~
 
6. The dial (button control)
  has a relatively high interactivity compared to other buttons, and is relatively beautiful, and has been adapted to long-press and short-press drives.
7. The power management and charging module
  uses a pmos tube for power management. When there is no power (VBUS) input from the USB, a weak pull-down resistor makes the gate at a low level. At this time, DS is turned on and powered by a lithium battery. When there is USB power, VBUS will power the system through a Schottky diode. At this time, DS is disconnected, so that the system can be powered while charging. If you don't understand it very well, you can go and watch the video of Mr. Sun, a male engineer. The charging part uses a lithium battery power management chip. LTC4054 is an enhanced version of TP4054 (?), and its functions are similar to TP4054, so I won't go into details.
8. The water pump
  is just an ordinary 3V mini water pump. I can only say that it works. 9.   Solder the copper nut
on the fixed part 2. The inspiration for the project   "Pole Star Project" is my dream of designing a smart home (control) by myself, a complete set of IoT interactive devices and control devices, just beginning. (It's not God who forces me to do it) 2. Hardware   1. The power supply   uses two AMS1117s to power ESP8266 and MCU and devices respectively. The star connection is used to separate the power supply to avoid the AMS1117 from heating up seriously when the ESP8266 is in high power consumption, resulting in inaccurate temperature measurement. The battery power supply uses RC filtering to effectively reduce low-frequency noise. The coexistence of charging and discharging has been explained above. 2.   A 1nf capacitor is added to   measure soil moisture to stabilize the data.  3. The ESP8266   crystal oscillator is grounded, there is no wiring under the antenna, and there is a delayed start. All parts are strictly in accordance with the requirements of the technical manual. 3. I2C has added a pull-up resistor to greatly support external I2C devices. 4. Because the dial can be set to a pull-up state inside the chip, the dial state can be detected when the pull-up input is input. 5. The battery power detection adopts a switch type to avoid unnecessary power consumption. 6. The water pump drive uses PWM to drive MOS speed regulation, low conduction, and adjusts the water pump horsepower through the timer output of different duty cycle PWM. 7. There is nothing much to say about reset. BOOT0 is grounded through a pull-down resistor and directly enters the system flash. NRST pulls up to start normally and resets to ground. 8. Charging module 9. The short-circuit point is short-circuited, using the short-circuit point, and selecting USB serial port debugging. 3. The software part  is divided into eight parts for implementation. 1. UI   The UI is actually a nesting doll. Create a main linked list as the parent object, and then include the child object (actually also a linked list). When you click OK and the child object is not empty, it points to the child object. When you exit, it points back to the parent object. For details, please refer to this article. The idea reference comes from this article (@snqx-lqh) . I have commented on most of the code. The linked list is as follows, and the comments have been made. When creating an object, strictly follow the following format. The establishment of the menu is the same as what I just said, nesting dolls! Create an object. This object can be a parent object or a child object. The meaning of a child object is that it is included by this parent object. When the child object is clicked, it enters the linked list of the child object. At the same time, this parent object may also be a child object of another object (hence the nesting doll). UI screen refresh The UI screen refresh is controlled by two functions, one is the menu page refresh, the other is the data refresh Menu page refresh Data refresh UI control When the button is triggered, turn to the corresponding linked list. For details, please see the source code 2. OLED driver This driver is taken from B station UP host Mjgame. It mainly drives the graphics library and various graphics interfaces. The only disadvantage is that it cannot be used for inversion. 3. Soil moisture uses DMA to transfer ADC. I feel there is nothing much to say. After enabling DMA and ADC, the data will be automatically converted. 4. Ambient temperature and humidity



 






















 



 









 


 



I2C drives SHT30. After the EV7 flag is set, it continuously acquires information. It detects the flag every 8 bits and then gives EV7 to end the reception. In fact, it is also possible to detect EV7 during continuous acquisition, as long as the termination signal is sent at the end.

    while(!I2C_CheckEvent(I2C2, I2C_EVT_MASTER_DATA_RECVD_FLAG));
    data[0]     = I2C_RecvData (I2C2); while(!I2C_CheckEvent(     I2C2, I2C_EVT_MASTER_DATA_RECVD_FLAG)); data[1] = I2C_RecvData(I2C2); while(!
   
    I2C_CheckEvent(I2C2, I2C_EVT_MASTER_DATA_RECVD_FLAG)) ;     data[2] = I2C_RecvData(I2C2);     while(!I2C_CheckEvent(I2C2, ENABLE);     I2C_ConfigAck     (I2C2     ,     ENABLE     );     5.The motor drive is very simple. Just     adjust     the  duty cycle. The duty cycle algorithm is to set the comparison value/period . void Motor_Speed( int16_t speed_level ) {     int16_t level =0;     if( speed_level <=10 )     {         level = speed_level*100;         TIM_SetCmp1( TIM3, level );     } } 6. Flash This project uses the method of writing Flash to store data, mainly setting data, such as the speed of the motor, setting the soil moisture for watering, and storing it on page 63, starting from bit 0, the high 8 bits record the motor speed, and the low 8 bits record the soil moisture for watering. 7. The delay function uses two general timers TIM6 and TIM7. I thought they would not be used anyway, so I used them for timing, and performed ms-level and us-level delays respectively. They must be called once at the beginning of the system, otherwise the first delay function will fail. 8. The button  realizes the function of long and short press, but my project only uses short press. The idea is that when a button is detected to be pressed, it enters the while loop, at which time the value of the corresponding button is ++. When the threshold (long press time) is reached or the button is no longer pressed, it jumps out. There is a judgment in the loop, which will set the long press flag to the position, and then judge which button is pressed, as well as the long and short press situation. IV. Functional video





   



















   








 

 
 
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-05-22 22:05:59

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号