ghaytweyhtoo

Tencent Cloud IoT Smart Desk Lamp

 
Overview

1 Project Introduction

1.1 Project introduction

Desk lamps are the most frequently used electrical appliances in daily life. I will introduce to you how to make a smart desk lamp that can be remotely controlled using the WeChat applet. This desk lamp is easy to operate and can flexibly adjust the brightness and color temperature. The OLED display on the development board can display the status of the desk lamp in real time. It also has a WS2812 light strip interface and a variety of built-in colored light modes, which can be used as an ambient light. All software and hardware designs are open source, and friends with strong hands-on skills can also transform your own smart desk lamp on this basis. For answers to related questions, please see the Q&A section at the end of the article.

1.2 Material list

TencentOS_tiny_EVB_G0 development board x1 E53 interface LED driver module x1 (needs to be welded by yourself, see the link below for a detailed list of materials) A set of basswood board casing (needs to be processed by yourself according to the drawings) Dual color temperature LED lamp x2 (Search for "Rohm led light strip for the same model in the article" ”) 150 20 6 mm Radiator x2 12V 1A Power supply x1 (To protect the environment, you can use the power supply of old routers, TV boxes, etc., the output voltage is 12V, the output current is 1A or higher) Gooseneck x1 Gooseneck matching iron clip x1 Gooseneck matching nut, some UHU glue, wires, solder, soldering iron, tweezers, wrenches and other materials and tools

1.3 Project link

Video demonstration https://www.bilibili.com/video/bv1BK411G7cn

Project source code https://gitee.com/dma/iot_led.git

2 Hardware production

2.1 TOS_EVB_G0 development board

TOS_EVB_G0 development board is an IoT development board designed by Tencent TencentOS-tiny team. Its appearance is as follows:

board1.jpeg

  • The main control chip uses STM32G070RB, with a Flash space of 128KB and a RAM space of 36KB;
  • Onboard Tencent Cloud customized firmware version ESP8266 WIFI module;
  • Onboard E53 sensor standard interface makes it easy to connect various E53 sensors;
  • Onboard 128*32 OLED display screen;
  • Onboard 8MB SPI Flash, can be used for firmware upgrade;
  • Onboard CH340 to serial port connection, you can use a USB cable to connect to the computer to view the serial port log;

Below is a detailed description of each part:

Detailed explanation of the development board hardware circuit (1) Minimum system circuit The minimum system part consists of power circuit, clock circuit, Boot circuit, reset circuit and download circuit:

board2.png

(2) WIFI circuit The WIFI part includes the ESP8266 WIFI module power supply circuit and serial communication circuit:

board3.png

(3) E53 expansion interface circuit The E53 expansion interface is used to connect external sensors, including: a serial port, an SPI interface, an IIC interface, four ordinary GPIO ports, an ADC analog acquisition interface, and a DAC analog output interface, as shown in the figure:

board4.png

(4) USB to serial port circuit The USB to serial port circuit converts serial port information into USB port signals, so that the development board can be directly connected to the PC through the USB cable, and use the serial port assistant on the PC to view the log:

board5.png

(5) OLED display screen circuit The OLED screen part includes the OLED power supply part and the communication part:

board6.png

(6) Connect the Micor USB cable

board7.jpeg

(7) Connect the ST-Link downloader development board 3v3---> STlink 3.3V development board DIO---> STlink SWDIO development board CLK---> STlink SWCLK development board GND---> STlink GND Please refer to the following Make the connections as shown in the figure, be sure not to reverse the connections to avoid burning the MCU.

board8.jpeg

2.2 Desk lamp shell and structure

First, you need to purchase goosenecks, iron frames, nuts and other parts. The specifications are as follows:

