张三叔

[Tuya Smart] IoT thermometer and hygrometer

 
Overview

Lichuang & Tuya Training Camp Phase 2--Internet of Things Temperature and Humidity Sensor


The IoT thermometer and hygrometer based on Tuya Smart automatically collects current temperature and humidity data, uploads it to the cloud through STM32 & Tuya IoT module, and displays it through the Tuya Smart APP.


1. Implement functions

2021.2.24:
  1. Get ambient temperature and humidity
  2. Display temperature and humidity information through OLED
  3. Transmit the obtained temperature and humidity information to the APP
  4. Set the network distribution mode with buttons
2021.2.28:
  1. Display distribution network information on OLED screen
2021.3.6:

6. RTC clock, network time synchronization 7. Press the button to switch the display interface


2. Hardware

1. MCU


The design uses STM32F103C8T6. Due to the outrageous price of STM32 recently, we switched to the domestic chip APM32F103C8T6.

2. Power supply


Use a USB-Type-C plug and a power switch; 5V to 3.3V, of course the AMS1117-3.3 that remains unchanged for thousands of years.

3. Networking module


Tuya's WB3S module has BLE & WIFI dual-mode, and the network configuration operation is very comfortable. This time I used the MCU SDK development method.

4. Temperature and humidity sensor


SHT30-DIS uses the IIC interface. This is my first time using this. It is said to have high precision, low power consumption, and is suitable for welding.Very friendlyI bought a heating plate specifically for this purpose, but it left a black mark on my coffee table... WeChat picture_20210301201828.png

The nRESET pin does not need to be connected, there is a pull-up inside the component.

5. Serial chip: CH340N


It is used for debugging and is connected to the Type-C port. A relatively small serial port chip is used. I feel that an onboard serial port chip looks more elegant than an external serial port cable. Both CH340N and CH330N are available. Don't forget there is a 0.1uF decoupling capacitor on the back. Back + arrow.jpg

6. Display


0.96-inch OLED screen with IIC interface.

7. Buttons


2021.2.24:

There are two function buttons, KEY0 is used to configure the network, and KEY1 is used to clear the network configuration (actually the functions of these two buttons are the same). No matter which button is pressed, LED2 will light up for a while and then go out automatically.

2021.3.6 update:

KEY0 is used to trigger SmartConfig, and KEY1 is used to switch the OLED display interface.


3. Software

Before the school holiday, we had a course design (the topic has been assigned in 2020/11). By coincidence, we also designed an Internet of Things thermometer and hygrometer (the hardware is different, the thermohygrometer is DHT11, and the WiFi module is ESP8266) . At that time, I used a hardware initialization code sent by a classmate, and added some mqtt, esp8266, and function codes on this basis. I started working on it after the final exam. It was actually less than 6 days before the acceptance. One night before the acceptance, I stayed up until after 3 o'clock to barely finish it. It can only be regarded as a semi-finished product. It only realizes that the device sends temperature and humidity to the server through the MQTT protocol. The data is used to light up the LED lights through the server (everything starts from lighting up the lights). Later I found out that the two classes actually produced very few sets.

In this project, I also developed the hardware initialization code based on the code sent by my classmate (his code is really good, although he also copied and pasted it in various ways), and added SHT30 and Tuya SDK codes.

I have to say that if I had known about the Tuya platform before, the course design would not have been a chore.


4. Display

1. PCB

I made two boards. The welding on the first board was really bad. It was so ugly that I couldn’t stand it anymore, so I made a new one.

20210225_161352.jpg

20210225_161339.jpg

2. Initialization

Hardware initialization.jpg

3. Distribution & Networking

Networking.jpg

4. Temperature and humidity display

Display temperature and humidity.jpg


Summarize

1. Thanks to Tuya Smart and Lichuang EDA for their strong support, I learned a lot. With Tuya Smart, the difficulty of the Internet of Things has really dropped a lot, and this holiday has been full of rewards.

2. As a person who just draws on the board when he has nothing to do, and has a habit of gathering Jiali to create something every month, circuit design is not difficult, but it is difficult to do it well, whether the PCB layout is reasonable and beautiful, etc. I think the functions of PCB design this time are not very rich, and they only complete the most basic functions.

3. In terms of programming, Tuya’s SDK itself supports quite a few functions, such as school time, weather, etc., but I still don’t know enough about STM32. I want to implement these functions, but I don’t know where to start. The ability to solve complex problems is still needed. improve.

4. I am very happy to discuss and learn with everyone in the group! ! !


Engineering link: https://oshwhub.com/Flight666/wu-lian-wang-wen-shi-du-ji

GitHub: https://github.com/Flight98030/TuYa-Iot-hygrothermograph

gitee: https://gitee.com/Flight98030/TuYa-Iot-hygrothermograph

bilibili: V1 version link (V1.5 version b station link is below) https://www.bilibili.com/video/BV1UV411e7fw


renew

2021.3.6: V1.5: Added clock function based on V1.2 version

1. Add the RTC clock. At the beginning of the design, the PCB circuit only had an 8MHz high-speed crystal oscillator and did not use a 32.768KHz crystal oscillator, so the RTC clock used the HSE clock. The code adds the choice of RTC clock source based on Atomic Brother's RTC code. Which clock source you need to use, just open the corresponding macro definition in RTC.h!
After being connected to the Internet, Tuya's SDK package will automatically calibrate the RTC clock (the corresponding macro definition must be enabled in protocol.h, and the RTC clock writing code must be completed in protocol.c), and the RTC clock is automatically calibrated every minute in the code. , there is no need to worry about incorrect clock due to problems with the RTC clock source.

RTCH.PNGRTCHH.PNGRTCCC2.PNG

2. Modify the temperature and humidity interface, remove the OLED to display WiFi connection status, and change this part to display time.

Time + temperature and humidity.jpg

3. Add the interface switching function, press KEY1, the OLED display interface switches between the temperature and humidity interface and the clock interface.
Below is the clock interface

Current time.jpg

The demonstration video is on station B: https://www.bilibili.com/video/av629535413
It has been updated to the V2 branch of GitHub (gitee has not been updated synchronously, and the V2 branch is still the V1.2 version of the code). You can use VS CODE+Embedded IDE to open and edit the project.

2021.2.28: V1.2: The GitHub code has been covered by the V1.5 version, and Gitee can download this version of the code

  1. Modify interface
  2. Solve the problem of not being able to check temperature and humidity when not connected to WiFi
  3. Solve the problem of OLED display stuck after APP network distribution
  4. KEY0 is used to trigger Smart Config and cancel the definition of KEY1 function
  5. Added new OLED screen to display network connection status below
Connected to cloud interface

20210301_192840.jpg

Smart Config interface

20210301_192915.jpg

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-22 05:54:09

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号