alYLo3

Alibaba Cloud Platform + CW32 Microcontroller Multifunctional Desktop Tool

 
Overview
 
I. Project Introduction
1. This project utilizes various environmental sensors, such as the SGP30 for CO2 and environmental quality monitoring, and the SHT30 for temperature and humidity detection.
2. An Alibaba Cloud IoT platform was built using the ESP01S for data transmission, reception, and monitoring. It also functions as a power meter for monitoring device power, such as voltage and current during mobile phone charging, and uploading data to Alibaba Cloud.
3. To fully utilize the mobile phone charger, a CH224KPD decoy chip or a Qualcomm protocol QC decoy was used to extract the charger's voltage. This voltage was then controlled by a microcontroller PWM via a BUCK circuit, transforming the charger into a desktop-level adjustable voltage source. This data can also be sent to Alibaba Cloud for monitoring.
4. A CH340K serial communication chip was added, allowing connection to a computer via USB for microcontroller serial data printing, facilitating program modification and parameter tuning.
5. A 1.69-inch TFT color screen was used for data display. TFT screens offer fine color reproduction, long lifespan, and are inexpensive.
6. The control method utilizes EC11 programming. The device is controlled by a encoder and a button, and also incorporates three W2812B ambient LEDs to provide lighting effects
. A lithium battery charging management circuit was designed, with an 18650 battery installed on the back of the board, eliminating the need for a power cord.
These are the main functions.
II. Program Function Implementation
1. The microcontroller used is the LCSC CW32F030C8T6 development board, which has complete official documentation, low power consumption, and most importantly, supports 5V power supply, which is far more convenient than the 3.3V power supply required by other brands of microcontrollers. This convenience extends beyond just the 3.3V power supply. In terms of power supply, this means that one less 5V step-down to 3.3V circuit can be designed, greatly reducing production costs and simplifying the power supply process during debugging. It's also worth reiterating that the LCSC development board provides abundant documentation, significantly reducing development difficulty. The documentation is excellent, covering everything from microcontroller introductions to program examples and environment porting. Here is the LCSC development board documentation link: https://wiki.lckfb.com/zh-hans/dwx-cw32f030c8t6/beginner/
 
2. For the development of environmental sensors, TFT screens, EC11 rotary encoders, and ESP01S, we referenced the successfully ported library files provided by the LCSC development board. The LCSC development board documentation is comprehensive, and the porting methods and steps are very detailed.
Here is the documentation link: https://wiki.lckfb.com/zh-hans/dwx-cw32f030c8t6/
 
