Jump to content
Rickta59

APA102 - simple to drive RGB leds

Recommended Posts

Those APA-102 leds that are packaged like ws281x pixels but you drive like a ws2801 (clk/data) have hit ebay.com. I ordered a 1 meter length and it arrived today. They look and feel like a ws2811 strip. It has 4 connections. 5V, GND, CLK, DATA. I whipped up a quick test and they seem to be happy:

 

/**
 * APA-102 - test of 5 leds
 *
 * Author: rick@kimballsoftware.com
 * Date: 09-11-2014
 *
 */

#include <fabooh.h>
#include <main.h>
#include <spi.h>

namespace {
  typedef spi_attr_t<> SPI_MODE3_A;
  typedef spi_eusci_b0_t<CS, SCLK, MOSI, NO_PIN, SPI_MODE3_A > spi_t;

  spi_t spi;
}

void setup(void)
{
	spi.begin();
	spi.set_divisor(8); // 1MHz spi
}

static const unsigned char buff0[] = {
	0x00, 0x00, 0x00, 0x00, // start frame
	(0b111 << 5 | 31), 0x00, 0x00, 0xFF, // red
	(0b111 << 5 | 31), 0x00, 0xFF, 0x00, // green  
	(0b111 << 5 | 31), 0xFF, 0x00, 0x00, // blue
	(0b111 << 5 | 31), 0xFF, 0xFF, 0xFE, // white
	(0b111 << 5 | 31), 0x00, 0x00, 0x00, // off
	0xFF, 0xFF, 0xFF, 0xFF  // end frame
};

static const unsigned char buff1[] = {
	0x00, 0x00, 0x00, 0x00, // start frame
	(0b111 << 5 | 31), 0x00, 0x00, 0x00,
	(0b111 << 5 | 31), 0x00, 0x00, 0x00,
	(0b111 << 5 | 31), 0x00, 0x00, 0x00,
	(0b111 << 5 | 31), 0x00, 0x00, 0x00,
	(0b111 << 5 | 31), 0x00, 0x00, 0xFF,
	0xFF, 0xFF, 0xFF, 0xFF  // end frame
};

void loop(void)
{
	while(1) {
		spi.select();
		spi.shiftout(buff0, sizeof(buff0));
		spi.deselect();
		delay(1000);

		spi.select();
		spi.shiftout(buff1, sizeof(buff1));
		spi.deselect();
		delay(1000);

	}
}
These chips are perfect when you don't want to run your msp430 at high clock speed but still want to be able to use a bunch of rgb leds without resorting to external led drivers or shift registers. However, if you do want to run fast, even faster than the ws281x 800kHz, you can. I tested with both a low speed (500Hz) and a high speed (up to 16MHz) configuration successfully. Using an msp430fr5969 chip at 8MHz I settled on 1MHz in the code above.

 

For a nice review of the chip's internals, you can read more about them on this cpldcpu's blog:

 

http://cpldcpu.wordpress.com/2014/08/27/apa102/

 

-rick

Share this post


Link to post
Share on other sites

I agree they will be popular. Though i still wouldn't completely discard the WS2812. The APA102 only have a maximum of 400Khz while the WS2812 has a maximum (and minimum) of 800Khz.

I think for bigger things the WS2812 is better since it's not that hard for a powerful MCU to control them + the higher refresh speed + when you do something with allot of LEDs you alredy are using a powerful MCU/processor.

 

But now these APA102. They are like a dream when you want to use the MSP430 now that they are integrated into the LED package. It's so simple the control. I want to do something for next month with just a few RGB LEDs. Well it's better to use a DIP packet for this so i need the MSP430 instead of the Tiva so those are perfect. So for hobby projects these will certainly be the most popular. Just give it some time.

Share this post


Link to post
Share on other sites

Saw this thread awhile ago, and think that would be cool to make some x'mas light with this. So I brought some APA102 strip on ebay and give it a try, but somehow I can't get it work.

 

I get a spare 2231, hook up the clk to P1.5 and data to P1.6, but it only randomly turn on a couple LED on a 72-LED strip. Just to make sure the strip is working, I hook it up with a picaxe 08m (which been collecting dust for many years.... ^.^), write some simple basic code, and the strip seems works fine.

 

Do I need a 3.3v->5v level shifter on the SPI lines? I was thinking 3.3V should be good for logical 1 for the APA102.

Share this post


Link to post
Share on other sites

Saw this thread awhile ago, and think that would be cool to make some x'mas light with this. So I brought some APA102 strip on ebay and give it a try, but somehow I can't get it work.

 

I get a spare 2231, hook up the clk to P1.5 and data to P1.6, but it only randomly turn on a couple LED on a 72-LED strip. Just to make sure the strip is working, I hook it up with a picaxe 08m (which been collecting dust for many years.... ^.^), write some simple basic code, and the strip seems works fine.

 

Do I need a 3.3v->5v level shifter on the SPI lines? I was thinking 3.3V should be good for logical 1 for the APA102.

You might have better luck running the msp430 at 3.6V. That tends to near the typical VIH of a 5V ttl device (VCC * 0.7).

Share this post


Link to post
Share on other sites

Saw this thread awhile ago, and think that would be cool to make some x'mas light with this. So I brought some APA102 strip on ebay and give it a try, but somehow I can't get it work.

 

I get a spare 2231, hook up the clk to P1.5 and data to P1.6, but it only randomly turn on a couple LED on a 72-LED strip. Just to make sure the strip is working, I hook it up with a picaxe 08m (which been collecting dust for many years.... ^.^), write some simple basic code, and the strip seems works fine.

 

Do I need a 3.3v->5v level shifter on the SPI lines? I was thinking 3.3V should be good for logical 1 for the APA102.

I'm not entirely sure, but these packages seem to use I2C, so you should put a pair of pull-up resistors on the Clk/Data lines. Never mind, it's SPI, not I2C.

Maybe you can drive the MSP430 at 3.6 volts (like the launchpad), does that do the trick?

Share this post


Link to post
Share on other sites

Thanks for everyone tried to help. Somehow it seems the voltage regulator I used is faulty and only giving out around 2.1v. The strip works fine after I replace the regulator, by simply direct connect clock and data line to P1.5 & P1.6.

post-1817-0-73930600-1415262924_thumb.jpg

Share this post


Link to post
Share on other sites

How did I miss this topic?!

 

@@Rickta59, I purchased the APA102, 144 LEDs/meter strip from the same eBay store just yesterday.

 

After I get my code running, I will be cutting up the strip to make my prototype marquee clock.

 

My kids are begging me to hurry up. They are mesmerized by the coloured blinkyness of the LEDs.

 

Thanks for the code as well.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×