ghaytweyhtoo

[V2.0 in design] 51 control EMW3080 connected to Alibaba Cloud smart switch switch

 
Overview

If you don't win the award, you won't be embarrassed and the content will be ignored. . sad!

This article is updated in chronological order. You can read from bottom to top when reading:) If you have read the previous ones, just read the latest content:)

Table of contents:

1. I updated the demo video of this project on August 22. Friends in the group said that my vertical video was very tiring to watch. . . Then I will make a new horizontal version:) (PS: Some browsers may find that the video is jittery when watching this video. In fact, there is no problem with the video. You can download the video directly to watch);

2. Updated on August 19th to upload the revised content of temperature settings in Alibaba Cloud and Teacher Hu’s method to solve the problem of out-of-sync between mobile APP and buttons;

3. Updated on the afternoon of August 18th. There are some things that need attention and debugging methods in serial communication;

4. On the morning of August 18, the method of displaying the temperature around the device on the mobile APP was updated;

5. The EMW3080V2P module was updated on the evening of August 17 to start the device AP mode distribution method (code part): (the attachment code has been updated);

6. Updated on August 16: Precautions for hardware welding and software debugging;

7. August 11th diary: Project establishment and basic design ideas;

At the end of the article, a video of IoT controlled light switch, a simple reflow soldering video and the code and tools mentioned in the article are attached:)

IMG_0955.jpg

===========I === is === time === time === division === division === line ============= =

On August 19th, the temperature was updated to upload the revised contents of Alibaba Cloud settings and Teacher Hu’s method to solve the problem of out-of-sync between mobile APP and buttons:

As I said before, when setting the mobile APP screen, the temperature displayed on Alibaba Cloud is inconsistent with the actual temperature. During accidental debugging yesterday, I discovered that as long as the temperature range is set to 0~50 degrees Celsius in the string attribute, the problem of inconsistent temperature display on Alibaba Cloud can be solved.

tep01.png

tep02.png

The following is the solution introduced by Teacher Hu to solve the problem of out-of-synchronization between mobile APP buttons and physical buttons:

Looking at the source code, we found that after our device was connected to Alibaba Cloud, our device information was not reported to Alibaba Cloud within 5 minutes. Therefore, we only need to actively upload it after being connected to the Internet to solve this problem:

The file is in Wifi.c and the attachment has been uploaded.

sb01.png

===========I === is === time === time === division === division === line ============= =

Updated on the afternoon of August 18th. There are some things to pay attention to and debugging methods in serial communication:

1. On the evening of the 17th, Teacher Song said that when CH340C communicates with the 51 microcontroller, it is necessary to prevent backflow to prevent the 51 microcontroller from being unable to reset. My solution uses a Schottky diode, and Teacher Song’s solution uses a 330 ohm resistor. Because I have not actually tested the resistor, if you are interested, you can try it. The resistor can also be directly soldered to my Schottky diode pad, and there is no big problem.

SS24.png

2. Regarding the method of checking the data sent by the test microcontroller to the EMW3080, because my board is mainly used for engineering proofing, I directly reserved the IO terminals of each module. You only need to connect the TXD2 of the microcontroller (or the 10-pin RXD0 of the EMW3080 ) connected to the RXD of CH340, you can read the data sent by the microcontroller to the 3080. Every time the system starts, you can see what the microcontroller has sent to the 3080. If you press the reset button, what the microcontroller has sent:) For example, switch status? Temperature status? I hope you guys can figure out more functions by yourself. I used a separate CH340 module for testing. The one on the original board can also be used, but it requires jumpers. I find it troublesome, so I just use the off-the-shelf one.

tx1.png

Of course, Alibaba Cloud also has the option of device debugging. You can also get the status of the device on the left. I feel that the content on the right may be a little encrypted and I can’t understand it, so I just ignore it!

tx3.png

===========I === is === time === time === division === division === line ============= =

On the morning of August 18th, the mobile APP was updated to display the ambient temperature of the device:

Regarding the temperature display, it is actually relatively simple. We only need to solder the DS18B20 to our board. In the actual test, I found that not all DS18B20 can read the temperature value, so it is best to choose according to DATASHEET.

We don’t need to modify the code part, because Teacher Song’s code already contains this part (this part of the code may have a small bug, that is, the temperature value cannot be obtained occasionally). The main thing that needs to be modified is Alibaba Cloud. We looked at WIFI.C and found that the two key strings associated with our code and Alibaba Cloud are "CurrentTemperature" (temperature) and "PowerSwitch" (switch).

tep1.png

I mentioned PowerSwitch on the 15th, so I’ll mention it again here. These two strings correspond to our Alibaba Cloud location:

tep2.png

Many friends have said that they have added switches and temperatures, but either they cannot control them or they do not display the temperature. In fact, this is the problem here. Of course, if we want to develop the control of relay 2 or other controls in the future, we only need to add the corresponding keywords in the code and the corresponding keyword attributes in Alibaba Cloud.

Then we go to the human-computer interaction/device panel to update our APP side panel. It should be noted that the temperature displayed on the customized panel may be wrong, and the actual display on the mobile phone shall prevail.

