0

New High-Speed SPI Library for LPD8806 LED Strips
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

New High-Speed SPI Library for LPD8806 LED Strips

by cjbaar on Sat Sep 17, 2011 12:48 pm

After reading through some of the forums here, and building on a few examples from others, I have put together a modified version of the LPD8806 library that uses the native hardware SPI on an Arduino board to significantly increase the write speed to the strip.

I have tested the code on an Arduino Uno (16MHz), with a full five-meter strip of 160 LEDs. At this size, the original software emulation took around 200ms to update all 160 LEDs. This gave me a refresh rate of only 5fps.

This very helpful post explains how to modify the write8() function to use direct port access, which is big improvement. This got me up to 25fps at 160 LEDs, but I still needed something faster.
http://forums.adafruit.com/viewtopic.php?f=47&t=22929

Using the SPI bus directly, I am able to achieve refresh rates of up to 167fps (around 37us per pixel). It's actually fast enough that the amount of calculation you do between the show() calls can affect the framerate. For example, the sample functions colorChase() or colorWipe() -- which only modify two pixels each time -- run at up to 167fps with no delay specified. If you modify all of the pixels every time, the refresh rate drops to around 140fps. If you perform other calculations -- such as the sample rainbowCycle() function -- the frame rate drops to around 85 fps.

Again... all of these tests were done on a strip of 160 LEDs. If you are only running one meter (32 LEDs), you could theoretically get even higher speeds.

Any feedback or comments are appreciated. This is my first attempt at writing and publishing low-level code, but hopefully I have given credit to the original authors where it is due.

The library is currently posted at https://github.com/cjbaar/LPD8806

cjbaar
 
Posts: 73
Joined: Fri Aug 26, 2011 5:58 pm

Re: New High-Speed SPI Library for LPD8806 LED Strips

by cjbaar on Sat Sep 17, 2011 3:24 pm

I got a couple of videos posted to show this driver in action. The visual difference in impressive. Both runs use the included sample sketch, which runs through various passes of colorChase(), colorWipe(), and the rainbow sequences. I eliminated all of the wait values so what you see is nothing but the sending of data down the strip.

Here is the result using the original software-based library. Note that I cut this video in half. One full run through the loop() series takes around 12.5 minutes.
http://www.youtube.com/watch?v=4iXgoBn9sLU

Here is the result of the same sequence using the hardware SPI library. The full loop() takes about 26 seconds... almost 30x faster.
http://www.youtube.com/watch?v=2xbZTF4GZBc

cjbaar
 
Posts: 73
Joined: Fri Aug 26, 2011 5:58 pm

Re: New High-Speed SPI Library for LPD8806 LED Strips

by adafruit on Mon Sep 19, 2011 6:24 am

nice work! do you mind opening an issue on github with a link to this library so we'll remember to update it?

adafruit
 
Posts: 12124
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: New High-Speed SPI Library for LPD8806 LED Strips

by cjbaar on Tue Sep 20, 2011 12:21 am

No problem. I think it's done.

cjbaar
 
Posts: 73
Joined: Fri Aug 26, 2011 5:58 pm

Re: New High-Speed SPI Library for LPD8806 LED Strips

by bkuehner on Tue Sep 20, 2011 11:49 pm

Thanks! The original 8806 code was too slow for my needs, so I was just about to look at changing it to use SPI. I'm happy to see you've done the work for me. Your library is working fine for me so far.

bkuehner
 
Posts: 14
Joined: Sun Jan 09, 2011 8:19 pm

Re: New High-Speed SPI Library for LPD8806 LED Strips

by adafruit on Wed Sep 21, 2011 1:19 am

thanks! we will be integrating your updates as soon as we can, thank you :)

adafruit
 
Posts: 12124
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: New High-Speed SPI Library for LPD8806 LED Strips

by Pewright on Wed Sep 21, 2011 5:49 am

Great work, I've been using the LPD8806 on SPI for a few weeks now but your code will certainly help optimise it. I've learnt quite a bit from it such only needing to send 4 zeros to latch and the way you have replaced SPI.transfer - excellent.

