Jump to content
Rickta59

[Energia Library] WS2811Driver LED Controller Class

Recommended Posts

I ported over oPossum's ws2811 asm routines to msp430-gcc and wrapped it in simple Energia library. This class provides Energia users with a simple class with methods that allow you to configure the datapin, and set the leds colors in a ws2811 led strip.

 

To install, stop running Energia and create a directory in your sketch folder called 'libraries'. Unzip the attached zip file into libraries directory. You should end up with a directory called libraries/WS2811Driver.

 

Restart Energia and you should have some new items in your "File/Sketchbook/libraries/WS2811Driver/Examples" menu item.

 

post-190-0-85255600-1353023637_thumb.gif blink_strip example

 

You need to create an instance of the WS2811Driver class. It provides methods that let you set the number of leds in your strip, it is called setLedCount(). The begin() methjod configures P1.7 as an output pin. The write() call is the main method for setting the leds. The write() method takes an array of uint8_t, it expects 3 bytes of color data per led in Green, Red, Blue order.

 

See the blink_strip.ino example for more details.

 

This could use a lot of work, however some might find it useful. I only ported the high speed 800KHz version of the asm code. One problem with using the asm routines with Energia is that they use cycle counting to achieve accurate timing. This will cause problems with the millis() accuracy. When I'm sending data I disable the watchdog before calling the asm routine and then reenable it after. I've only tested with the msp430g2553, however it might work with the other chips. I was testing with my development environment which is in flux at the moment.

 

You can edit the ws2811.h file and change the port and pins if P1.7 doesn't work for you.

 

-rick

WS2811Driver_0_1.zip

Share this post


Link to post
Share on other sites

Got my strip and played with this a bit. It works great!

Here's all 60 LEDs in my one meter strip with flowing colors. Max duty cycle is limited to 40, partly because these things are quite bright and partly because at full burn the strip eats ~1.2 amps and my regulator starts getting rather toasty. The LEDs are supplied with 5v (actually 4.5v after the LDO after coming out the USB3 port) from a seperate power board, the MSP430G2553 is on a standard Launchpad.

 

#include <WS2811Driver.h>

byte leds0[180];
WS2811Driver ledStrip; // uses P1_7 as datapin connect to DIN on strip

void setup(void)
{
ledStrip.setLEDCount(60); // setup for 60 leds on a strip
ledStrip.begin();	 // configure P1.7 for output
for (byte x = 0 ; x < 180 ; x++){
 leds0[x] = 0;
}
}

void loop() {
for(byte x = 179; x >= 5 ; x--){
leds0[x] = leds0[x-3];
leds0[x-1] = leds0[x-4];
leds0[x-2] = leds0[x-5];
}
leds0[0] = random(0,random(10,40));
leds0[1] = random(0,random(10,40));
leds0[2] = random(0,random(10,40));
ledStrip.write(leds0);			 // write to the LEDs
delay(100);

}

 

Thanks for the library! It made this FAR easier!

Share this post


Link to post
Share on other sites

I'm working on a board that will use an MSP430 to drive a number of WS2811 LEDs based on commands sent to it over I2C plus a single capacitive touch sensor. With the tight timing requirements, is it still possible to run I2C slave and capsense functions while writing to the LEDs? Likely the LEDs will only update after one of these is detected, but I might have functionality where these inputs affect a constantly running pattern.

Share this post


Link to post
Share on other sites

The WS2811Driver::write() method is blocking a call. It will disable the watchdog interval ISR while sending data to the ws2811 chip. This is the only way to achieve the required timing. If you are doing interrupt processing you should disable it before calling write(). It seems like you should be able to do what you want with some careful attention to what is running when. Of course it all depends on how many leds and the framerate of your animation.

 

-rick

Share this post


Link to post
Share on other sites

Hey guys, I haven't been around much lately, but a recent project brought me back here and using this WS2811 library.

 

I'm trying to enable more people to use the LaunchPad in some of my volunteer work (FIRST robotics) and flashing LEDs is a good eye catching way to do it.  To help facilitate people who are already using Arduino and the venerable AdaFruit NeoPixels, I ported over almost all of her functionality to work in Energia.

 

https://github.com/ILAMtitan/WS2811Driver

 

With this, any project using the NeoPixel library will be near 100% compatible.  I also took some time and worked out support for 25MHz on the 5529 LP (although it's a bit crude).  My assembly knowledge is also only enough to get me so far.  I haven't been able to work out the best way to enable PORT2 to be used since it's a #def in the assembly.  If any of you guys can help work that out, it would be awesome.  I know y'all are also really good at finding problems with code, so feel free to do some QA for me :)

 

I've tested the timings up to 120 LEDs at 25MHz, but it might fail beyond that (I only had two strips to play with).

 

post-30521-0-12115000-1410217185_thumb.jpg

 

 

And here's a little preview of the first project I'm working on with it:

 

post-30521-0-01612900-1410217186_thumb.jpg

Share this post


Link to post
Share on other sites

@@ILAMtitan I just tried this lib and it works like a charm! Thanks for consolidating the code into a lib and thanks to @@Rickta59 and @@oPossum for the drive code!

 

I'm just standing on the shoulders of giant's here.

 

 

@@ILAMtitan Good idea.. I might steal this shoe idea!!!!

 

There sadly aren't many photos of the shoes during the build process so far, but I'll probably still do a project post about them when they are done.

Share this post


Link to post
Share on other sites

Any chance of getting this working on cc3200 ?

I tried replacing the msp includes to energia.h, and made an attempt at the pin declarations, the compiler isnt impressed though :)

#define WS2811_BITMASK digitalPinToBitMask(3)
#define WS2811_PORTDIR portDIRRegister(digitalPinToPort(3))
#define WS2811_PORTOUT digitalPinToPort(3)

Share this post


Link to post
Share on other sites

Yea I looked at it, hoped it would be compatible :)

Even at 80MHz the timing is pretty tight, 72 cycles for the long delay if I remember correctly.

Share this post


Link to post
Share on other sites

@@MORA99 - This lib is very MSP430 asm dependent.  The CC3200 uses an M4, so there is no chance of a direct port.  You might have some luck looking into a Tiva WS2811 library since it's the same core, but I doubt it would be a simple port.  Once I get my hands on a CC3200 LP I'll probably try to make a compatible WS2811 library for it, or expand this one to work with it 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

×