王达业

[Tuya Smart] Intelligent temperature and humidity sensor

 
Overview

Intelligent temperature and humidity sensor

Project source code: https://github.com/lin-kangkang/temperature-and-humidity-senso-tuya-mcur

Demo video: https://www.bilibili.com/video/BV1DA411K7TZ/

First picture: 65ea7a58b4f5b6314ac65d68243af2b.jpg61c946bee2bd0fbfcc09786e8bf4a04.jpg

Did you notice the time above? I stayed up late to write this article. It seems that I need to correct my procrastination problem, hhh.

Instructions for use

  • Long press key0 to turn on and off the machine
  • After powering on, press and hold key1 to enter or exit the setting interface.
  • Short press key0 and key1 to switch pages.
  • In the setting interface, short press key1 to select functions, and short press key0 to confirm execution of the corresponding function.
  • Flashing red light means the battery level is less than 20%
  • Flashing green light means it is in network distribution mode
  • The green light is always on, which means it is connected to wifi and cloud.
  • The blue light flashes to indicate that the program is running
  • These indicators can be turned on or off in the settings interface

hardware design

Please refer to the project schematic diagram for the specific circuit.

  • The control chip uses STM32F103C8T6 because I am most familiar with this chip.
  • It is powered by a lithium battery and can be charged through the typec interface.
  • There is a CH340N chip onboard, which can communicate with the computer via serial port for easy debugging.
  • Two ME6212C33 chips are used for voltage stabilization, one of which supplies power to the MCU alone and the other to other peripherals. This is beneficial to the stability of the circuit, and can also be used to disconnect the power supply of other peripherals through MCU control, thereby saving power.
  • The networking module uses the "WB3S-IPEX WiFi&BLE dual protocol module" officially recommended by this event, which has wifi and Bluetooth functions. In order to prevent the heat of the module from affecting the temperature measurement, and also to avoid interference to the module's signal, I placed the module on another board, and the two boards were connected through pin headers and female headers. Tuya module adapter board open source link: https://lceda.cn/linkk/zhi-neng-wen-shi-du-chuan-gan-qi_-tu-ya-kuo-zhan-ban
  • The temperature and humidity sensor uses the commonly used SHT30, and grooves are carried out around it to minimize the interference of the board temperature on the SHT30. However, the temperature measured in actual use will still be a little higher than the real temperature.
  • Displayed through OLED screen.
  • There are two buttons and three LEDs on board.
  • Although equipped with so much hardware, the size of the board is only 40mm X 40mm, which is very compact.

Porting of Tuya MCU SDK

1. First download the required MCU SDK in Tuya Workbench, as shown in the figure below:

image20210226170231931.png

2. Then add all the .c files inside to the process and add the header file path.

image20210226170429761.png

3. Enter wifi.h and add #include "stm32f10x.h" (modify according to your own chip, the chip I chose is stm32f103c8t6)

image20210226170814389.png

4. Finally, enter protocol.h, configure it according to your needs, and then modify it according to the compilation error prompts.

The places to be modified are as follows:

4.1. Call the serial port single-byte sending function in the uart_transmit_output function. Note that it is single-byte sending! ! !

image20210226171831080.png

4.2. Call uart_receive_input(value) in the serial port reception interrupt. The parameter value is the data received by the interrupt. Remember to turn on the serial port interrupt first, and try not to turn off the serial port interrupt used during program running.

image20210226172113816.png

4.3. Enter the function my_strcpy(char dest, const char src) and put the definition of the pointer p at the front of the function.

image20210226173115428.png

4.4. Call the function in the while loop of the MCU main function: wifi_uart_service()

4.5. Add wifi_protocol_init() in the main function to complete the wifi protocol initialization

4.6. Process and automatically generate data reporting function all_data_update() according to your own needs

4.7. For other errors, just comment out the line that caused the error.

The final modification results are as follows, 0 Error, 0 Warning, hahaha

image20210226173327109.png

Trampling on pit records

1. If you need to use the function of obtaining weather, be sure to increase the size of the serial port data processing buffer, otherwise the processed data will not be received.

image20210226201316139.png

2. As mentioned in the above transplantation process, the serial port sending function called in the uart_transmit_output function must send single-byte data.

3. When obtaining weather data, be sure to read official reference documents to confirm the type of data, and do not just rely on your own feelings. For example, the wind speed is of string type. I was stuck here for most of the day and convinced myself.

image20210226234043536.png

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-23 17:25:05
  • TMS320F28335 SVPWM source program
  • Use of hardware multiplier in MSP430 library
  • avr gcc optimization problem
  • 430 inverter power on AUTO
  • UPD78F0888A Renesas MCU peripheral settings
  • How to enable the independent watchdog in STM32?

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号