Simple SPI on Raspberry Pi

 This article aims to show a simple method of setting up the SPI interface on the Raspberry Pi Computer with python. The SPI interface is one of the busses made available on the 26 pin GPIO header of the Raspberry Pi.After the setup has been completed, a test circuit using a TLC549 8 bit A/D converter with a potentiometer is used and the output displayed in a python window. The image shows the test circuit attached to our Raspberry Pi Propeller development board, but the circuit can be directly attached to the GPIO header on the R-Pi. The following procedure assumes a clean install of Raspbian 2013-02-09.

Simple SPI on Raspberry Pi

An image of the GPIO header is shown to the right with the necessary connections marked in purple. They include the MOSI, MISO, CLK, CE0, and CE1 pins. In addition the +3.3v, and Ground pins will also be needed to power the slave device.

Setup for SPI use is rather simple. I had to do a lot of Googling to find the simplest method to enable the SPI and have come up with the following procedure:

First it is necessary to enable the peripheral.

Edit:

 /etc/modprobe.d/raspi-blacklsit.conf

Add ‘#’ in front of the line spibcm2708. Save the file.

Next reboot with:

 sudo reboot


    At the prompt type:

 lsmod


You should see spi_bcm2708 in the list.

So far so good.

    Next we have to update the Raspberry Pi in order to be able to find the files
in the following steps. Update using
:

 sudo apt-get update

Simple SPI on Raspberry Pi schematic    With that now complete, it is necessary to install python-dev with:

 sudo apt-get install python-dev


Finally, it is time to install the python SPI wrapper needed for python to access the port.

mkdir python-spi
cd python-spi
wget https://raw.github.com/doceme/py-spidev/master/setup.py

wget https://raw.github.com/doceme/py-spidev/master/spidev_module.c
sudo python setup.py install

 

For more detail: Simple SPI on Raspberry Pi


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top