This project drives a WS2812B RGB LED matrix (or strip) using the SPI protocol. Each 3 byte SPI frame gets displayed on each sequential LED in the matrix. This allows for animations to be displayed given the color composition of each pixel on each frame. For an 8x8 matrix, the expected refresh rate is roughly 300hz.
The simple write-only SPI peripheral is designed for a CPHA (clock phase) and CPOL (clock polarity) of 0 and a baudrate of 1Mhz. Each frame should consist of pulling CS low, writing 3 bytes, and pulling CS high.
After a pixel's worth of data has been recieved into the SPI register, it is latched and the LED driver is signalled to start sending data.
Connect Wires:
Set up outputs:
uo[0]
to the input pin (DIN
) of a WS2812B LED matrixuo[1]
and uo[2]
to status LEDs for debugging purposesSet up the SPI connection:
SCK
to ui[0]
SDI
(or MOSI
) to ui[1]
CS
to ui[2]
Display Data:
An example micropython script can be found here
Set up a SPI peripheral with CPHA
= CPOL
= 0 and a baudrate of 1Mhz
. Send 3 bytes of data in GRB format. The correct color should show up on the first LED in the matrix.
# | Input | Output | Bidirectional |
---|---|---|---|
0 | SCK | DIN | |
1 | SDI | LED1 | |
2 | CS | LED2 | |
3 | |||
4 | |||
5 | |||
6 | |||
7 |