tep4.png

tep3.png

In this way, we get the temperature display around our device on the mobile phone:

tep5.png

At this point, our device has completed the functions of device AP network configuration, manual device control, mobile APP control, mobile phone viewing of device surrounding temperature, etc. We have also got rid of the need to use the serial port assistant to manually send AP network configuration instructions every time the network is configured. embarrassing situation.

Later, you can consider updating the switch control of relay 2, controlling the LED1~LED5 of the panel, and setting the operation of the empty KEY1~KEY4. For example: setting the Alibaba Cloud platform, if the ambient temperature of the device is detected to exceed 50 degrees. , start the relay 2 fan to cool down the device, etc. (The main logic of the code is: locally collect the temperature of DS18B20, about once every 10 seconds. If the collected temperature exceeds 50 degrees, it will be reported to the Alibaba Cloud platform and a warning will be issued. The device will control relay 2 by itself. Turn on the fan. Of course, this may be more of a local operation, Alibaba Cloud is only responsible for issuing warnings)

===========I === is === time === time === division === division === line ============= =

EMW3080V2P startup device AP mode network configuration code part updated on the evening of August 17th: (The attachment code has been updated)

On the evening of the 16th, Song Gong introduced the problem of the 3080V2P network distribution method. There are two main types of 3080 network distribution methods: one is one-click network distribution, which has poor compatibility, but is more convenient. The command is AT+ILOPAWSSTART, and the other is It is a device AP network configuration method with good compatibility and slightly complicated operation. The command is AT+ILOPAWSAP. Of these two methods, my network environment only needs to use the latter one, and it is very convenient to change the code. Simply and crudely replace AT+ILOPAWSSTART in WIFI.C with AT+ILOPAWSAP. However, this kind of modification is not conducive to reading, and it has the meaning of selling dog meat to others. So we re-add a few lines and modify it as follows:

1. Comment out the one-click network configuration in WIFI.C and add a new AP network configuration

AP1.png

2.Add a line in WIFI.H

AP2.png

3. Comment out the one-click network configuration and adding AP network configuration in the main program Main.c

AP3.png

After completing the above 3 steps, you can perfectly change the one-click network configuration to the device AP network configuration. This distribution method has good compatibility and is more practical.

In fact, if you want to have both one-click network distribution and device AP network distribution, you can consider following Teacher Hu’s approach:

ap01.png

AP02.png

The difference from what Teacher Song said in class is that this delay code is actually added to main.c, not wifi.c. Through the above code, we can complete the one-click network configuration first. If the one-click network configuration is unsuccessful, the device AP network configuration will be started after 60 seconds. Of course, this method doesn't make much sense for someone like me who can't succeed in one-click network distribution anyway, so GF friends can make their own decisions.

===========I === is === time === time === division === division === line ============= =

Updated on August 16: Precautions for hardware welding and software debugging:

1. I got the board on the morning of August 15th and first measured whether the MCU chip pad and each IO port line were normal or not. The measurement points of the actual test board were all normal and there were no problems. Welding begins immediately.

2. The first thing to solder is the Typec port and MCU. This is relatively simple and can be done with a high-temperature blade and flux. I don’t know if it’s because of my age, but the direction of the small dots is reversed. I have no choice but to dismantle and re-weld it. Fortunately, this is not difficult, so skip it.

3. After welding the right half, test the core board system of the right half first. Pressed the reset button, but it didn't work? ? ? After pressing reset, even if the ME6215C33M5G enables the terminal to be connected to a low level, the output voltage is still 3.3V? There were various doubts. First, I suspected that the LDO was bad. After removing the two faults, the fault persisted. After removing the LDO, the output pin of the LDO was still 3.3V? ? In the entire circuit, the LDO on the left was not soldered, and the CH340C on the right except the LDO was powered by 5V. Then I suspected that there was something wrong with the CH340C. The 3.3V pin might be faulty. After picking it up with a needle, the fault remained. There is no way to dismantle the entire CH340C. Now the output of the LDO no longer has 3.3V. I know there is a problem with the CH340C, but how to solve it? The first thing that came to mind was to change the CH340C power supply to 3.3V, so the PCB circuit board was cut off manually and the wires were flown to 3.3V. Here comes the problem. After the enable terminal of the 51 microcontroller is reset, the 3.3V drops to 0. At this time, the CH340C stops working and cannot be programmed. . . . It's okay, it doesn't bother me. There is an LDO on the left side of the circuit board. . . After a few operations, the LDOs on the left and right sides are all done, and the CH340C is normal, but it still cannot be programmed? ? ? The programming software could not recognize the 51 microcontroller. I checked the pins of the 51 microcontroller and found no problems. Ten thousand grass and mud horses galloped past in my heart! There is only one possibility left, that is, there is a communication problem between the 51 microcontroller and the CH340C. After checking some information, I estimate that there may be a backflow between the RXD of the 51 microcontroller and the TXD of the CH340C, and then a Schottky diode flew on the back of the board. Tested again and the function returned to normal! Then I tried to restore the 5V power supply system of CH340C, and it turned out to be normal? ? ? Well, the 51 microcontroller system is OK!

