PDA

View Full Version : Hardware SPI with Python on a Raspberry Pi



wraggster
January 6th, 2013, 21:19
http://hackadaycom.files.wordpress.com/2013/01/raspi_arduino_spi.png?w=580&h=378
While the Raspberry Pi has very good support for an I2C bus, a lot of very cool chips – including the in system programmer for just about every ATtiny and ATmega microcontroller – use an SPI bus. [Louis] sent in a tutorial for getting hardware SPI on his Raspi (http://louisthiery.com/spi-python-hardware-spi-for-raspi/), and even though it’s rather limited right now, it’s a step in the right direction.
Previously, [Brian Hensley] put up a tutorial for using the Linux SPI drivers with the Raspi (http://www.brianhensley.net/2012/07/getting-spi-working-on-raspberry-pi.html). [Louis] wanted to play with SPI in Python, so he added a C extension to the spidev.c file (available here (https://github.com/lthiery/SPI-Py)) that allows him to open an SPI connection, initialize, transfer, and close the connection.
After connecting an Arduino to the MOSI, MISO and SCK pins of his Arduino, [Louis] was able to transfer data from his Raspi over an SPI bus. It should be noted that a level shifter would be a really good idea here, but this is an excellent project if anyone would ever want to port AVRDude to Python.

http://hackaday.com/2013/01/06/hardware-spi-with-python-on-a-raspberry-pi/