0

control WS2801 by Raspberry Pi
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

control WS2801 by Raspberry Pi

by MrFix on Mon Aug 13, 2012 3:55 pm

Hi Guys,

I'm new here and I think this site with all its members and tutorials is awesome.

With that said, I'm wondering how I can control the WS2801, as bought on this website, with an Raspberry Pi (RP). I saw the tutorial with Arduino but I think you can definitely do the same with the RP.

The RP does have GPIO pins on witch I guess you can mount the LED's.
Image

I know it's possible because I've looked it up a few weeks ago. But I didn't find a clear solution/code. And that's the problem, the code. I know you can attach it to the gpio pins but how to control these is a big question to me. C? Python? A library? And can the code run realtime on the background so I can control the led's on the fly?

Is there anyone who can help me out? I don't aspect a very clear code offcourse.

Let me know.

Peter
MrFix
 
Posts: 2
Joined: Mon Aug 13, 2012 3:42 pm

Re: control WS2801 by Raspberry Pi

by pburgess on Mon Aug 13, 2012 4:33 pm

Hi Peter,

I'd suggest looking at the recent Light Painting tutorial for ideas. Using the Occidentalis Linux image and the hardware SPI pins makes everything amazingly simple! The tutorial was written for the LPD8806 LED strips, but with just a few simple changes should work on the WS2801 LEDs as well.

The gamma table calculation changes from:
Code: Select all | TOGGLE FULL SIZE
gamma[i] = 0x80 | int(pow(float(i) / 255.0, 2.5) * 127.0 + 0.5)

to:
Code: Select all | TOGGLE FULL SIZE
gamma[i] = int(pow(float(i) / 255.0, 2.5) * 255.0 + 0.5)


Don't need the extra latch byte at the end. Allocation changes from:
Code: Select all | TOGGLE FULL SIZE
column[x] = bytearray(height * 3 + 1)

to:
Code: Select all | TOGGLE FULL SIZE
column[x] = bytearray(height * 3)


LEDs use RGB color order rather than GRB. Conversion changes from:
Code: Select all | TOGGLE FULL SIZE
      column[x][y3]     = gamma[value[1]]
      column[x][y3 + 1] = gamma[value[0]]
      column[x][y3 + 2] = gamma[value[2]]

to:
Code: Select all | TOGGLE FULL SIZE
      column[x][y3]     = gamma[value[0]]
      column[x][y3 + 1] = gamma[value[1]]
      column[x][y3 + 2] = gamma[value[2]]


There needs to be at least a 500 microsecond delay between columns in order for image to 'latch'. The sample code already has a 1 millisecond delay there and should work fine.

This can be pretty easily adapted to C or other languages as well, just need to open the "/dev/spidev0.0" device, write, flush and delay. And you'll need to run your code as 'root' a la sudo.

pburgess
 
Posts: 4022
Joined: Sun Oct 26, 2008 2:29 am

Re: control WS2801 by Raspberry Pi

by MrFix on Mon Aug 13, 2012 5:04 pm

Thanks for your reply!

Does look awesome and does the trick but it is to complicated for how I want to use it. I just want to control 5 led, make them blue red yellow etc. Fade in, fade out. Not that complicated. It would be ideal if I don't have to install that much software because I still want to run XBMC on the foreground. Any suggestions how to manage this?
MrFix
 
Posts: 2
Joined: Mon Aug 13, 2012 3:42 pm

Re: control WS2801 by Raspberry Pi

by charlieczech on Tue Sep 04, 2012 10:36 am

Thanks to pburgess my WS2801 lighting is up and running. I have to remove last line in code "time.sleep(0.5)" some how its error there and because I'm starting with python I need to dig in deeper to find out why.
I really like the idea controlling my lighting with Raspberry. Because of my minimal knowledge about electronic I need to start from beginning to fully understand what is happening between GPO and WS2801 chip.
English is my 2nd language.
charlieczech
 
Posts: 1
Joined: Tue Sep 04, 2012 3:48 am
Location: Leeds GB / Opava CZ

Please be positive and constructive with your questions and comments.