PinDescriptionPinDescription
SDIData InputSDOData Output to next LED
CKIClock InputCKOClock Output to next LED
GNDGroundVCC5 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.

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

External 5 volt power supplyAPA102Description
+5 voltsVDDPower to the APA102
GNDGNDGround connection to the APA102

If your strip is very small (<5 LEDs), you can get away with powering the LEDs from the Bus Pirate VOUT pin.

Data

Bus PirateAPA102Description
SDOSDIData from Bus Pirate to first LED
SCLCKIClock from Bus Pirate to first LED
GNDGNDA 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.

Setup

Bus Pirate [/dev/ttyS0]
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 type
  • W 5 - set the onboard power supply to 5 volts to power the Bus Pirate buffers

Blue, green, red

Bus Pirate [/dev/ttyS0]
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.

Purple

Bus Pirate [/dev/ttyS0]
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.

RGB cycle

Bus Pirate [/dev/ttyS0]
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

Bus Pirate [/dev/ttyS0]
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

Bus Pirate [/dev/ttyS0]
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.