Click to view the past lives of this project . This project iterated on two hardware versions. First version: L298N H-bridge chip + toggle switch dual power supply switching + temperature and humidity sensor + light sensor + dual optocouplers. Second version: AT8870 H-bridge chip, remove the toggle switch, add OLED interface and location, remove the light sensor. Remove an optocoupler. Add three buttons.
This project contains an AT8870 H-bridge driver to drive the motor. There is also an external raindrop sensor interface and an onboard temperature and humidity sensor. The AP6212 onboard ART-Pi cannot be connected to Tuya, so the Tuya WB3S module is used instead to connect to Tuya Cloud through MCU access. The operating system uses RT-Thread and the Tuya MCU SDK is integrated into the RT-Thread project. MCU development IDE uses RT-Thread Studio.
The hardware is an expansion board based on ART-Pi, and the pin header is designed according to the ART-Pi expansion pin. The software of this project must be used with this hardware and ART-Pi to connect to Tuya Cloud. When used independently from the ART-Pi, it can also be used as an external motor driver board.
Using RT-Thread to connect to Tuya, maybe my project is the first one on this site (on the entire network)?
Because the motor requires 24V input, the power supply solution: The power supply inputs 24V from the expansion board, converts 24V to 5V through the onboard TPS54331 of the expansion board, and then supplies power to the ART-Pi through the +5V_USB pin of P1. The 24 power supply DC port is designed with overvoltage and overcurrent protection circuits.
The motor driver uses a single-channel H-bridge current control motor driver AT8870. Features:
●Wide voltage power supply, 6.5V-38V
●Low RDS(ON) resistance
●PWM current rectification/current limiting
●Support low-power sleep mode
●Over-temperature shutdown circuit
●Short circuit protection
●Under-voltage lockout protection
●Automatic fault recovery
●3.6A peak drive output, 2A continuous output capability.
The original plan used an electronic push rod, which can be driven directly with 24V, and the positive and negative poles can be reversed to move in the opposite direction. As a result, I used an AT8870 during the test. It seems that the AT8870's driving capability is not enough, so the demo was changed to drive a small current motor. It is still OK to use it to pull a curtain or roller blind.
The external raindrop detection module was originally planned to use the onboard LM393 comparator to determine whether it is raining. Finally, I decided to use ART-Pi's ADC directly for detection. Since too high speed is not required, DMA is not used, and it seems that the RTT framework does not encapsulate ADC's DMA? So just use a task loop detection. The raindrop detection interface also reserves digital input, and it can also determine whether it is raining through interrupts generated by the high and low levels of the external module.
Instead of using the common SHT31, TI's HDC1080DR is used, and it is cheaper. Finally, it was designed to the upper right corner of the board, isolated by slots, and the bottom through holes were opened to minimize the impact of the board's own heating on the temperature measurement.
Display content:
Note:
RTT and RTT Studio were in contact for the first time, hoping to get all the code done at once. I already have the foundation of freeRTOS and CubeMX, so it shouldn’t be a problem. First attempt at using a multi-page schematic. Fairly smooth.
At first, I tried RT-Thread's u8g2 software package, and it was indeed able to drive the OLED screen quickly. However, it uses GPIO to simulate I2C, but does not use RT-Tread's software I2C framework. Both of my I2C devices are hung on this I2C bus, which is very troublesome to modify. So I gave up software I2C and switched to hardware I2C. Then I encountered the legendary STM32 I2C lockup problem, which was solved by re-initialization. There are many problems encountered in driving OLED. At first, the partial refresh method was used, but some partial misalignments would randomly occur. Then I switched to global refresh, but it was vertically misaligned by 4 bits when booting. Then I debugged it for a long time and fixed it by modifying the offset settings. However, I found that misalignment will gradually occur after running for a long time. This is a very strange phenomenon. This problem has not occurred on other chips. Maybe it has something to do with the way I2C lockup is handled? Further inspection is required.
I also tried to use hardware I2C + DMA. After struggling for 2 days, I discovered that the I2C4 derived from ART-Pi only supports BDMA, while BMDA can only access SRAM4. If you want to use DMA, you must store or map the buffer to SRAM4. This. ..It is quite troublesome to operate in CubeMX, and the LD file needs to be modified. So I gave up for now.
It also took a lot of time to debug HDC1080. At first, I tried to use RT-Thread’s HDC1000 software package (compatible with HDC1080). However, after RTT registered the software I2C1, the software package prompted that i2c1 could not be found when initializing the device. So give up. The package uses a sensor framework which makes initialization and access complicated. After switching to hardware I2C, since HAL has I2C read and write encapsulation, if HDC1080 directly uses HAL_I2C_MEM_Write(), the measurement command will fail to be sent, and the reading of temperature and humidity will also fail. There is very little information on the Internet, and finally I found inspiration from a post by a foreign netizen and solved the problem of reading it.
├─applications
│ │ app_event.c //事件和全局变量
│ │ app_event.h
│ │ app_gpio.c //配网按键相关
│ │ app_oled_hwi2c.c //oled显示相关
│ │ app_ti_hdc1080.c //温湿度传感器相关
│ │ app_uart.c //串口及天气相关
│ │ app_uart.h
│ │ app_window_control.c //电机控制相关
│ │ main.c //入口文件
│ │ oled.c //OLED驱动相关
│ │ oled.h
│ │ oledfont.h //OLED字体相关
| |--mcusdk //tuya MCU SDK
> Note: The real PRODUCT_KEY in the source code has been removed.
second edition physical | First version 3D preview |
---|---|
![]() |
![]() |
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet