Difference between revisions of "LEDCtl (WS2812b LED Controller)"
(Created page with "Category:STM32 Hardware Development LED strips and panels based on some form of the WS2812 RGB LEDs have gained an enormous popularity the past couple of years wit...") |
|||
(34 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | [[Category:STM32 Hardware Development]] | + | [[Category:STM32]][[Category:STM32 Projects]][[Category:KiCAD]][[Category:STM32 Hardware Development]][[Category:Work in progress]]{{metadesc|WS2812b LED Controller}} |
+ | At the moment this document is a work in progress. I'll add to it as I go along designing the device, jotting down design decisions as I go along. | ||
+ | |||
[[LED]] strips and panels based on some form of the [[WS2812]] RGB LEDs have gained an enormous popularity the past couple of years with the price of the individual LEDs dropping well below 10 cent each. These LEDS contain 3 individual LEDs: one red, one green and one blue and the intensity of each of these can be set at 256 different levels. | [[LED]] strips and panels based on some form of the [[WS2812]] RGB LEDs have gained an enormous popularity the past couple of years with the price of the individual LEDs dropping well below 10 cent each. These LEDS contain 3 individual LEDs: one red, one green and one blue and the intensity of each of these can be set at 256 different levels. | ||
+ | |||
+ | == Overall Design Parameters == | ||
+ | |||
+ | The "device" should be able to drive 2-4 strings of up to 1000 leds on each string and the length and type of each string should be configurable. | ||
+ | |||
+ | The "device" will offer multiple ways of controlling LEDS: | ||
+ | |||
+ | * USB/CDC (emulated Serial over USB) | ||
+ | * Serial rx/tx lines | ||
+ | * I2C | ||
+ | * SPI | ||
+ | |||
+ | == Hardware Design and Implementation == | ||
+ | |||
+ | === Picking the CPU === | ||
+ | |||
+ | It might be possible to find a better CPU in ST's enormous line of processors, but since we've used the [[STM32F103]] on our own [[Green Pill]] board, that processor will be the initial choice. | ||
+ | |||
+ | The "limiting" factor of this choice is the available memory. The STM32F103 has got 20 kB of RAM. Our "device" will need a "buffer" holding the RGB values of each LED. So with 1 string of 1000 LEDS we will need around 3k of RAM for this purpose alone. With 2 strings that value doubles to 6k (which might still be doable) but if we want to support 1000 LEDs on 4 strings each that will require more than half the RAM, most likely leaving too little for the software to run. | ||
+ | |||
+ | === Schematics === | ||
+ | |||
+ | The design of the schematics is largely based on the [[Green Pill]] with a few changes. | ||
+ | |||
+ | ==== Rev. a ==== | ||
+ | |||
+ | <div class="res-img"> | ||
+ | [[File:ledctl rev a.svg|1800px]] | ||
+ | </div> | ||
+ | |||
+ | The primary changes are: | ||
+ | |||
+ | Using a 16 MHz crystal rather than the 8 MHz one used on the [[Green Pill]]. The 16 MHz crystal is in fact cheaper and more importantly takes less space (the 8 MHz crystal was used on the [[Green Pill]] to remain compatible with [[Blue Pill]] boards). | ||
+ | |||
+ | The two [[LED]] drive lines are open drain which is pulled up to the 5V power rail to be compatible with the [[WS2812]] LEDs. | ||
+ | |||
+ | Only relevant [[GPIO]] pins are pulled out to the header. | ||
+ | |||
+ | ==== Rev. c ==== | ||
+ | |||
+ | Two issues were identified with [[#Rev. a|rev. a]]: | ||
+ | |||
+ | # Floating [[Boot0]] pin | ||
+ | # Pull up resistor too weak | ||
+ | |||
+ | <div class="res-img"> | ||
+ | [[File:ledctl rev c.svg|2100px]] | ||
+ | </div> | ||
+ | |||
+ | == Register Map == | ||
+ | |||
+ | {|class=wikitable width=100% | ||
+ | |- | ||
+ | ! Start | ||
+ | ! End | ||
+ | ! Width (B) | ||
+ | ! Type | ||
+ | ! Default | ||
+ | ! Description | ||
+ | |- | ||
+ | | align=right | 0x0000 | ||
+ | | align=right | 0x0000 | ||
+ | | align=right | 1 | ||
+ | | R | ||
+ | | align=right | 0x19 | ||
+ | | Device ID. Must be 0x19 | ||
+ | |- | ||
+ | | align=right | 0x0001 | ||
+ | | align=right | 0x000b | ||
+ | | align=right | 12 | ||
+ | | R | ||
+ | | align=right | | ||
+ | | Unique 96 bit device ID. | ||
+ | |} | ||
+ | |||
+ | == Software == | ||
+ | |||
+ | === Hayes Like Serial Interface === | ||
+ | |||
+ | To control the attached LEDs a simple serial interface is used. | ||
+ | |||
+ | ==== AT Commands ==== | ||
+ | |||
+ | {|class=wikitable width=100% | ||
+ | |- | ||
+ | ! Command | ||
+ | ! Parameters | ||
+ | ! Example | ||
+ | ! Response | ||
+ | ! Description | ||
+ | |- | ||
+ | | &F | ||
+ | | | ||
+ | | AT&F | ||
+ | | OK | ||
+ | | Factory reset | ||
+ | |- | ||
+ | | ATLsnnn=rrrgggbbb | ||
+ | | s=string<br/>nnn=led<br/>rrr=3 digit value | ||
+ | | ATL0000=010010010 | ||
+ | | OK | ||
+ | | Set a specific led on a specific string to a specific value | ||
+ | |- | ||
+ | | Sx=y | ||
+ | | y = value | ||
+ | | ATS0=64 | ||
+ | | OK | ||
+ | | Set register to a certain value. Example will set register 0 to a value of 64 | ||
+ | |- | ||
+ | | Z | ||
+ | | | ||
+ | | ATZ | ||
+ | | OK | ||
+ | | Reset device | ||
+ | |} | ||
+ | |||
+ | ==== S Registers ==== | ||
+ | |||
+ | {|class=wikitable width=100% | ||
+ | |- | ||
+ | ! Register | ||
+ | ! Valid values | ||
+ | ! Default value | ||
+ | ! Description | ||
+ | |- | ||
+ | | 0 | ||
+ | | 0-999 | ||
+ | | 1 | ||
+ | | LEDs on string 0 | ||
+ | |- | ||
+ | | 1 | ||
+ | | 0-999 | ||
+ | | 0 | ||
+ | | LEDs on string 1 | ||
+ | |- | ||
+ | | 2 | ||
+ | | 0-99 | ||
+ | | 31 | ||
+ | | "Width" of a zero (percentage) | ||
+ | |- | ||
+ | | 3 | ||
+ | | 0-99 | ||
+ | | 69 | ||
+ | | "Width of a one (percentage) | ||
+ | |} | ||
+ | |||
+ | == Gallery == | ||
+ | |||
+ | <gallery> | ||
+ | File:ledctl1.png | ||
+ | File:ledctl2.png | ||
+ | File:ledctl3.png | ||
+ | File:ledctl4.png | ||
+ | </gallery> |
Latest revision as of 09:55, 15 October 2024
At the moment this document is a work in progress. I'll add to it as I go along designing the device, jotting down design decisions as I go along.
LED strips and panels based on some form of the WS2812 RGB LEDs have gained an enormous popularity the past couple of years with the price of the individual LEDs dropping well below 10 cent each. These LEDS contain 3 individual LEDs: one red, one green and one blue and the intensity of each of these can be set at 256 different levels.
Overall Design Parameters
The "device" should be able to drive 2-4 strings of up to 1000 leds on each string and the length and type of each string should be configurable.
The "device" will offer multiple ways of controlling LEDS:
- USB/CDC (emulated Serial over USB)
- Serial rx/tx lines
- I2C
- SPI
Hardware Design and Implementation
Picking the CPU
It might be possible to find a better CPU in ST's enormous line of processors, but since we've used the STM32F103 on our own Green Pill board, that processor will be the initial choice.
The "limiting" factor of this choice is the available memory. The STM32F103 has got 20 kB of RAM. Our "device" will need a "buffer" holding the RGB values of each LED. So with 1 string of 1000 LEDS we will need around 3k of RAM for this purpose alone. With 2 strings that value doubles to 6k (which might still be doable) but if we want to support 1000 LEDs on 4 strings each that will require more than half the RAM, most likely leaving too little for the software to run.
Schematics
The design of the schematics is largely based on the Green Pill with a few changes.
Rev. a
The primary changes are:
Using a 16 MHz crystal rather than the 8 MHz one used on the Green Pill. The 16 MHz crystal is in fact cheaper and more importantly takes less space (the 8 MHz crystal was used on the Green Pill to remain compatible with Blue Pill boards).
The two LED drive lines are open drain which is pulled up to the 5V power rail to be compatible with the WS2812 LEDs.
Only relevant GPIO pins are pulled out to the header.
Rev. c
Two issues were identified with rev. a:
- Floating Boot0 pin
- Pull up resistor too weak
Register Map
Start | End | Width (B) | Type | Default | Description |
---|---|---|---|---|---|
0x0000 | 0x0000 | 1 | R | 0x19 | Device ID. Must be 0x19 |
0x0001 | 0x000b | 12 | R | Unique 96 bit device ID. |
Software
Hayes Like Serial Interface
To control the attached LEDs a simple serial interface is used.
AT Commands
Command | Parameters | Example | Response | Description |
---|---|---|---|---|
&F | AT&F | OK | Factory reset | |
ATLsnnn=rrrgggbbb | s=string nnn=led rrr=3 digit value |
ATL0000=010010010 | OK | Set a specific led on a specific string to a specific value |
Sx=y | y = value | ATS0=64 | OK | Set register to a certain value. Example will set register 0 to a value of 64 |
Z | ATZ | OK | Reset device |
S Registers
Register | Valid values | Default value | Description |
---|---|---|---|
0 | 0-999 | 1 | LEDs on string 0 |
1 | 0-999 | 0 | LEDs on string 1 |
2 | 0-99 | 31 | "Width" of a zero (percentage) |
3 | 0-99 | 69 | "Width of a one (percentage) |