3. Regarding the process of flashing the ESP01S module with MQTT to complete Alibaba Cloud IoT, I combined the documentation provided by LCSC development board to implement the process
of using a microcontroller to control the ESP01S initialization to generate a Wi-Fi hotspot. After connecting to the hotspot, mobile devices can view the data collected by the microcontroller through a mobile app. The detailed documentation provided by LCSC regarding using the ESP01S with the CW32 development board for direct data transmission and reception with smart devices can be found at: https://wiki.lckfb.com/zh-hans/dwx-cw32f030c8t6/module/rf/esp01s-wifi-module.html
Unfortunately, the documentation does not cover this. This document introduces how to connect devices to Alibaba Cloud. Therefore, I researched and learned to improve the device connection process for Alibaba Cloud IoT, enabling network data transmission and reception. Below are some debugging steps I took to connect devices to Alibaba Cloud, partially referencing information from a CSDN blog
: https://blog.csdn.net/yijujishouweihe/article/details/128694641.
Following this blog, I learned how to configure the Alibaba Cloud platform and completed the device setup and triplet parameter acquisition, which is a crucial step in connecting devices to Alibaba Cloud. (Based on information from LCSC development...) The program that passed the test showed code linking to Alibaba Cloud, including a section for parsing Alibaba Cloud triples. However, during actual use, the command would get stuck at the triple parsing stage, possibly due to a problem with my code. This remained unresolved. But in this blog post, I found that the author used computer software to parse Alibaba Cloud device triple parameters.
Therefore, I modified the Alibaba Cloud triple parameter parsing code in my program, commenting it out and replacing the output with the three data points parsed by the computer software. This allowed the device to connect to Alibaba Cloud and upload data via subscription. It also allows the device to receive data sent from Alibaba Cloud via serial port. When printing out the data,
please note that after establishing the device via Alibaba Cloud, you need to obtain the triplet parameters and then use computer software (which will be packaged in the attachment) to parse and fill them into the corresponding location in the program. Refer to the source code packaged in my attachment. In addition, this location in the program needs to be run according to my modifications to ensure success. Otherwise, the program will freeze.
Here is the Alibaba Cloud platform website: https://cn.aliyun.com/
The program is designed with two modes for ESP01S: one is AP mode, where the device generates a hotspot, and the other is STA mode for connecting to Alibaba Cloud. You only need to comment out the STA initialization program in the initialization program to run AP mode, and then use your mobile phone to connect to the device hotspot for data transmission and reception.
4. Voltage Spoofing Scheme PD/QC
CH224k Voltage PD Spoofing: I also referred to an article by a blogger on CSDN, link: https://so.csdn.net/so/search?spm=1010.2135.3001.4498&q=ch224k&t=&u=
I chose level control. Regarding the 1K current limiting resistor, I used four 4.7K resistors in parallel to achieve the effect of heat dissipation and power distribution.
QC deception is achieved by controlling the voltage on D- and D+ of the TYPEC wiring sequence.
A 9k and 2k resistor are connected in parallel to divide the voltage, and the microcontroller's I/O port controls the level, allowing different protocol chargers to be deduced to output their voltages.
5. BUCK Circuit Design:
To better drive the core MPSFET in the BUCK circuit, a 12V voltage is used to control the MOSFET's on/off state. A totem-pole circuit is used to drive the MOSFET, and a 5V boost to 12V circuit and a MOSFET push-pull circuit are designed.
These circuits, combined with the BUCK circuit, control the output voltage induced by the charger to achieve an adjustable voltage, realizing a desktop-level adjustable voltage source design.
6. ADC Sampling Design:
By consulting the CW32 microcontroller datasheet, four-channel ADC sampling was selected for voltage and current data acquisition. A 10K + 1K voltage divider circuit was used for voltage sampling; the INA199A current sampling chip was used for current sampling, with external circuit detection. The sampling data is relatively accurate. It should be noted that voltage sampling is incorrect during data transmission and reception with Alibaba Cloud, and this problem remains unresolved.
7. Serial Communication Circuit Design:
A CH340K serial communication circuit module was built using the CH340K microcontroller and some simple components. This circuit allows the microcontroller to communicate with a computer's serial port tools, facilitating microcontroller development and parameter tuning.
 
8. Lithium Battery Charging Circuit Design
The mature TP5400 lithium battery charge and discharge management circuit was adopted.
During the design process of the initial 5V1A charging circuit, some problems were discovered. For example, there was a wiring error in the 5V to 12V boost circuit, which was solved using a flying wire method. However, the power meter measurement circuit and the PD/QC decoy circuit were connected together, causing the power meter to malfunction. After removing the PD/QC decoy circuit, the power meter functioned normally. Additionally, the MOSFET could only output a maximum of about 9V after being turned on. Furthermore, the PWM pulse width amplitude adjustment was not ideal; the voltage step was directly fine-tuned from 4V to 9V, but irregular and difficult to control from 0V to 4V. This problem remains to be solved. All hardware circuit problems encountered have been addressed by redrawing the schematic and PCB layouts.
This is a physical verification image
. III. Hardware Function Introduction:
1. Set up and completed according to the original plan and schedule.
2. Four sets of sensors measure environmental quality. The planned DS18B20 and barometer could not operate properly and were removed. Currently, the SHT30 temperature and humidity sensor and SGP30 environmental quality sensor are operating normally.
3. Four-channel ADCs perform voltage and current detection. The software debugging is complete, and the hardware circuit has been modified but not yet verified.
4. The LCSC CW32 development board collects data and uploads it to Alibaba Cloud using ESP01S. This has been successfully implemented.
5. PWM pulse width modulation is currently possible, but some issues exist, as mentioned above, and are currently being resolved. The DC 5x2.5 output port can drive a geared motor or DC fan with voltage speed regulation.
6. TFT color screen is currently complete. 7. The WS2812B color LED bead has been successfully debugged
and now displays different colors depending on the voltage inducement mode.
8. PD and QC inducement have been successfully verified and can now support the voltage inducement
 
