ohahaha

[ART-Pi] Smart Window Motor Controller Expansion Board +272650A

 
Overview

I have heard of the name RTT for a long time, but have never had the opportunity to contact it. Taking advantage of this opportunity, I can just add a skill. It is said that RTT's software package can be easily connected to Alibaba Cloud and other platforms, so I decided to participate in this event with the attitude of learning RTT. It is planned to use the RT-Thread software package to connect to Alibaba Cloud and control the forward and reverse rotation of the window pusher push rod motor to achieve intelligent control of windows. After actual measurement, it was found that the current that the AT8870 can provide is still too small, and it cannot fully drive the push rod even under no load, so the video demonstration can only be done with a small motor. There is a chance to make a relay version to control the fader.

We originally designed a temperature and humidity sensor, but Tuya's second training camp happened to be opening at the same time, and it also focused on the MCU development model. What a coincidence, and it matched perfectly with the ART-Pi activities. So I temporarily changed the design and reserved the location of the graffiti module. One board can participate in two training camps, with different focuses on both sides.

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.

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. The power supply scheme also underwent major changes. Since the original toggle switch was eliminated, it was later discovered that an anti-backflow diode should be added to 5V so that the baseboard could be used for power supply alone. So one flew up. 24-5V power chip introduction:

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
  • Undervoltage lockout protection
  • Automatic failover
  • 3.6A peak drive output, 2A continuous output capability

The original plan used an electronic push rod, which can be driven directly by 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.pngThe most important thing is that when there is no bottom board, it can also be used as an independent motor driver board! !

3. Raindrop detection

After the board arrived, I discovered that I chose the wrong package and used a 1.5-pitch pin header... This product is much more expensive than the 2.54mm-pitch one, and I don't have pin headers with this pitch on hand. I won’t do the raindrop detection test for the time being.

5. 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. 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.
  2. 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 (using the hardware RTC of STM32H750, and using the NTP function to synchronize the clock regularly).
  • window status
  • switch status
  • Real-time weather (using Amap Weather API)
  • 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:

  • The first time RTT and RTT Studio came into contact, I struggled for many days and finally finished all the codes at once.
  • First attempt at using a multi-page schematic. Fairly smooth.

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

blockdiagram.png

software design

  • Software projects are created in RT-Thread Studio.
  • 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

There is a big difference in software between this version and Tuya version. Weather information acquisition, clock synchronization, cloud platform, etc. are all very different. This version makes more use of the RT-Thread operating system's own threads to access the network and work together.

About the clock

This project uses the hardware RTC of STM32H750 and performs clock synchronization through NTP. And I discovered a strange phenomenon. Once I operate the motor, drv_rtc. return mktime(&tm_new);will return an incorrect data. The value in the register is correct, but the timestamp returned by mktime is incorrect! Later, I had to rewrite a function: void app_read_rtc(struct tm *timeinfo), and directly pass the pointer in. Anyway, I don’t need a timestamp, what I need is the date and time.

About the weather

I have implemented automatic query of local weather based on IP.

There are actually many free weather APIs. Among the free ones, we recommend Zefeng Weather and Amap. This project finally uses Amap’s free weather API. When using it, please use the macro definition in the source code to write your own API KEY. Regarding the location of the weather, I still used a free API to obtain the location of the IP address, and then automatically obtained the local weather based on the location. The disadvantage is that it can only be accurate to the city level. The code can also customize the default location (Yuhang District in this example). If the location API cannot obtain information, the weather can be queried based on the default location.

About Alibaba Cloud

A major feature of RT-Thread is its various software packages. However, although Alibaba Cloud's software package can be connected to the server, my test results for the network distribution part are that that part has not been transplanted. If the network distribution is enabled, it will not pass the compilation. Therefore, the device cannot be configured and bound to the device through Alibaba's "Cloud Intelligence", and cannot be connected to the smart life platform for use. In the end, we could only use the Alibaba Internet of Things platform and IoT Studio to make a mobile H5 page for control. The speed response would be slower than the app control, but the display and control required for this project were still completed.

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
│  ├── amap_weather.c   //高德天气API相关
│  ├── amap_weather.h
│  ├── app_event.c      //事件和全局变量
│  ├── app_event.h
│  ├── app_oled_hwi2c.c     //OLED硬件I2C驱动
│  ├── app_window_control.c //电机控制相关
│  ├── linkkit_solo.c   //阿里云相关
│  ├── main.c
│  ├── oled.c           //OLED显示相关
│  ├── oledfont.h       //OLED字体相关
│  ├── oled.h
│  ├── sensor_hdc1080.c        //温湿度传感器相关
│  └── SConscript

|

Github address

Github project address

picture

second edition physical Mobile APP
2_1.jpg app.jpg

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-06-20 08:22:38
  • Regarding the LM2596 conversion circuit problem, the output cannot be output
  • _wcsicmp cannot compare Chinese characters?
  • What do you think of TI's lithium battery AFE chip bq76940?
  • InstaSpin FOC question
  • Share and ask for help g2553 temperature serial port
  • A small problem in the program...

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号