User Guide
Table Of Contents
172
wants to communicate with it, and others expect the SS line to
be low.
Enabling SPI on the Raspberry Pi
You can use any of the GPIO input/output pins for SPI since it
only involves bringing pins high and low, and reading input in
the same way as described earlier in this chapter. This approach
is often called “bit-banging”. However, five of the Raspberry Pi’s
GPIO pins have alternative uses for communicating over SPI. By
using these pins you can use prebuilt libraries and tools instead
of writing as much code.
The SPI pins on the GPIO header are: MOSI – pin 19; MISO – pin
21; SCK – pin 23. The header has two slave select pins – pin 24
and pin 26.
By default, the SPI functions of these pins are disabled in
Raspbian. To enable them:
1. On the Application Launcher, click LXTerminal.
2. Type the following command and then press Enter:
sudo raspi-config
3. Press the Down Arrow key seven times to select
Advanced Options, and then press Enter.
4. Press the Down Arrow key four times to select SPI,
and then press Enter.
5. Press Enter.
6. Press Enter.
7. Press the Right Arrow key twice to select <Finish>.
Then press Enter.
8. Type the following command and then press Enter:
sudo nano /etc/modules
9. On a new line at the end of the file, add the
following text:
spi-dev
10. Press Ctrl + O, and then press Enter.