It is recommended that the gooseneck be 40-60cm long, hollow and hard. Pay attention to the inner diameter of the gooseneck not being too small, otherwise it will be difficult for the wires to pass through. Be sure to choose a hard gooseneck to ensure it can withstand the weight of the lamp. , the thread specifications at both ends are M10 fine-thread flat head and M8 fine-thread round head. The flat end is mainly used to connect to the clip, and the round head is used to connect to the lamp shell, making it easy to adjust the angle of the lamp. If you can't buy it, For the same specifications, try to buy goosenecks with similar parameters.

100.jpg

When purchasing an iron clip, pay attention to the shape of the opening. It is best to use a flat hole, which is convenient for fixing the gooseneck and ensures that it will not rotate. If you cannot buy a flat hole, you can also use a round hole for the clamp and the gooseneck. Remember to tighten the nut slightly. Tighter

110.jpg

Of course, remember to buy matching nuts, some stores will give them to you.

120.jpg

Use 704 silicone rubber to stick the lamp in the middle to the radiator. Be sure not to squeeze too much glue. After the glue dries, weld the two-color LED lamp (search for "Rohm led light strip" for the same style). The yellow and yellow colors of each lamp Parallel, white and white in parallel

230.jpg

The next step is to prepare the table lamp shell. The drawings are in the doc folder of the source code. Stores usually cut on a whole piece of wood. Regardless of the actual size of the cutting, the charge is based on the entire board (different stores may charge different prices. Please contact the store yourself. communication), so it is recommended to cut several more shells in one drawing to make full use of this piece of wood and reduce waste. As shown in the picture below, 4 sets of table lamp shells and several other shells are cut on a piece of wood.

210.jpg

The actual measured single lamp lighting is a bit dark. It is strongly recommended to use two lamps. Do not use the single lamp parts marked in the picture below. B1 and B2, G1 and G2, H1 and H2 are exactly the same. The difference between F1 and F2 is The diameters of the openings are different, one is 8mm and the other is 10mm. If you cannot buy a gooseneck of the same specification, it is easy to replace.

200.png

Glue H1 and H2 to A. The main purpose of this step is to increase the overall thickness of the shell and ensure that there is a certain lightness at the openings of F1 and F2. Otherwise, the openings and the frame are too close to each other and will easily break.

201.png

Insert F1 or F2 into the corresponding hole of A as shown by the arrow in the drawing. B1 and B2 are installed vertically on both sides of A. At the same time, insert F1 or F2 into the hole. Align C and D and glue them together. Place C according to the arrow. Assemble as shown

202.png

After the glue in the previous steps is dry, put the lamp tube into the casing and pass the wire through the hole reserved for E. Finally, install E as shown by the arrow.

203.png

Finally, install G1 and G2 as shown by the arrows. The wires also need to pass through the reserved grooves.

204.png

Before assembling, it is recommended to place it as shown in the picture below to ensure that you have not picked up the wrong parts, and then complete the assembly.

239.jpg

The final assembly is like this, for your reference. Be sure to pay attention to the order when installing, and thread the wires and nuts in advance to avoid rework.

240.jpg

There is a detail in the picture above. The edge of my shell is about 2mm higher than the middle part, which is reserved for installing the transparent shell. If the packaging box of something you buy is made of frosted plastic material, you can cut a piece of suitable size and cover it on the lamp shell, so that the light will be softer and not too dazzling. If you don’t have it, you don’t have to install it. If you don’t have the money, you can also find a merchant to cut a 2mm thick matte acrylic according to the size.

Notes: There are certain errors in the thickness of wooden boards from different merchants, and there are certain errors in cutting machines. Please communicate in advance. The error is generally around 0.1-0.2mm. You may need to compensate in the drawings.

2.3 E53 interface LED driver module

Please purchase components and weld them according to the material list in the schematic diagram. The module welding is completed as shown in the figure.

300.jpg

310.jpg

Please assemble it with the development board as shown in the figure below

250.jpg

