aerobotics

[Tuya Smart] Intelligent motor (window) controller +272650A

 
Overview

Introduction

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)?

hardware design

1. Power supply

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. image.png

2. Motor drive

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. AT8870.png

3. Raindrop detection

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.

4. Temperature and humidity detection

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. image.png

5. Buttons

  1. Network distribution button: Press the button to enter the network configuration state and switch between smartconfig and ap config.
  2. Window closing button: Press it to enter the window closing operation (rotating motor), press it again in the middle to pause, and then press it again to continue the remaining window closing operation. At the same time, the screen will show that the window is closing.
  3. Window opening button: Press to enter the window opening operation (reverse rotation of the motor). The operation logic is the same as above. At the same time, the screen will show that the window is opening.

6. OLED display

image.png Display content:

  • Clock (software RTC, uses Tuya module NTP function to synchronize the clock regularly).
  • window status
  • switch status
  • Real-time weather (using Tuya module weather forecast function)
  • Indoor temperature and humidity (provided by onboard HDC1080)
  • When pressing the button, it will prompt whether the window is opening or closing. The OLED driver chip is SSD1315, global refresh mode. The initialization code is slightly different from the popular one on the Internet.

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.

All resistors and capacitors in the schematic diagram support Jialichuang SMT basic library.

Radial flow chart.png

software design

  • The software project was created in RT-Thread Studio. Since the MCUSDK of the Tuya module handles all network requests, no RT-Thread software package is used. The project uses RT-Thread software RTC. NTP time synchronization and weather information acquisition are implemented from the MCU SDK.
  • The project makes full use of the multi-threading feature of RT-Thread and uses events to achieve mutual communication between threads.
  • The project uses the automatic initialization feature of RT-Thread, so there are basically no other initialization functions in main().
  • RT-Thread version: 4.0.3
  • RT-Thread Studio version: 2.0.0

About OLED driver and hardware I2C

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.

About HDC1080

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.

Brief description of source files:

├─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.

Github address

Github project address

picture

second edition physical First version 3D preview
IMG_5693-2.jpg 3D_transparent.png

screenshot.png

final advice

  1. Try to isolate the power supply of the motor part, otherwise it may cause interference to the OLED display.
  2. If it is not isolated, at least add an expansion board 5V output anti-backflow diode.
  3. If you use applications such as push rods that do not require speed regulation, relays are the best.
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-07-01 01:04:56

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号