huNaz3l

10 X 10 snowflake lamp based on HK32

 
Overview

Snowflake Lights

A snowflake lamp based on HK32F030MJ4M6

Overview

This document contains

  • Hardware introduction
  • Firmware introduction
  • Introduction to the host computer

introduce

Snowflake lamp using HK32F030MJ4M6 as the main control


Precautions

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:

WS2812 timing sequence 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.


Manufacturing steps

  1. Use snowflake-lights/hardware/Gerber.zip for pattern making
  2. Purchase the device and solder it, please pay attention when soldering
    • Complete the welding of all WS2812 lamp beads first , and then weld the decoupling capacitor to prevent the decoupling capacitor from hindering the lamp bead welding.
    • Upturned TYPE-C female seat .
  3. Test and power on

Project details

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

Snowflake Lights Hardware

introduce

The following content contains an introduction to schematics, PCB, and GERBER


MCU pin distribution

Pin layout

MCU pin function mapping

Pin number Function
1 PD4
3 PD7
7 PA0
8 PD1

Main bill of materials

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

Model rendering

top bottom
2D top 2D bottom
3D top 3D bottom

Snowflake Lights Firmware

introduce

The following content contains an introduction to the EWARM project


MCU pin function mapping

Pin number Function AF
1 PD4 SPI1- MOSI
3 PD7 USART1- RX
7 PA0 EXTI0
8 PD1 USART1- TX

Peripheral configuration information

  • 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

Secondary development

  • Pin 7

    • Used as reset button by default .
    • It can be reused as an external interrupt , and the falling edge triggers the interrupt.
    • Can be reused as GPIO input mode , and loop to determine whether it is low level.
  • Pin 8

    • Used as SWDIO by default
    • Can be reused as USART1-TX . At this time, SW cannot be used to debug , but it can be downloaded through SW.

Precautions

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.

  1. Power off the device.
  2. Keep the button pressed and power up.
  3. Continue to keep the button pressed and use the debugger to connect the computer to the device.
  4. Continue to keep the button pressed to start the download process.
  5. Continue to keep the button pressed , and release the button when the word Flashing appears on the screen .

Snowflake Lights Software

introduce

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.


Window screenshot

Window screenshot


Configuration file

Directory Structure

  • The configuration file needs to be placed in the styles folder under the installation directory.
  • The folder should contain a db.csv data file
  • It is recommended to place all image files used in the styles directory and its subdirectories

db.csv file format

List Function
1 Prompt text
2 Identifier
3 Display image or animation path
  • The prompt text will be displayed in the drop-down list. Since the component width is fixed, please modify the prompt text and run the program to see whether the prompt text can be fully displayed in the list box.
  • It is recommended to use letters and numbers as identification codes to avoid garbled characters during text encoding and decoding.
  • Please fill in the relative path in column 3 to specify the display image or animation. The path is relative to the styles directory and supports ./ ../ symbols, but it is not recommended to place images and animation files outside the styles directory.
  • Display pictures support common image formats, and display animations only support gif format.
  • If column 3 is left blank, the content filled in column 1 will be displayed in the display area.

Default db.csv file content

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

letter of agreement

  • The upper computer and lower computer should send requests at least 5ms apart from the last request sent by the local computer .
  • Unless otherwise specified, all characters and symbols used in this communication protocol should be in English half-width format.
  • Unless otherwise specified, all characters below represent a newline character .characters represent a null character .
  • Unless otherwise specified, all space characters below should not appear consecutively .
  • Unless otherwise specified, all character strings specified in this communication protocol should end with symbols, and symbols are not used as a valid basis for judgment.

shake hands

  1. The host computer sends the handshake request string sl connect query to the serial port.
  2. After receiving the handshake request, the lower computer replies with the string sl connect successfully dev:"AAAAA" ver:"BBBBB" .
    • AAAAA should be replaced with the firmware developer name.
    • BBBBB should be replaced with the firmware version number.
  3. After receiving the reply, the host computer displays the developer's name and firmware version number on the screen.

Change style

  1. The host computer sends the style change request string sl code XXXXX to the serial port.
    • XXXXX should be replaced with the identifier corresponding to the style used .
    • It should be ensured that the identification codes of the upper computer and lower computer are consistent.
    • Modify the stylesdb.csv file to modify the corresponding relationship between the host computer identification codes.
    • If you want to modify the corresponding relationship between the identification codes of the lower computer, please modify the firmware code directly.
  2. After receiving the style change request, the lower computer parses the identification code and immediately changes it to the corresponding style.

Identification code format

  • reserved identification code
    • Monochrome display identification code
    • All upper computers and lower computers using this communication protocol should support this identification code.
    • Identification code format color RRR GGG BBB
    • Please replace RRR GGG BBB in the identification code with the color R, G, and B values ​​respectively.
    • It should be ensured that the color R, G, and B values ​​are integers in the range of 0 ~ 255 .
  • open identifier
    • The open identification code is used to identify special styles and should be unified between the upper computer and the lower computer.
    • The open identification code should minimize the use of space symbols to avoid being recognized as a reserved identification code by the lower computer.
    • It is recommended to use a combination of letters and numbers without spaces as the open identification code.

Change brightness

  1. The host computer sends the brightness change request string sl light XXXXX to the serial port.
    • XXXXX should be replaced with the brightness to be used.
    • Brightness should be a decimal in the range 0 - 1 .
  2. After receiving the brightness change request, the lower computer parses the brightness value and immediately changes it to the specified brightness.
    • Display style should not be modified when modifying brightness.
    • This brightness setting should take effect for all current and future styles.
    • This brightness setting should expire on the next brightness change request. Bold
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-23 08:50:15
  • F2812 programming problem
  • Smile, ten years younger
  • DC/DC 24V to 5V
  • [GD32E503 Review] Part 3: Screen Code Analysis
  • PIC microcontroller key recognition program
  • How capacitive isolation solves key challenges in AC motor drives

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号