Precautions

  1. The board has a reserved interface for the WS2812 light strip. If you don’t have a light strip or don’t need a light strip, you don’t need to solder it.
  2. If you do not use light strips or the number of WS2812 lamp beads is less than 5, it is recommended to use a linear voltage stabilization solution; if there are more than 5, it is recommended to use a switching voltage stabilization solution.
  3. There are two PT4115 drivers on the board. If a two-color lamp is used, the left one is connected to yellow and the right one is connected to white. If you use a single-color lamp, it is recommended to only connect one channel on the right and adjust the color temperature to 6500K. The disadvantage of this method is that it wastes one drive. If you want to drive two channels of white LED, please modify the code yourself and delete the relevant content about adjusting the color temperature. .
  4. 灯管的功率计额定电压决定了PT4115的采样电阻,目前用的是两根双色温灯管,单根灯管额定电压6V,单色额定电流300mA,这里是两根灯管的黄色与黄色并联、白色与白色并联,单色温的总额定电流为600mA,根据PT4115手册计算出0.2ohm采样电阻输出电流为500mA,因此串联两个0.1ohm的采样电阻。如果使用其他规格的灯管请自行计算采样电阻阻值。
  5. 旋转编码器旁边有一个排阻,为IO口上拉,如果单片机支持上拉可以不焊。
  6. P2、P3、R3、R4为预留测试焊盘,不需要焊接。
  7. 设计输入电压为12V,如需驱动更高电压、更大功率的LED灯管,请注意元件耐压,可能需要更换更高耐压的元件。

3 软件开发

3.1 ESP8266烧写腾讯云定制固件

3.1.1 下载固件

腾讯云IoT AT指令是一套针对使用通讯模组(2G/4G/NB/WIFI)接入腾讯云物联平台的定制AT指令集,如果通讯模组实现了该指令集,则设备接入和通讯更为简单,所需代码量更少。 ESP8266作为IoT领域使用最广泛的一款WiFi芯片/模组,腾讯云在其通用AT指令基础上,增加了腾讯云IoT AT指令集,形成一个定制的模组固件QCloud_IoT_AT_ESP8266。 下载链接:https://github.com/tencentyun/qcloud-iot-esp-wifi 使用git下载的命令如下: git clone https://github.com/tencentyun/qcloud-iot-esp-wifi.git 下载之后即可在图中圈出的文件夹中看到定制固件:

esp1.png

3.1.2 下载烧写工具

使用乐鑫官方下载工具ESPFlashDownloadTool,下载链接如下: https://www.espressif.com/zh-hans/support/download/other-tools 点击下载Flash 下载工具(ESP8266 & ESP32 & ESP32-S2):

esp2.png 下载之后解压即可。

3.1.3 固件说明

腾讯云IoT定制的AT模组固件QCloud_IoT_AT_ESP8266,适用于所有FLASH大小为2MB或者2MB以上的ESP8266模组。 AT串口使用UART0,默认的Tx为GPIO1,Rx为GPIO3。但因为ESP8266的UART0 默认会在上电启动期间输出一些打印,如果打印信息影响设备功能,可在上电期间将 U0TXD(GPIO1)、U0RXD(GPIO3) 分别与 U0RTS (GPIO15),U0CTS(GPIO13)进行交换,以屏蔽打印。因此提供两个版本的固件:

  • 名称包含UART_1_3的固件串口使用的Tx为GPIO1,Rx为GPIO3。
  • 名称包含UART_15_13的固件串口使用的Tx为GPIO15,Rx为GPIO13。 进入QCloud_IoT_AT_ESP8266_FW,本文中我们使用第一个固件:

esp3.png

3.1.4 烧写固件

切换boot选择端子和串口选择端子 (1)将开发板上的ESP8266启动引脚配置端子切换到低电平; (2)将开发板上的串口选择端子置于中间,使ESP8266直接与PC串口连接: 方法参考下图:

esp4.jpeg

运行Flash烧写工具 双击工具,运行:

esp5.png

选择开发者模式:

esp6.png

选择ESP8266下载工具:

esp7.png

开始下载 按照图中进行操作:

esp8.png

