Controlling a 595 using SPI from Python (working)

4 posts
by sinneb » Thu May 24, 2012 8:49 pm
With the kernel driver from bootc, I've been able to control a 74HC595 over SPI using Python on the Rpi.

Software part (did it a few days ago, perhaps missing a step)

> Installed the debian6 image
> updated & upgraded the packages
> installed bootc ( rpi kernel (3.2.17)
> rebooted and dmesg shows SPI enabled
> a "ls -al /dev/spi*" shows the /dev/spidev0.0 device, ready for use
> Brian Hensley ( ... us-on.html) wrote SPI code to use from Python on a Beagleboard but this is also working on the Rpi.
> Following the instruction, you'll compile spimodule.c using (both supplied by Brian).
> Changed the following in his code: data = ["00"] to turn every port off the 595 off, data = ["FF"] to turn every port to on. Also changed -> a = spi.SPI(0,0)
> Run this code using sudo (direct port access)

Hardware part

> Using the GPIO pin layout for the Rpi on the wiki (
> Connect 5v to 595 pin 10 and pin 16
> Connect GND to 595 pin 8 and pin 13
> Connect SPI0 MOSI to 595 pin 14
> Connect SPI0 SCLK to 595 pin 11
> Connect SPI0 CE0 N to 595 pin 12
> Connect LED's to pin 1 etc.

Still needs work in the C module etc, but this is a nice proof of concept.
Posts: 2
Joined: Fri Apr 20, 2012 10:42 am
by jbeale » Thu May 24, 2012 8:56 pm
great to hear it! Look forward to seeing more R-Pi hardware interfacing activity.
User avatar
Posts: 2005
Joined: Tue Nov 22, 2011 11:51 pm
by df8ms » Mon May 28, 2012 7:41 am
Do I see it correct, that this SPI implementation does not use the Broadcom SPI peripherials ?
If yes, is there a device specific implementation so far ?

best regards
Posts: 2
Joined: Mon May 28, 2012 7:38 am
by bootc » Mon May 28, 2012 7:48 pm
sinneb - you shouldn't need to be root; you should be able to chown the /dev/spidev0.X device nodes to a non-root user and then use them as said user.

df8ms - my kernel has a driver for the Broadcom SPI peripheral, and transfers are done in interrupt mode for minimum CPU usage. My kernel also has a driver for the Broadcom BSC (I2C) units as well.

My latest kernel: ... pi-kernel/

You can take a look through my blog to see how I've been working on the drivers too :-)
Posts: 19
Joined: Mon May 28, 2012 7:45 pm