I'm just getting started trying to figure out how the whole SPI thing works.

I'm using an APA102 led as I figured turning on and off LEDs and setting colours would be a good start.

I bought the kind you have to solder yourself, not a strip, and have soldered the pins on to little breakout boards. I'm using an external 5v source to power the led and have a 5v regulator on it.

According to the datasheet (https://cpldcpu.wordpress.com/2014/08/27/apa102/), I have to send an 'led frame' of 32 bits where all the bits are 0s. Then send another frame of 32 bits, if all 1s, that should turn on the led bright white. I only have 1 led, so it should light up on the first go.

At one point, I had the led glowing red, but I'm not sure how I managed to get it to do that (apparently I'm equal to 100 monkeys typing on 100 keyboards).

Using the command line, I've tried

$ echo -ne "\x00\x00\x00\x00" > /dev/spidev0.0
$ echo -ne "\xff\xff\xff\xff" > /dev/spidev0.0
$ echo -ne "\xff\xff\xff\xff" > /dev/spidev0.0

As well as using the pi-spi node library by writing

var SPI = require('pi-spi');
var spi0 = SPI.initialize('/dev/spidev0.0');

var clear = new Buffer(32);
var full = new Buffer(32);


function cb() { console.log(data)};

spi0.write(clear, cb);
spi0.write(fill, cb);

I've tried the above with both /dev/spidev0.0 and /dev/spidev0.1

Is there something obvious I'm doing wrong here? how can I tell which SPI address I should be using in the initializer? Am I even close?

  • How have you connected the LED to the Pi? A photo and a description would be useful. Have you tried echo -ne "\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff" > /dev/spidev0.0
    – joan
    Commented Feb 23, 2016 at 11:59
  • @joan unfortunately, I wasn't able to get a clear photo. quite a few wires in a fairly tight space. Yes, the led is connected to the Pi. As mentioned, it is connected to the mosi and sclk with power being supplied via the 5v regulator. I just realised the led is grounded via the regulator as well, but maybe I should grounding via the pi? I won't have network access until next week, so can't test the command you suggested until then.
    – pedalpete
    Commented Feb 24, 2016 at 11:09
  • 1
    You will need to connect a Pi ground to where the LED is grounded (otherwise the SCLK and MOSI lines will effectively be floating as they don't have a reference voltage). Presumably it will be simplest to connect Pi ground to the 5V ground (-ve terminal).
    – joan
    Commented Feb 24, 2016 at 11:24

4 Answers 4


the most significant bit of the LED frame has to be “1”, since it is used to identify the start of the frame. It appears that the next two bits serve no function and can have arbitrary values. To stay compliant with the APA102 data sheet, it makes sense to set them to “1”, though.

  • I'm not sure I completely understand what you mean @josh. Can you give an example?
    – pedalpete
    Commented Mar 15, 2016 at 11:14

not sure if you've solved this yet, but I have an apa102 single LED working well with SPI and python. You'll need a logic shifter (see the one the AdaFruit recommend on their website) as GPIO are 3V3 and APA102 is 5V. If you need python help, I can share what I used.


First, it doesn't matter at all if you use /dev/spidev0.0 or /dev/spidev0.1: The APA102 LEDs do not have an input for the CE0/CE1 pin. The ,0 device sets CE0 high, and ,1 does the same for CE1. But since you can't connect the pin to the LED, it doesn't matter.

Second, your code looks good. Sending 32 Zeroes, followed by 32 ones, should indeed light one LED in white. I am not 100% sure if you need to send the stop frames if you only have one LED, but to make sure just send say 16 or 32 zero bits after the ones.

A level shifter is not usually required. The 3.3V from the Raspberry Pi are usually detected correctly as "high" by the 5V LEDs. As mentioned before, the Pi and the LEDs must have a common ground.

If you want to use a level shifter, I have a wiring diagram here: https://github.com/tinue/APA102_Pi


The APA102 LEDs are what Adafruit calls DotStar LEDs. They have a lot of information and libraries for them.

The 5050 in the title of the question is misleading because that is just the physical size/form factor of the LED. There are 5050 LEDs available which are not individually addressable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.