点击下载之后,按下开发板上的复位键,Flash下载工具开始下载:

esp9.png

若没有显示,请检查接线端子是否连接正确。

下载完成 下载完成之后如图:

esp10.png

关闭工具,将boot选择引脚拔下,将串口选择端子恢复默认。

注意:完成固件下载后,一定切记将跳线端子恢复到默认状态,默认端子怎么短接可以参考前面完整的组装成品图,否则wifi将没法工作,MCU也没法控制wifi。

3.2 工程代码修改与使用

下载TencentOS代码 https://github.com/Tencent/TencentOS-tiny.git

下载本工程代码 https://gitee.com/dma/iot_led.git

把本工程代码放在 TencentOS-tinyoardTencentOS_tiny_EVB_G0KEIL

本工程使用的是AT SDK,已经集成在工程下,因为部分功能的需要,我在官方SDK的基础上做了一些修改及适配,源码在这里 https://github.com/tencentyun/qcloud-iot-sdk-tencent-at-based

如需移植其他OS或开发板请参阅官方文档自行修改。

在腾讯物联网开发平台创建设备,具体步骤参见 https://cloud.tencent.com/document/product/1081/34738

产品定义,新建项目,新建产品,按如下配置

400.png

数据模板,选择“导入json”,json文件路径 iot_leduser_code智能灯.json,你也可以添加自己的功能,或在此基础上进行二次开发

410.png

没有修改json的话可以略过这一步,如果你之前在数据模板中添加了自己的功能或有其他修改,请点击“查看json”然后导出 ,将导出的json放在iot_ledqcloud-iot-sdk-tencent-at-based ools,cmd窗口运行python codegen.py -c 你导出的数据模板.json,重新生成数据模板代码,如果提示出错,请检查编码是否为GBK,将生成几个c文件放入 iot_ledqcloud-iot-sdk-tencent-at-basedusr_logic,打开 iot_ledqcloud-iot-sdk-tencent-at-basedusr_logicdata_template_usr_logic.c,在 static void deal_down_stream_user_logic(void *pClient, ProductDataDefine * pData) 中开发你自己的功能。

交互开发,面板配置这里按自己的需求摆放各个组件、设置图标等,点击左边的箭头可以设置图标顺序,样式和图标可以按自己的喜好进行更改,也可以照搬这个设计

420.png

设备调试,设备端代码编译并下载后你可以在这里在线调试

打开 iot_leduser_codeuser_config.h 找到你刚刚创建的设备,填入设备密钥、产品ID、设备名

430.png

填入你家的wifi名和密码(如果作为一个真正商用的产品,应该通过配网或其他方式来获取wifi信息,不应该在代码中写wifi名和密码,因为你不可能知道用户家的wifi,目前配网功能有,但还不完善,就先这样用吧)

打开TencentOS-tinyoardTencentOS_tiny_EVB_G0BSPIncstm32g0xx_hal_conf.h打开这处宏 /* #define HAL_TIM_MODULE_ENABLED */

打开TencentOS-tinyoardTencentOS_tiny_EVB_G0TOS_CONFIG os_config.h 修改#define TOS_CFG_TASK_DYNAMIC_CREATE_EN 0u#define TOS_CFG_TASK_DYNAMIC_CREATE_EN 0u 由于启用了动态创建任务,任务栈会从对内存申请,所以系统堆内存适当改大一点,避免溢出#define TOS_CFG_MMHEAP_DEFAULT_POOL_SIZE 0x2000

最好结合自己的代码,在系统完全运行起来以后使用k_err_t tos_mmheap_check(k_mmheap_info_t *info);查看内存使用情况,适当修改对内存的大小。如果出现莫名其妙的死机、重启等问题,大概率是内存不足溢出了。