I have also made it so you can drive strips Independently by adding a slave select to an AND gate that only lets the clock through to the strip we are trying to control. The schematic and a program that converts bitmaps to LPD8806 / WS2801 and HL1606 for lightpainting is also on my site www.wright-online.com
Pewright
 
Posts: 1
Joined: Thu Sep 08, 2011 3:52 am

Need SPI.h library

by DoctorDidj on Thu Sep 22, 2011 8:09 pm

Awesome, this is just what I was looking for! Your demo needs the SPI.h library which my compiler can't find. I'm looking in the Arduino shared libraries to see if I can find it there. If not, is there someplace else I should be looking for it?
Food Processor with Ears
User avatar
DoctorDidj
 
Posts: 28
Joined: Fri Apr 27, 2007 9:30 am
Location: Boston

Re: New High-Speed SPI Library for LPD8806 LED Strips

by adafruit_support_bill on Fri Sep 23, 2011 5:42 am

The SPI library is included with the Arduino IDE. Do you have the latest version?
http://arduino.cc/en/Reference/SPI

adafruit_support_bill
 
Posts: 59028
Joined: Sat Feb 07, 2009 10:11 am

Re: New High-Speed SPI Library for LPD8806 LED Strips

by DoctorDidj on Fri Sep 23, 2011 7:31 pm

I"m using 0018 which I thought was fairly current. In its directory tree I find spi.h in libraries/Ethernet/utility/ but the IDE doesn't find it there. If I copy spi.h to my sketch directory library, the IDE finds it okay but then barfs on a bunch of undefines, probably because there's no spi.cpp there. I can't find an spi.cpp anywhere. Not sure what's up with that.

I'll try updating to the most current version, see if that makes a difference.
User avatar
DoctorDidj
 
Posts: 28
Joined: Fri Apr 27, 2007 9:30 am
Location: Boston

from bad to worse

by DoctorDidj on Fri Sep 23, 2011 8:30 pm

Well, I went to http://arduino.cc/playground/Linux/Ubuntu and installed 0022 which is the latest and greatest. No spi.h, Spi.h or SPI.H to be found anywhere at all. Nada. I'm confused.
Food Processor with Ears
User avatar
DoctorDidj
 
Posts: 28
Joined: Fri Apr 27, 2007 9:30 am
Location: Boston

Re: New High-Speed SPI Library for LPD8806 LED Strips

by cjbaar on Sat Sep 24, 2011 1:28 am

That is odd. I haven't used the development environment on Linux, but I assume it should be in the main /libraries folder under the arduino tree. The folder is SPI, and the files should be (case-sensitive) SPI.cpp and SPI.h. According to http://arduino.cc/en/Reference/Changes, the SPI library has been included since version 0019.

cjbaar
 
Posts: 73
Joined: Fri Aug 26, 2011 5:58 pm

which version to use

by DoctorDidj on Sat Sep 24, 2011 7:59 am

Well, at least that confirms that 0018 does not have the SPI library.

The 0022 version didn't install properly, there were some errors, so maybe it got interrupted before it could load everything.

Next, I can look around to see if there's a version in between that will install properly on my system (Ubuntu Lucid on AMD64, its own apt-get says 0018 is the most recent version).
Food Processor with Ears
User avatar
DoctorDidj
 
Posts: 28
Joined: Fri Apr 27, 2007 9:30 am
Location: Boston

version issues

by DoctorDidj on Sat Sep 24, 2011 11:13 pm

Dunno why the .deb install of 0022 doesn't work, but I've downloaded the binary from arduino.cc and it works fine, including the SPI library. My tape is now going full speed. Thanks!
Food Processor with Ears
User avatar
DoctorDidj
 
Posts: 28
Joined: Fri Apr 27, 2007 9:30 am
Location: Boston

Re: version issues

by cjbaar on Sun Sep 25, 2011 1:00 am

Glad to hear it!

cjbaar
 
Posts: 73
Joined: Fri Aug 26, 2011 5:58 pm

Please be positive and constructive with your questions and comments.