APA102/SK9822 LED
Pin | Description | Pin | Description |
---|---|---|---|
SDI | Data Input | SDO | Data Output to next LED |
CKI | Clock Input | CKO | Clock Output to next LED |
GND | Ground | VCC | 5 volt power supply |
APA102/SK9822 RGB LEDs are controlled by a simple two wire interface. Multiple devices can be chained together, with the SDO and CKO pins of one LED connecting to the SDI and CKI pins of the next.
3 LED dies (red, blue, green) and an controller chip are bonded to a bit of metal called a leadframe. The leadframe is put inside a casing and covered in epoxy. Then the whole thing is baked, like a cake. Technically we should call the device a pixel, because it contains multiple LEDs.
See it in action
Protocol
The APA102 uses a two wire protocol with data and clock lines. A full transmission includes:
- A start frame (0x00000000)
- LED color data frames
- An end frame (0xffffffff)
Start frame
Each APA102 update begins with a start frame, which is 0x00000000 (32 bits of 0).
LED frame
Each LED receives a 32 bit frame with brightness and color data.
111
- the first 3 bit of every LED frame is 111 to distinguish it from the start frame.- GLOBAL - the next 5 bits determine the brightness of all the LEDs in a single APA102. It is a global dimmer setting for each APA102. The value is 0-31, where 0 is off and 31 is full brightness.
- BLUE - the next 8 bits are the blue color value, 0-255.
- GREEN - the next 8 bits are the green color value, 0-255.
- RED - the next 8 bits are the red color value, 0-255.
End frame
The transaction is complete when the end frame is sent. The end frame is 0xffffffff (32 bits of 1).
Images via datasheet.
Connections
Many strips of APA102s come with connectors already soldered for external power and data. You may need to pull back the heatshrink over the connector wires to determine the pinout.
Our strip has a 4 pin data connector with +5volts, data, clock and ground. Two additional wires are available for external power, which we connected to a screw terminal barrel jack socket.
External power
If using a strip of more than 5 APA102s, you must use an external 5 volt power supply.
External 5 volt power supply | APA102 | Description |
---|---|---|
+5 volts | VDD | Power to the APA102 |
GND | GND | Ground connection to the APA102 |
APA102s generally come in a strip of multiple devices. RGB LEDs can consume a lot of current, up to 60mA per device when all the dies are powered. When using a string of more than 5 devices, you must use an external power supply.
If your strip is very small (<5 LEDs), you can get away with powering the LEDs from the Bus Pirate VOUT pin.
Data
Bus Pirate | APA102 | Description |
---|---|---|
SDO | SDI | Data from Bus Pirate to first LED |
SCL | CKI | Clock from Bus Pirate to first LED |
GND | GND | A ground connection is required |
Connect the Bus Pirate SDO pin to the APA102 SDI wire and the SCL pin to the CKI wire. Connect the Bus Pirate ground to the APA102 ground.
Don’t forget a ground connection, even if the strip is powered by an external supply.
Setup
HiZ> m led Mode: LED LED type 1. WS2812/SK6812/'NeoPixel' (single wire interface)* 2. APA102/SK9822 (clock and data interface) 3. Onboard LEDs (18 SK6812s) x. Exit Type (1) > 2 LED-(APA102)> W 5 5.00V requested, closest value: 5.00V 300.0mA requested, closest value: 300.0mA Power supply:Enabled Vreg output: 5.0V, Vref/Vout pin: 5.0V, Current: 2.6mA LED-(APA102)>
Setup is easy, enter LED mode and enable a 5 volt power supply.
m led
- set LED with the mode command, choose APA102 as the interface typeW 5
- set the onboard power supply to 5 volts to power the Bus Pirate buffers
Even if the LEDs are powered by an external supply, the Bus Pirate buffers must be powered or the data signal will not be sent.
Blue, green, red
LED-(APA102)> [0xffff0000 0xff00ff00 0xff0000ff ] START FRAME (0x00000000) TX: 0xFFFF0000.32 0xFF00FF00.32 0xFF0000FF.32 STOP FRAME (0xFFFFFFFF) LED-(APA102)>
Let’s light the first three LEDs in the strip. The first LED will be blue, the second green, and the third red.
[
- APA102 data frames start with 0x00000000,[
sends frame start in LED/APA102 mode.0xffff0000
- set the first APA102 to blue/full brightness0xff00ff00
- set the second APA102 to green/full brightness0xff0000ff
- set the third APA102 to red/full brightness]
- APA102 data frames end with 0xffffffff,]
sends frame end in LED/APA102 mode.
[
sends the APA102 start frame (0x00000000), while ]
send the end frame (0xffffffff). We could accomplish the same by entering 0x00000000
at the start and 0xffffffff
at the end. [
and ]
are shortcuts.
Purple
LED-(APA102)> [0xffff00ff:3 ] START FRAME (0x00000000) TX: 0xFFFF00FF.32 0xFFFF00FF.32 0xFFFF00FF.32 STOP FRAME (0xFFFFFFFF) LED-(APA102)>
Next let’s mix colors to make all three LEDs purple.
[
- APA102 data frames start with 0x00000000,[
sends frame start in LED/APA102 mode.0xffff00ff:3
- set blue and red to full brightness, green to 0.:3
repeats the command 3 times, so all three APA102s are set to purple.]
- APA102 data frames end with 0xffffffff,]
sends frame end in LED/APA102 mode.
RGB cycle
LED-(APA102)> [0xffff0000:3] D:500 [0xff00ff00:3] D:500 [0xff0000ff:3] START FRAME (0x00000000) TX: 0xFFFF0000.32 0xFFFF0000.32 0xFFFF0000.32 STOP FRAME (0xFFFFFFFF) Delay: 500ms START FRAME (0x00000000) TX: 0xFF00FF00.32 0xFF00FF00.32 0xFF00FF00.32 STOP FRAME (0xFFFFFFFF) Delay: 500ms START FRAME (0x00000000) TX: 0xFF0000FF.32 0xFF0000FF.32 0xFF0000FF.32 STOP FRAME (0xFFFFFFFF) LED-(APA102)>
We can use the Bus Pirate delay command to create a simple RGB cycle.
[0xffff0000:3]
- set three APA102s to blue/full brightness.D:500
- delay 500ms.[0xff00ff00:3] D:500
- set three APA102s to green/full brightness, delay 500ms.[0xff0000ff:3]
- set three APA102s to red/full brightness.
White
LED-(APA102)> [0xffffffff:3] START FRAME (0x00000000) TX: 0xFFFFFFFF.32 0xFFFFFFFF.32 0xFFFFFFFF.32 STOP FRAME (0xFFFFFFFF) LED-(APA102)>
To aproximate white, we can set all three colors to full brightness.
[0xffffffff:3]
- set three APA102s to white/full brightness.
Off
LED-(APA102)> [0xff000000:3] START FRAME (0x00000000) TX: 0xFF000000.32 0xFF000000.32 0xFF000000.32 STOP FRAME (0xFFFFFFFF) LED-(APA102)>
To turn off the LEDs, we can set all three colors to 0.
[0xff000000:3]
- set three APA102s to off.