You have an SPI (serial peripheral interface) bus that you want to use with your Raspberry Pi.
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.