Smart network desk lamp, project submission
[Copy link]
This post was last edited by hehung on 2022-10-16 20:10
Smart network desk lamp
Author: hehung
1. Introduction
This work is based on ESP32S2 and MaixBit. ESP32S2 implements LCD display function, which can display time, weather information (7-day weather), lamp brightness information, network status information, etc.; local control, remote APP control and Tmall Genie voice control functions are implemented, and the brightness, switch, study time, delayed shutdown, control mode and other functions of the smart lamp can be set; the mode control includes manual, automatic, reading and sleeping, which can be switched freely; MaixBit implements the function of collecting ambient light intensity with the camera and interacting with ESP32S2 through the serial port; this work also implements the wifi network configuration function, and the APP can be used to configure the network of the smart network lamp.
2. System Block Diagram
The system architecture diagram is as follows:
3. Functional description of each part
(The functional description and explanation of each part are presented in a combination of pictures and text.)
Hardware Connection:
ESP32S2: L298 driver chip MaixBit
IO0 -- L298N driver IN1
GND -- L298N driver IN2 -- MaixBit GND
IO4 (UART TXD) -- MaixBit IO9 (UART RXD)
IO5 (UART RXD)--MaixBit IO10 (UART TXD)
ESP32S2
The following introduces the functions of ESP32S2 related components.
- LCD
The LCD display uses the GUI driver LVGL to provide a good-looking GUI interface.
As shown in the figure above, LCD is mainly used to display some information, including:
- Date, Time
- Network connection status (wifi icon)
- When not connected to the network, the Wifi icon flashes periodically;
- After connecting to the network, the Wi-Fi icon is always displayed.
- IoT connection status (IoT icon)
- If not connected, the Wifi icon will flash periodically;
- After connecting to the network, the Wi-Fi icon is always displayed.
- Table lamp delayed off enable status (DO icon, DelayOff)
- The delayed closing function is always displayed when it is enabled;
- No display when the delay closing function is turned off
- Weather Information
- Today's weather, temperature and humidity
- Air quality, today's temperature range
- The weather for the next six days starting from tomorrow, scrolling display
- Study time bar (the time bar on the left shows the remaining study time)
- Desk lamp brightness bar (the brightness bar on the right shows the current brightness of the desk lamp)
- The remaining study time number, the lower middle part shows how much study time is left, as shown below
- RGB
The three RGB LEDs are mainly used to mark the current status.
- If the wifi is not connected, the red LED flashes;
- If the wifi is connected but not connected to the Alibaba Cloud platform, the blue LED flashes;
- If the Wi-Fi is connected and linked to the Alibaba Cloud platform, the green LED flashes;
- If the lamp is off, all LEDs are off.
- button
There are 6 buttons (K1~K6) on the ESP32S2 board. They are ADC buttons, so they are controlled through an IO port and configured in ADC mode. The function of each button is described in detail below:
- K1:
- Long press (press for more than one second) to enable/disable the delayed shutdown function of the desk lamp. If it is currently enabled, it will be disabled; if it is currently disabled, it will be enabled;
- Short press (press for less than one second) is used to turn the desk lamp off or on. If it is currently off, it will turn it on; if it is currently on, it will turn it off.
- K2
The mode switch button is used to switch the control mode; the control modes include automatic mode, manual mode, reading mode and sleep mode. Each time the button is pressed, the mode will be switched in sequence.
- K3
Manual control increases the brightness of the console lights, which is only valid when the control mode is manual.
- Press and hold the button to increase the brightness of the desk lamp to a maximum of 100%.
- K4
Manual control reduces the brightness of the console lamp, which is only effective when the control mode is manual.
- Press and hold the button to reduce the brightness of the desk lamp to a minimum of 0%.
- K5
Manual setting learning time increases, which is only valid when the control mode is manual.
- Press and hold the button to increase the learning time to a maximum of 120 minutes.
- K6
Manual setting reduces the learning time, which is only valid when the control mode is manual.
- Press and hold this button to reduce the learning time to a minimum of 0 minutes.
- Delayed closing function
Note: Delayed shutdown means that when you turn off the desk lamp, it will not turn off immediately, but wait for 30 seconds before turning off.
During the delayed shutdown waiting period, if the power button is pressed again, the shutdown process will be stopped and the desk lamp will not be turned off.
- desk lamp
The brightness of the desk lamp is controlled by the PWM signal output by LEDC of ESP32S2, using the L298N driver chip, as shown in the figure below.
- LEDC outputs PWM signal to IN1 port of L298N driver chip; IN2 port of L298N is connected to GND;
- OUT1 and OUT2 are connected to the positive and negative poles of the desk lamp;
- The positive and negative poles of the desk lamp's power supply are connected to +12V and GND respectively.
Then, the PWM control signal output by LEDC will be output to the desk lamp through the L298N drive signal to achieve brightness control.
- Control Mode
The control modes include automatic mode, manual mode, reading mode and sleep mode.
- Automatic mode: automatically sets the brightness of the desk lamp according to the intensity of ambient light;
- Manual mode: control the brightness manually (or through network control, voice control);
- Reading mode: desk lamp brightness mode is 90%;
- Sleep mode: This is also the night light mode, and the brightness is set to 10% by default.
- time
The RTC chip of ESP32S2 is used to automatically control the time, add networking functions, and calibrate the internal RTC. Once every hour, the display will show the current time in real time (hour, minute, second, month, day, and day of the week).
- weather
HTTPS is used to obtain weather information, obtain network weather information and update it locally.
Get the weather URL: https://www.yiketianqi.com/index/doc?version=day .
Two types of weather will be obtained:
- One is real-time weather information, including weather, temperature and humidity, today's temperature range, air quality and other information;
- The other is to get seven-day weather, including date, weather, and temperature range;
Get weather information, parse it through CJSON and display it on the LCD screen.
- Serial Port
The serial port is used to communicate with MaixBit and receive the ambient light brightness information calculated by MaixBit.
The serial communication format is: data length (1 Byte) + data command (1 Byte) + data (1 Byte), transmitted in ASCII format.
- Internet of Things
This work uses the Alibaba Cloud Physical Network platform for remote data interaction. The functions that can be controlled through the Internet of Things include:
- Mode (Auto, Manual, Reading, Sleep)
- Brightness (0%~100%)
- Study time (0~120 minutes)
- Desk lamp power on/off
- Delay switch enable/disable
The data after local control will be transmitted to the cloud platform in real time.
Alibaba Cloud Platform Data Definition. The following figure defines the data format for the interaction between the smart network desk lamp and the Alibaba Cloud Platform:
The following is the control interface configuration of the mobile APP:
- Tmall Genie
You can control the console lights through Tmall Genie, and the following functions can be controlled:
- Desk lamp on/off
- Desk lamp brightness
- Distribution Network
If the work has not been connected to the Internet, it will automatically enter AP mode when in use and create a WiFi hotspot.
Use Alibaba Cloud's Cloud Intelligence APP to add a device, which will automatically search for the current device. After a successful search, it will connect to the hotspot created by ESP32S2, and then wait for the network configuration to be completed. The network smart desk lamp can successfully connect to the network. There is no need to connect again the next time it is powered on. The information will be automatically saved in nvs, and it will automatically connect to wifi and the cloud platform the next time it is powered on.
For detailed network configuration operations, please see the end of the demonstration video.
MaixBit
- The MaixBit code is implemented in Python.
- Ambient light detection
The camera will collect the current environment image, then take a picture every second, read the picture in LAB format, and calculate the average value of L (indicating brightness) in the picture to know the ambient light intensity. The L value is 0~100, indicating that the ambient light brightness is 0%~100%.
- LCD
LCD is an auxiliary device used to display the image currently captured by the camera and display the ambient light intensity on the image.
- RGB
RGB is used to show whether the environment is working properly. If it is normal, the green LED will be displayed once every second, and the one-second flashing will be realized through timer 1 channel 0.
- Serial Port
The serial port is implemented in timer 0 channel 0, which is used to send ambient light intensity data to the serial port once a second. It also monitors the data received by the serial port and prints it out.
4. Source Code
The source code is placed in the EEWorld download center:
https://download.eeworld.com.cn/detail/hehung/625181
At the same time, the source code is placed in gitee, the link is as follows:
5. Demonstration video of the work’s functions
The video demonstrates some of the features of the work, including network distribution, network control, local control, voice control and other functions.
The video is placed on bilibili, the link is as follows:
https://www.bilibili.com/video/BV1sP411N7fa/
6. Project Summary
In order to complete this project, I learned a lot of knowledge, such as ESP32S2 networking, ntp time update, obtaining weather information, using lvgl driver, linking to Alibaba Cloud IoT platform, etc. I also learned how to use maixbit, which was very helpful to my growth.
Share posts during project production:
[2022 Digi-Key Innovation Design Competition] Latest unboxing post
[2022 Digi-Key Innovation Design Competition] 1. ESP32-S2 environment construction and lighting
[Smart Network Desk Lamp] 2. Setting system time and printing
[Smart Network Desk Lamp] 3. ESP32-S2 + lvgl use
[Smart Network Desk Lamp] 4. ESP32-S2 onboard button use
[Smart Network Desk Lamp] 5. ESP32-S2 uses sntp for network time synchronization
[Smart Network Desk Lamp] 6. ESP32-S2 solves the problem of excessive RAM space overhead
【Smart Network Desk Lamp】7. Get real-time weather information and analyze it
【Smart network desk lamp】8. Maix bit driver RGB
【Smart network desk lamp】9. Maix bit driver serial port
【Smart Network Desk Lamp】10. Esp32-S2 driver UART
【Smart Network Desk Lamp】11. MaixBit uses a camera to detect ambient light intensity
VII. Others
Thanks to Digi-Key and EEWORLD for this opportunity. After three rounds of selection, I was not selected, but because some friends gave up the competition, I was lucky enough to be selected to enter the competition again. Thanks to Dudu for the recommendation. This work has achieved a lot, learned a lot of knowledge, and gained valuable software debugging experience. I hope to participate in more competitions in the future and make progress together with my friends.
|