Project source code: https://github.com/lin-kangkang/temperature-and-humidity-senso-tuya-mcur
Demo video: https://www.bilibili.com/video/BV1DA411K7TZ/
First picture:
Did you notice the time above? I stayed up late to write this article. It seems that I need to correct my procrastination problem, hhh.
Please refer to the project schematic diagram for the specific circuit.
1. First download the required MCU SDK in Tuya Workbench, as shown in the figure below:
2. Then add all the .c files inside to the process and add the header file path.
3. Enter wifi.h and add #include "stm32f10x.h" (modify according to your own chip, the chip I chose is stm32f103c8t6)
4. Finally, enter protocol.h, configure it according to your needs, and then modify it according to the compilation error prompts.
The places to be modified are as follows:
4.1. Call the serial port single-byte sending function in the uart_transmit_output function. Note that it is single-byte sending! ! !
4.2. Call uart_receive_input(value) in the serial port reception interrupt. The parameter value is the data received by the interrupt. Remember to turn on the serial port interrupt first, and try not to turn off the serial port interrupt used during program running.
4.3. Enter the function my_strcpy(char dest, const char src) and put the definition of the pointer p at the front of the function.
4.4. Call the function in the while loop of the MCU main function: wifi_uart_service()
4.5. Add wifi_protocol_init() in the main function to complete the wifi protocol initialization
4.6. Process and automatically generate data reporting function all_data_update() according to your own needs
4.7. For other errors, just comment out the line that caused the error.
The final modification results are as follows, 0 Error, 0 Warning, hahaha
1. If you need to use the function of obtaining weather, be sure to increase the size of the serial port data processing buffer, otherwise the processed data will not be received.
2. As mentioned in the above transplantation process, the serial port sending function called in the uart_transmit_output function must send single-byte data.
3. When obtaining weather data, be sure to read official reference documents to confirm the type of data, and do not just rely on your own feelings. For example, the wind speed is of string type. I was stuck here for most of the day and convinced myself.
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