A snowflake lamp based on HK32F030MJ4M6
This document contains
Snowflake lamp using HK32F030MJ4M6 as the main control
The TYPE-C female port of this product will interfere with snowflakes. When welding, it can be tilted upward to avoid the situation where thicker TYPE-C data cables cannot be connected.
I think the currently used TYPE-C female socket is more cost-effective, and the upturned welding is also an acceptable solution. I haven't found a female socket that better meets the requirements in the Lichuang Mall. Of course, if you have any better suggestions, please feel free to put them in the comment area
There are certain differences in signal timing between the WS2812 used in this project and the WS2812 sold in the mall:
WS2812 sold in the mall:
It can be seen that after receiving 24-bit data, this WS2812 will interpret it as green, red, and blue (GRB) in sequence .
The WS2812 used in this project will interpret 24-bit data into red, green, and blue (RGB) at one time .
Of course, there may be other situations in WS2812 sold on the market. If your WS2812 does not interpret data in RGB order, please modify the firmware code to adapt to your hardware.
Line 338 of the firmwaresrcmain.c file defines a function void SN_WS2812_Transmit(uint8_t* color)
, which is a data sending function. This function will be called every time the color information is updated. The passed-in parameter color is a color array, with 3 adjacent data as a group, namely R, G and B values.
You can modify lines 344 ~ 346 of this file, which are lines 6 ~ 8 in this function. The original code is
R = (uint8_t)(color[3 * pos] * LED_light);
G = (uint8_t)(color[3 * pos + 1] * LED_light);
B = (uint8_t)(color[3 * pos + 2] * LED_light);
Among them, the corresponding relationship between RGB and digits is as follows:
Bit | code |
---|---|
1 | (uint8_t)(color[3 * pos] * LED_light); |
2 | (uint8_t)(color[3 * pos + 1] * LED_light); |
3 | (uint8_t)(color[3 * pos + 2] * LED_light); |
That is, if you are using WS2812 to interpret data according to GRB, you should modify the code to:
G = (uint8_t)(color[3 * pos] * LED_light);
R = (uint8_t)(color[3 * pos + 1] * LED_light);
B = (uint8_t)(color[3 * pos + 2] * LED_light);
Here I directly modified the previous variable name, of course you can also modify the subsequent value.
The following link directs to the Gitee project address, where you can view code updates in real time
project | address |
---|---|
project address | snowflake-lights |
hardware | snowflake-lights/hardware |
firmware | snowflake-lights/firmware |
software | snowflake-lights/software |
The following content contains an introduction to schematics, PCB, and GERBER
Pin number | Function |
---|---|
1 | PD4 |
3 | PD7 |
7 | PA0 |
8 | PD1 |
serial number | device | Remark |
---|---|---|
LED1 ~ LED49 | WS2812E | WS2812E lamp beads |
U1 | HK32F030MJ4M6 | master control |
U2 | CH340N | USB to serial port |
U3 | SPX3819 | LDO |
USB | TYPE-C 16P | 16Pin TYPE-C female socket |
top | bottom |
---|---|
![]() |
![]() |
![]() |
![]() |
The following content contains an introduction to the EWARM project
Pin number | Function | AF |
---|---|---|
1 | PD4 | SPI1- MOSI |
3 | PD7 | USART1- RX |
7 | PA0 | EXTI0 |
8 | PD1 | USART1- TX |
SPI
Setting items | content | Remark |
---|---|---|
SPI_Direction | SPI_Direction_1Line_Tx | Single line sending |
SPI_Mode | SPI_Mode_Master | host mode |
SPI_DataSize | SPI_DataSize_10b | 10 Bits |
SPI_CPOL | SPI_CPOL_Low | Low level idle |
SPI_CPHA | SPI_CPHA_2Edge | Second edge sampling |
SPI_BaudRatePrescaler | SPI_BaudRatePrescaler_4 | 4 dividers |
SPI_FirstBit | SPI_FirstBit_MSB | High starting position |
USART
Setting items | content | Remark |
---|---|---|
USART_BaudRate | 115200 | baud rate |
USART_HardwareFlowControl_None | USART_HardwareFlowControl_None | Does not use hardware flow control |
USART_Mode | USART_Mode_Tx|USART_Mode_Rx | Use TX RX at the same time |
USART_Parity | USART_Parity_No | No parity bit |
USART_StopBits | USART_StopBits_1 | Stop bit |
USART_WordLength | USART_WordLength_8b | Data bit length |
Pin 7
Pin 8
Since SWDIO will be reused as TX and NRST as external interrupt immediately after power-on, if you need to program the code again, please follow the steps below.
The following content contains the upper computer code introduction
The host computer is developed using python3 and uses the serial port to communicate with the snowflake lamp. The baud rate is fixed at 115200. Of course, the user can also directly modify the code to change the baud rate.
List | Function |
---|---|
1 | Prompt text |
2 | Identifier |
3 | Display image or animation path |
Column 1 | Column 2 | Column 3 |
---|---|---|
Gradient from inside to outside | 0x00 | 0x00.jpg |
Gradient from outside to inside | 0x01 | 0x01.jpg |
counterclockwise gradient | 0x02 | 0x02.jpg |
clockwise gradient | 0x03 | 0x03.jpg |
warm white | color 255 255 55 | |
pure white | color 255 255 255 |
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