newrudeman

[Tuya Smart] IoT thermometer and hygrometer

 
Overview

Brief description

MCU:

STM32F1 (using Yefire STM32F103C8T6 core board) or STC8A (maybe most people don’t have Yefire core board, but related functions can also be achieved using STC8A)

IMG_20210207_215944IMG_20210207_195651

The reason why STC8A is placed on the back is that the order of RX and TX on the STM32 core board is reversed. Placing it on the back can facilitate wiring.

Select the MCU through the jumper cap (originally I wanted to do this so that when both MCUs have been programmed, the power can be disconnected without interfering with each other. Later I found that because the hardware IICs of the two MCUs were connected together, After STC8 burned the relevant IIC program, even if the STC8 was not powered, the STM32 program was still stuck in OLED initialization. In the end, it was solved by shielding the relevant code and then burning it into STC8, and when using STC8 , and cannot be inserted into the STM32 core board)

Temperature and humidity sensor:

DHT11

Its precision humidity is ±5%RH, temperature is ±2℃, measuring range humidity is 5-95%RH, and temperature is -20~+60℃.

Display module:

OLED_IIC or serial screen (reserved interface, not used)

The IIC bus is connected to the hardware IIC of the MCU

Internet of Things:

TUYA-WBR3

I have used ESP8266 to upload data to OneNET before. In comparison, the Tuya module is easier to use, and Tuya Smart provides MCU_SDK, which allows us to quickly complete MCU program development.

RGB_LED:

The three-color cycle changes to increase the presence of this small object.

Active buzzer:

Set thresholds for temperature and humidity and provide alarm function

The alarm function can be canceled by unplugging the jumper cap

LDO (5V to 3V3):

When using the STM32 core board, since there are related circuits on the core board, disconnect it at this time. When selecting the MCU as STC, since the operating voltage of some devices is 3V3, it can provide a voltage source for the peripheral circuits at this time.

Button module:

The schematic diagram of the two buttons on the PCB refers to the schematic diagram of the buttons on the Yefire STM32F103C8T6 core board. Capacitors are connected in parallel for hardware debounce, so there is no need for software debounce in the button processing function.

Software debugging

Github: https://github.com/Lin-Chengqiu/LCEDA-TUYA-Demo

Debugging process:

1. Obtain temperature and humidity data through DHT11 and print it through the serial port;

2. Get the WBR3 working status through mcu_get_wifi_work_state(), and print the WIFI working status through the serial port

3. If the working status of WBR3 is WIFI_CONN_CLOUD, upload the temperature and humidity data to Tuya Smart and compare the cloud data and local data to see if they are consistent.

4. Display temperature and humidity data and WBR3 working status through OLED

5. Provide an alarm function through an active buzzer (at the beginning, I wanted to use RGB_LED to provide the alarm function, and then use it purely as an ambient light)

6. Plan the button functions, use buttons to turn off and on the RGB_LED, OLED wake-up and sleep, OLED interface switching, change the temperature and humidity alarm threshold, and write it into the FLASH of STM32, which can be saved after power-off and set the wifi working mode... ..

STM32:

image-20210212223853653

Network configuration is required when connecting the device for the first time.

IMG_20210213_211150IMG_20210213_211128

At this time, available devices can be found on the APP

Screenshot_20210213-211047Screenshot_20210214-214918Screenshot_20210214-215005

 int main()
 {
   All_init();
   while (1)
   {
     wifi_uart_service();
     alarmBeep();
     getValue_and_update();
     KeyFunction();
     switch(screenMode)
     {
       case 0:screen0();break;
       case 1:screen1();break;
       default:break;
     }
   }
 }
STC8:

I wrote the STM32 code first, and then directly transplanted part of the STM32 code to STC8. In fact, there is not much difference.

 int main()
 {
   All_init();
   while (1)
   {
     wifi_uart_service();
     getValue_and_update();
     KeyScan();
     screen();
   }
 }
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2024-11-22 18:33:20

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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号