0

WS2801 Speed Improvement & Code Additions
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

WS2801 Speed Improvement & Code Additions

by kch on Fri Sep 09, 2011 11:58 am

When working on my string of WS2801 pixels, I noticed that the refresh was quite slow.

The supplied library does its work with digitalWrite() calls. This is very good for a flexible library, but not so good for driving a large array of pixels.

I made some modification to the WS2801 library to do direct port manipulation with bitmasks rather than the digitalWrite method.

On the positive side, my 'show()' loop time dropped from 80 milliseconds to about 9 milliseconds.

On the negative side, It is not that easy to change the pin number for clock and data out. To help solve this problem, I have hard-coded the information in the header file as #defines, where is easier to change in one place. I tried using variables for the masks, but this caused a 50% increase in speed over the #define method. In the interests of speed, I took the more complex path.

Also in the library I have added functions for manipulating the LED pixels in many different ways. Primarily, my work is on organizing the pixels as a grid and using them like a display screen. There is an example file that demonstrates most of the functions.

Where can you find this code? It is all on github.

https://github.com/ph1x3r/WS2801-Library

The code is constantly changing as I make more functions to do various things, so if you do download it, keep an eye on the changelog from time to time and see if there is anything you want to download again.

Bug reports and feedback are welcome.
ph1x3r
kch
 
Posts: 16
Joined: Tue Nov 23, 2010 3:29 pm

Re: WS2801 Speed Improvement & Code Additions

by adafruit on Fri Sep 09, 2011 1:15 pm

awesome - actually there is a way to do this without even hardcoding it using the internal Arduino pin functions. we use this technique in our high speed libs like the TFTLCD and ST7735 libraries but havent had a moment to update this one.

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

Re: WS2801 Speed Improvement & Code Additions

by kch on Fri Sep 09, 2011 3:28 pm

Thanks for the information. I will look at those libraries and see if I can speed it up any further.
kch
 
Posts: 16
Joined: Tue Nov 23, 2010 3:29 pm

Re: WS2801 Speed Improvement & Code Additions

by kch on Sun Sep 11, 2011 11:46 am

I have been busy over the weekend and have re-written the code to use the SPI hardware on the Arduino.

The speed improvement is significant and the library will now push out data at 27.5 microseconds for each pixel.

pixeltiming.png
logic timing for single pixel
pixeltiming.png (84.75 KiB) Viewed 4423 times


The SPI is not running at full speed as I was getting unstable results on the pixel display. The spec says the chips can be clocked at 25Mhz, but a 1Mhz SPI clock is all I can reliable get to work. Since the protocol is only "SPI-like", it may just be that the SPI timing is wrong.

As before, code has been uploaded to my github repository.

Enjoy :D
kch
 
Posts: 16
Joined: Tue Nov 23, 2010 3:29 pm

Re: WS2801 Speed Improvement & Code Additions

by kch on Sun Sep 11, 2011 11:54 am

I have uploaded a video clip to youtube of my LED pixel panel running the example code in my library.

http://www.youtube.com/watch?v=vNSU6pSjbjU

The white panel in the clip is 3ft by 2ft and the pixels are on 1.5" centers. There are spaces on the right hand side of the board to hold more pixels when I can afford them! :(
ph1x3r
kch
 
Posts: 16
Joined: Tue Nov 23, 2010 3:29 pm

Re: WS2801 Speed Improvement & Code Additions

by adafruit on Sun Sep 11, 2011 7:34 pm

wow nice! we'll post this up!

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

Re: WS2801 Speed Improvement & Code Additions

by ceido on Fri Sep 30, 2011 8:39 pm