function of chargers supporting PD and QC protocols
. The onboard buttons include a small button and an EC11 encoder button (pressing the EC11 is equivalent to pressing a button). Device control is achieved via interrupts. The left and right buttons are conveniently named key1 and key2, as shown in the image above. The screen also displays the corresponding buttons and their status. Due to a hardware circuit error where the screen connector was installed backwards, the screen was incorrectly installed. This hardware circuit issue has been fixed.
For those who want to replicate this, the program needs
to be modified in the lcd_int.h file. The program is set to connect to the network by default upon startup and then the environment... When collecting data and reporting it to the Alibaba Cloud IoT platform, please note the following: The Wi-Fi name I set in the program is LAZXS-2, and the password is la12345678. Failure to modify this will cause the program to get stuck during initialization, preventing the device from powering on. You can manually set the same name and password for the hotspot using your mobile phone to allow the device to initialize successfully and start running normally. The program also supports AP mode, where the device generates a hotspot, and after connecting with a mobile phone, the corresponding app is opened to complete the interaction between the phone and the device. For details, please refer to the LCSC CW32 Geostellar datasheet. If you need to change it to your desired Wi-Fi network, modify the location as shown in the image,
and then press the device button key2 to enter mode two. In this mode, the device will disconnect environmental data sampling, as discovered during debugging. Sampling environment data can interfere with voltage and current measurements. In this mode, the device can be used as a power meter. Since the modified board has not been verified, according to the modified board's instructions
, the outermost part on the right is the power meter measurement section. The top port is the input port, and the bottom port is the output port. If connected incorrectly, the current will not be displayed. After connecting as instructed, it can measure the voltage and current of the device. The central Type-C port is the charging and power supply port. The circuit design disconnects the lithium battery and supplies power through the 5V boost module if external power is used.
The Type-C port slightly to the left of the bottom right corner is the voltage inducer input port, outputting through the DC x 2.5 socket. It can also measure the voltage and current output of the black socket.
The following describes how to induce voltage. The program defaults to initializing the CH224K to output 5V. Warning: The board is not running; the CH224K can induce 20V. Pressing key1 at this time will enter PD/QC voltage spoofing mode 1. Mode 1 is for spoofing four voltage levels of the PD protocol. Pressing the key once will enter the corresponding mode, and the WS2812B will light up different numbers and colors of lights. Similarly, the TFT screen will also display the corresponding information. After PD mode, there are four QC spoofing modes. The phenomena are the same as in the PD protocol. As shown in the figure,
these are the device statuses corresponding to QC spoofing.
Below are the device status images for the four PD spoofing levels
 
. Finally, the usage method of PWM pulse width modulation is as follows. The voltage spoofed as described above is generally one of four levels: 9V, 12V, 15V, and 20V. Sometimes a special voltage is required. A controllable voltage is output through the BUCK circuit. At this time, key2 needs to be pressed. When the screen displays the value 3 corresponding to key2, the corresponding PWM will be displayed as ON. If not, it will be displayed as OFF. At this time, the rotary encoder can control the PWM pulse width to achieve the purpose of voltage regulation.
 
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2026-03-27 14:44:42
  • M4 development board trial week plan submitted!!!
  • const
  • Privileged teacher FPGA read and write SDRAM program learning
  • DRV8412DDWEVM+3D PCB+real product+handmade heat sink
  • GD32E231 Learning 1: Download LED flashing program
  • 2440init.s

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号