chipKIT® Development Platform

Inspired by Arduino™

ws2811 RGB LED Module support

Created Thu, 31 Oct 2013 23:30:07 +0000 by HopWorks


Thu, 31 Oct 2013 23:30:07 +0000

I had a last minute Halloween idea and I ripped the plastic off my embedded bench and ... stared at my hardware... lost.

So I am asking for help. I do not want the code written for me, I just need a push.

I have an LED strip of 60 RGB LEDs that are actually WS2811 RGB LED modules. I plan to cut 8 of these off the strip because I don't need them all for my pumpkin. They are frustrating to communicate to, because they do not use a clock line. They need a fairly tight 800 khz data stream that is bit-banged largely judging by examples I have found for other controlling hardware. The SPI data line is used to send the bits to the module, actually using 8 bits to form the data waveform. So outputting 11110000 is suppose to be a high to low 50% duty cycle forming a single bit "1". Another bit config is used to send a zero.

Anyway, I KNOW my chipKit max32 is more that enough for this task, but I was hoping someone here had a library, or a block of code that would set up the max32, and offer functions to out a one or a zero.

The rest I can handle. But I need to be able to communicate with the WS2811 modules first before I can code any intelligible data streams.

Oh yes, the modules daisy chain, and are individually addressable. The more modules you use, the longer the data stream packet needs to be. On an order of modules times 24 bits (3 bytes) for the individual RGB intensity levels.

But without a scope or logic analyzer, I am at the mercy of how SPI is set up as far as baud rate and other features.

Also needs 5v logic levels. I have to ransack my bench for a 74HCT04 (I think I got that right) to bring up the max32 SPI 3.3v to 5v.

I hope this is enough info. Thank you so much for your time!


Fri, 01 Nov 2013 00:01:52 +0000

I just used a candle in my pumpkin... Old school, but doesn't take special programming skills ;)

So you want SPI at a specific rate? Simple enough. Just use the DSPI library instead of the SPI library (it's included with MPIDE) and use the setSpeed() function:

#include <DSPI.h>

DSPI0 spi;

void setup() {

void loop() {
  spi.transfer(blah blah blah);

It just so happens that 800KHz is easily achievable from an 80MHz clock signal. Just divide by 100.


Fri, 01 Nov 2013 01:39:31 +0000

That's awesome! Thank you! Too late for tonight, but I want to do the same for our Christmas stuff, and for Halloween next year. I'll give it a go.

Thank you very much for that info!!

Anything I need to worry about with start,stop bits, etc?

I hate the idea of bit banging. Seems like a crude way to communicate with such a feature rich protocol. I guess if it works.... lol

Oh, bit banging with the data out of SPI at a perceived bit rate of 800khz, SPI needs to run at 4mhz according to the only example I found that uses a 64mhz pic. I'll have to play with it and adjust.


Fri, 01 Nov 2013 10:49:53 +0000

64MHz pic? That wouldn't be something like the PIC18F46K22 would it? One of my all-time favorite 8-bit PICs...

4MHz is perfectly achievable from the SPI hardware (BRG=9), so spi.setSpeed(4000000UL) should do nicely.


Fri, 01 Nov 2013 20:40:29 +0000

Thank you majenko. I know you're an expert on the PIC32MX795F512L and have been a huge help to me with figuring out the features.

Good to see ya!


Mon, 04 Nov 2013 14:48:58 +0000

Just an outside observer (with no hardware or plan to test), but would you be interested in using the PWM module to drive these modules? In looking at the datasheet for the ws2811 it requires an 50% duty cycle for a logic 1 bit and 20% duty cycle for a logic 0 bit at 800khz (high speed).

This would allow for 5 channels to drive your LED string and leave the SPI available for interfacing with other devices. If a MAX32 is used you could load the DMA with the bits you want to transfer (this could be done for SPI as well) to save on waiting time for transfers to happen so that you can process other things.

Just a thought, and may not be practical for you needs but thought I'd offer the unsolicited idea.