The only snag I had... (I'm a noob) was working out which output the data and the clock were coming out of! :lol: 11 is data and 13 is clock! This is great, thank you!
ceido
 
Posts: 18
Joined: Fri Sep 30, 2011 4:57 pm

Re: WS2801 Speed Improvement & Code Additions

by CraigKC on Mon Oct 17, 2011 2:25 pm

I don't have any WS2801s handy to test this out, but I did find that a lot of people are also using this library that seems to be well thought out and well written as the author is very much an optimization guru. Maybe someone can offer a direct comparison to the library here? http://code.google.com/p/fastspi/

I don't know much about the guy personally but he seems pretty good at optimization and there's a lot of helpful information about WS2801 (which he loves) and HL1606 (which he isn't fond of) on his blog here too: http://waitingforbigo.com/
CraigKC
 
Posts: 8
Joined: Thu Aug 18, 2011 4:36 pm

Re: WS2801 Speed Improvement & Code Additions

by nahiko on Fri Nov 04, 2011 4:34 am

Hi!!

And which one is better / faster / easier ?

The FASTSPI_LED from waitingfrombigo or the one kch?

Yesterday I tried the FASTSPI_LED one, I just can say that it works, I just tried the example and changed a couple of things to see if it worked properly (at the begining everything went TOO fast to see if it was ok.
But I still did not try using my processing ambilight program with it.

I also tried ph1x3r's "strandtest.pde" but this line
WS2801 strip = WS2801(25, dataPin, clockPin);

fails, as the constructor does not accept those arguments.

I had no time to try many things as it was really late at night

Cheers!
nahiko
 
Posts: 24
Joined: Thu Nov 03, 2011 7:42 am

Re: WS2801 Speed Improvement & Code Additions

by europasteve on Mon Nov 07, 2011 9:04 am

ph1x3r Thanks for the library.
I have it working on a turn signal I'm building.
http://www.youtube.com/watch?v=rGDO-Y9ThPc

I had the matrix wired before I found your code. I commented out the line in WS2801.cpp that Zig Zigs the rows. I'm 27 wide and 3 high
My wiring changes:
0 5 6-to--6 7 8
1 4 7____3 4 5
2 3 8____0 1 2
I'm having a time of flipping X,Y in WS2801.cpp.
The project when finished will have two 3X27 matrixes and two 3 pixel "tails" up in the mirrors. The lights are going to sequence from the front of the car up on to the mirrors. Should look nice.

Thanks again...

Edit:
Still building hardware. 162 Pixels and climbing (81 per signal & 24 per Mirror)
http://www.youtube.com/watch?v=_dw0efkDLs4

europasteve
 
Posts: 10
Joined: Mon Nov 07, 2011 8:38 am

Re: WS2801 Speed Improvement & Code Additions

by europasteve on Sun Mar 04, 2012 4:45 pm

Still at it.
The turn signals are for my wife's car. She named the car OZMA after the princess of OZ, hence the scrolling name.
http://youtu.be/hkilvV_KZgE
Last edited by europasteve on Sun Mar 04, 2012 5:08 pm, edited 1 time in total.

europasteve
 
Posts: 10
Joined: Mon Nov 07, 2011 8:38 am

Re: WS2801 Speed Improvement & Code Additions

by europasteve on Sun Mar 04, 2012 5:02 pm

Oh, and I'm not to good with code so I asked my brother for help. He's a physicist who writes imaging code in C and C++. He download the Arduino IDE and wrote the code in half an hour.... :)

I'll attach the files for anyone to play with, he commented them. If you have questions... Hmmmm I Don't know :roll:

PS it uses Version 0023 of the IDE because that the one I had and I can't get stuff to run on version 1... Shows now much I know...
Attachments
SignalDemo.zip
turn signals
(10.53 KiB) Downloaded 115 times
Last edited by europasteve on Mon Mar 05, 2012 8:11 pm, edited 1 time in total.

europasteve
 
Posts: 10
Joined: Mon Nov 07, 2011 8:38 am

Re: WS2801 Speed Improvement & Code Additions

by pounce on Mon Mar 05, 2012 10:23 am

I don't want this to take away from the awesome work you have done. Please be careful with your color choice for lights on a vehicle. You can only use Red or Amber/Orange on car if you are in the states. I don't know about other places. Only law enforcement, ambulances, and emergency vehicles can use blue or other colors. I think you will be able to make a few mods and keep red and amber. Also, tail lights must reflect red when the car is off and parked etc. I can't tell from your video if that is an issue for you or not.

Just want you and your wife to be safe and stay out of trouble...and have cool tail lights :)

Nice work. Thanks for sharing!
pounce
 
Posts: 82
Joined: Wed Nov 23, 2011 6:36 pm

Re: WS2801 Speed Improvement & Code Additions

by europasteve on Mon Mar 05, 2012 8:07 pm

Yes Yes, If the motor is running only amber turn signals or white running lights. Motor has to be off to run in "Show Mode".
Looking into car wiring or sensor to use so they won't allow "Show Mode" if the vehicle is moving. Anywhere but a car show and these are definitely an expensive ticket.

These are car front and side mirror lights. Tail lights are stock.

Thanks for the reminder to point that out.

SteveD

europasteve
 
Posts: 10
Joined: Mon Nov 07, 2011 8:38 am

Please be positive and constructive with your questions and comments.