Question 8.6: You have an SPI (serial peripheral interface) bus that you w......

You have an SPI (serial peripheral interface) bus that you want to use with your Raspberry Pi.

Step-by-Step
The 'Blue Check Mark' means that this solution was answered by an expert.
Learn more on how do we answer questions.

If you are using Adafruit Occidentalis 0.2 or later, there is nothing to do. The distribution is preconfigured with SPI support.

If you are using Raspbian, there are a couple of configuration changes you need to make.

Edit the file /etc/modules using the command sudo nano /etc/modules and add the following line to the end of it:

spidev

You may also need to edit the file /etc/modprobe.d/raspi-blacklist.conf and comment out the line:

blacklist spi-bcm2708

by adding a # character in front of it:

#blacklist spi-bcm2708

If you plan to use I2C, you may want to comment out the I2C line from the blacklist as well.

The SPI feature of the Raspberry Pi is also supported by a Python library that will allow you to carry out SPI communication from a Python program. To install this, first install Git (Recipe 3.19), and then issue the following commands:

$ cd ~
$ sudo apt-get install python-dev
$ git clone git://github.com/doceme/py-spidev
$ cd py-spidev/
$ sudo python setup.py install

Reboot your Pi and it will be ready for SPI.

Discussion

SPI allows serial transfer of data between the Raspberry Pi and peripheral devices, such as analog-to-digital converter (ADC) and port expander chips, among other devices.

You may come across some examples of interfacing to SPI that do not use the SPI interface but instead use an approach called bit banging, where the RPi.GPIO library is used to interface with the four GPIO pins used by the SPI interface.

See Also

We use a SPI analog-to-digital converter chip in Recipe 12.4.

Related Answered Questions

Question: 8.16

Verified Answer:

The PiFace Digital (“Modules” on page 381) is an e...
Question: 8.15

Verified Answer:

Use a boost regulator module (Figure 8-10). The mo...
Question: 8.14

Verified Answer:

A typical project using a Raspberry Pi requires 5V...
Question: 8.11

Verified Answer:

Use a Pi Cobbler, a device consisting of a small p...
Question: 8.9

Verified Answer:

Install Minicom: $ sudo apt-get install minicom...
Question: 8.21

Verified Answer:

You can use the paddle terminal breakout board sho...
Question: 8.20

Verified Answer:

The Pi Plate (Figure 8-16) is a prototyping board ...
Question: 8.19

Verified Answer:

The Humble Pi (Figure 8-15) is a prototyping board...
Question: 8.17

Verified Answer:

Figure 8-13 shows a Gertboard attached to a Raspbe...