打开 TencentOS-tinyoardTencentOS_tiny_EVB_G0BSPSrcstm32g0xx_it_module.c 添加头文件#include "hal_at.h" 添加extern sRingbuff g_ring_buff; 修改

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
    /* data is defined in usart.c */
    extern uint8_t data;

    if (huart->Instance == USART2) {
        HAL_UART_Receive_IT(&huart2, &data, 1);
        tos_at_uart_input_byte(data);
    }
}

如下

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
    /* data is defined in usart.c */
    extern uint8_t data;

    if (huart->Instance == USART2) {
        HAL_UART_Receive_IT(&huart2, &data, 1);
        // tos_at_uart_input_byte(data);
        ring_buff_push_data(&g_ring_buff, &data, 1);
    }
}

编译下载运行

4 使用演示

设备菜单选择配网,打开微信,在主页面下拉,搜索“腾讯连连小程序”,点击加号添加设备,在电工照明中选择灯,按照提示进行配网。详细操作步骤请看视频演示 https://www.bilibili.com/video/bv1BK411G7cn

5 Q&A

Q: Why not use github but gitee? A: Based on the domestic network conditions, when using github, the situation "I can't upload and you can't download" often occurs. Gitee does not have this problem and supports domestic products by the way.

Q: The code of TencentOS is too large and the domestic network conditions are not good. What should I do if git clone always fails? A: Use gitee to create a new warehouse, choose to import an existing warehouse and fill in the information. https://github.com/Tencent/TencentOS-tiny.gitAfter the background synchronization is completed, you can use it like github, which is very fast.

Q: How to supply power to the E53 module and development board? A: Just use a 12V power supply to connect to the E53 module. The 5V power supply of the TOS_EVB_G0 development board and the E53 module itself comes from the step-down of the E53 module. The 3.3V power supply of the TOS_EVB_G0 development board and the E53 module itself comes from the step-down voltage of the TOS_EVB_G0 development board.

Q: What is the power supply capability of the E53 module? A: According to the current design plan, the maximum output current of SY8120B1ABC is 2A. If you need to drive more WS2812 lamp beads or supply power to other high-power loads, please replace other pin-to-pin compatible chips and select appropriate peripheral components according to the chip requirements. . There is currently no suitable inductor on hand. The one used in the picture is a 47uH inductor with a large internal resistance. When the measured output current exceeds 600mA, the inductor heats up seriously.

Q: What are the precautions for driving LED light strips with the E53 module? A: The current design power supply voltage is 12V, and it is recommended not to exceed 15V. 3V, 6V, 9V LED lamp beads or light strips that can be driven under 12V. Since PT4115 is a step-down LED driver chip, the theoretical input voltage is higher than the rated voltage of the LED. From the actual measurement, it can drive a 12V LED light bar, but the effect is not ideal and it is not recommended to be used in this way. The maximum output current of a single PT4115 is 1A. Pay attention to the power of the LED light strip and modify the appropriate sampling resistor.

Q: How to determine the value of the sampling resistor of PT4115? A: Please calculate the actual sampling resistor value based on the rated power of your LED light strip. The PT4115 driver on the E53 module reserves two sampling resistor pads. You can short-circuit one pad, connect two resistors in series, or Various resistance values ​​are combined by various means such as resistance stack welding. The calculation formula for the relationship between resistance and current limit is Iout = 0.1 / RS (RS ≥ 0.082 ohm), where Iout is the output current when the duty cycle is 100%, that is, the maximum output current. For more details, see the PT4115 data sheet.

Q: What are the precautions if using an input voltage above 12V? A: Pay attention to replacing capacitors and chips with higher voltage resistance. The maximum input voltage of the buck chip SY8120B1ABC is 18V. Please replace other pin to pin compatible chips with higher voltage resistance, such as SY8291ABC, SY8401ABC, ME3116AM6G, LM2841XBMKX, etc., more Chips can be purchased on Lichuang Mall.

