As you know from my previous posts, I wanted to communicate from Raspberry to chained WS2801 led drivers using python. Now that it is working fine, I can make a synthesis of what needs to be done :

  1. Unblacklist the spidev driver :

sudo nano /etc/modprobe.d/raspi-blacklist.conf

just comment ("#") the line which blacklists the spi-bcm2708 driver.

  1. Set the driver to be loaded at startup :

sudo vi /etc/modules

then add "spi_bcm2708" in a new line and restart :

sudo shutdown -r now

  1. Now you need to connect a 5V PSU to he GND and +5V of the raspberry header and your led string (do not use a PSU on the USB connector). Also connect SCLK to the clock signal of the WS2801 led string, and data signal to the MOSI (just search)

Warning : I had strange behaviour when I did like this. I tracked the problem down to some extra clock signal interpretation when the signal is still stabilizing. I could solve this by adding a 18kR (the first large value which came from my resistor box) between SCLK and the CLOCK pin of the first WS2801.

  1. Everything is ready, the python code is rather simple :
[python]
import time
import math
import array
import fcntl

spidev = file("/dev/spidev0.0", "wb")
#byte array to store the Red, Green and Blue values
rgb=bytearray(3)
#set the spi frequency to 400kbps
fcntl.ioctl(spidev, 0x40046b04, array.array('L', [400000]))

while True :

   for i in range(0, 48):
      #use your own colors here
      rgb[0] = 1
      rgb[1] = 1
      rgb[2] = 1
      spidev.write(rgb)

   spidev.flush()
   flipflop = not flipflop
   time.sleep(0.002)