The PCB modification is as follows: Cut off the connection between the 3.3V pin of CH340C and the 3.3V pin of other components, and connect diodes in series with the RXD of CH340C and 51MCU.

3.3V off.png

SS24.png

4. After the entire right side is completed, weld the left side immediately. There is no problem with the hardware circuit on the left side. Start debugging after welding (reminder, do not use washing water to clean 3080, you will regret it after spraying, refer to my pictures~) . The software part is really where the nightmare begins. . . My software part is relatively weak. After repeatedly compiling the program, I still cannot configure the network for the EMW3080V2P. I spent nearly 5 hours on this part. In the middle of the night on the 15th, Teacher Hu in the group pointed out to me that the software part of Teacher Song may be The defect is that after the entire system is started, the microcontroller completes the AT command output to the EMW3080, but the output AT command only lacks the command to make the EMW3080 become an AP. . . In this way, no matter how you use your mobile phone to configure the network, you will not be able to find the EMW3080 AP and cannot proceed. Teacher Hu instructed us to use serial communication tools and manually turn on the AP mode of 3080, and the network configuration was successful! At about 12 o'clock, Teacher Song went online and reminded that it is not necessary to set the network configuration mode to the device AP mode. You can try using the one-click network configuration mode. Teacher Hu's test was successful, but I was not so lucky. No matter whether you change your mobile phone, router, or mobile phone AP, you cannot successfully configure the network using the one-click network configuration mode. I also searched Baidu for this. Although this mode is convenient, it is not supported by some devices and has limitations. Then we will still use the device AP mode to configure the Internet cafe:) There is a download of Mr. Hu’s serial port debugging tool in the group. AP.png

5. After completing the network configuration, at first glance it seems that all functions should be normal. At this time, there are actually two problems: first, the mobile APP cannot control our device normally; second, it needs to be restarted every time. After reconfiguring the network, although the device indicator light appears to be online, the device on Alibaba Cloud is offline. So for these two questions, the first question is that in the code, Teacher Song uses the PowerSwitch switch, so in the Alibaba Cloud configuration, you need to manually add the switch button. The switch button is PowerSwitch. After modification, the problem can be solved. Second question, I used the serial port assistant to capture packets, and found that the triplet sent by the 51 microcontroller to the 3080 each time was not the one I asked to write, but I searched the entire code and could not find this triplet. I suspect it was the first time I was lazy and used a file compiled by someone else. After writing it to my FLASH, I couldn't refresh it. Try clearing the EEPROM when burning the program to solve the problem!

power.png

QQ screenshot 20200816174735.png

The current situation is that this board meets the exam requirements:) However, there are still problems. For example: the relay part is still empty and does not play a role; the code part has never written the command to make the 3080 become an AP when distributing the network, resulting in the need When distributing the network, AT commands need to be used for collaborative operations; the mobile APP operation interface is not beautified, etc. These all need to be improved later! I can only take the time to deal with it later :)

===========I === is === time === time === division === division === line ============= =

August 11th diary: Project establishment and basic design ideas:

This project is an Internet of Things control system based on the 51 microcontroller; the microcontroller is STC15W4K56S4, which should be the most powerful 51 microcontroller currently.

Isn’t it a bit overkill if it’s just used for an Internet of Things project? So...in addition to doing Internet of Things projects, let’s make a minimum core board:)

The upper left side of the board is the Qingke EMW3080V2P, the lower left side is the controlled 2-way relay; the right side is the 51 microcontroller core board. If you don't need to do the Internet of Things project one day, just cut off the left side.

Of course, it’s okay if you don’t cut it. I have set switch jumpers on both the IoT module and the relay module. I usually short-circuit the jumper caps, and just pull out the jumper caps when they are not needed.

Because I don’t know exactly how much power the relay requires, I can’t determine whether to use the 3.3V power supply of the microcontroller or the 3.3V power supply of the network module. There is no way, a two-choice jump cap is set up to choose the power supply method.

All IO ports of the core board and all IO ports of the network module have been led out, making it easy to disassemble and use them separately in the future:)

It is best to use a 1.27 pitch 4P female socket for the DS18B20, so that it can be compatible with DHT11 during actual use;

The row of female sockets on the far right side of the board can directly plug in 1602 and 12864 displays;

The IO port of the core board is silk-printed on the back~

There are a lot of vias, but there is no other way. I have to take care of the IoT module and lead out all the IO ports. I am also greedy and want to plug in 1602 and 12864. I can’t bear it!

WeChat picture_20200816235030.jpg

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-23 13:02:00
  • 【Uncle T's Library】Principles of Medical Instruments
  • Do you want to develop games for arcade machines and other devices?
  • Application of Load-Pull Principle in RF Power Amplifier Design
  • Ultrasonic sensor probe selection
  • 2016 year-end summary
  • USB Type-C Knowledge Quiz Prize Turns into a Twist

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号