Q: How to choose between linear voltage regulator and switching voltage regulator? A: If a high-power 5V load drives more than 5 WS2812s, it is recommended to use a switching voltage stabilization scheme. Otherwise, please use a linear voltage stabilization scheme. You can use AMS1117-5.0 or HT7150-1, etc. The maximum input voltage of AMS1117 is 18v, and the maximum input voltage of HT7150 The voltage is 30V, please select according to the input voltage. Linear voltage stabilization and switching voltage stabilization share the C1 and C3 capacitors.

Q: Why does the lamp not light up when the brightness is set to 2%? A: The effective duty cycle range of PT4115 is between 4% and 100%. If it is below 4%, it will be considered off. The performance of different batches of chips also varies slightly. Please refer to the PT4115 data sheet for details.

Q: What should I do if I use a 12V power supply and want to drive an 18V or higher voltage LED tube? A: The current solution is a buck LED driver, which does not support boost. If necessary, a boost LED such as SY7200AABC can be used. Please modify the circuit diagram and PCB by yourself. There is currently no finished product design plan.

Q: How are so many lighting effects achieved? A: Based on the github open source project WS2812FX , adapted to the arduino interface, the source code cpp is modified and adapted to the c language, which is relatively simple and crude, see WS2812FX_C_Lang

Q: Can this module be used on TencentOS_tiny_EVB_LX, TencentOS_tiny_EVB_MX_Plus and other development boards? A: Currently, it is only guaranteed to work properly on TencentOS_tiny_EVB_G0. Other development boards may need to transplant some codes. Pay attention to modifying the pin PWM output, WS2812 driver timing, etc. Some development boards corresponding to the E53 interface GPIO4 and GPIO5 may not be able to output hardware PWM. You may consider Software PWM or flying wires from pins that can output PWM.

Q: Where can I get the TencentOS_tiny_EVB_G0 development board? A: I don’t know either. I got this board from an event. I searched for “Internet of Things Club” on a well-known domestic e-commerce website. This store may have some for sale. If not, how about you draw one yourself based on the principle?

Q: The device goes offline after the router is restarted. Is there any solution? A: The official ESP8266 customized firmware does not support automatic reconnection when wifi is disconnected. You can only restart the device and wait for automatic reconnection. If you know the wifi password, you can also call AT+CWJAPthe command in the code to reconnect.

Q: Do you plan to release a finished product? Or do small batches? A: Personal energy is limited. Whether it is the E53 module or the entire set of desk lamps, I do not plan to produce finished products or small batches. All design solutions are open source. If you are interested, you can make your own. If you feel that my solution is not comfortable to use, you are welcome to modify it yourself. If you don’t want to do it, you can Buy branded smart desk lamps directly. The few remaining PCBs on hand may be given to friends and colleagues.

Q: Why are the schematics and PCB released by open source different from those shown in your article? A: Some chips compatible with SY8120B1ABC pin to pin require freewheeling diodes, but SY8120B1ABC does not, so this diode is added to the schematic and PCB without affecting use.

Q: Why does the light flash when the device is restarted and powered on? A: This is related to the MCU and LED driver chip. The GPIO of stm32 defaults to floating output when it is powered on, while the control pin of PT4115 has a 1.2M pull-up resistor inside. When the GPIO of stm32 has not been initialized and is pulled low, it will Turn on the LED light. Solution: You can weld a suitable pull-down resistor on the reserved pad. The value of this resistor in this solution is about 50K-100K. Note that the value of the resistor cannot be too small to avoid insufficient GPIO driving capability of the MCU. Can't pull it up and the LED light won't light up

Q: Can you provide technical support? A: Personal energy is limited, just let it happen! Leave a message and I will try my best to reply

Q: Can this solution be used commercially? A: Please comply with the open source agreement.

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-05-15 03:22:35
  • nRF905 in debugging
  • CC2530 CSMA/CA
  • Packaging is critical to LED reliability, but technology still needs to be improved
  • Ask vxworks dual network card communication
  • How to remove the title bar of the evc4.2 dialog box?
  • [CY8CKIT-149 PSoC 4100S Review] + Porting Program Code

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号