Enable SPI Interface on the Raspberry Pi


The Raspberry Pi has an SPI (Serial Peripheral Interface) bus which can be enabled on Pins 19,21,23,24 & 26. It is a synchronous serial data link standard and is used for short distance single master communication between devices. As far as the Pi is concerned this is usually relevant to certain sensors and add-on boards.

Step 1 – Enable SPI Interface

The default Raspbian image disables SPI by default so before you can use it the interface must be enabled. This can be done using either of three methods. I’ll describe all methods but the first one is probably easier and quicker.

Method 1 – Using “Raspi-config” on Command Line

From the command line or Terminal window start by running the following command :

sudo raspi-config

This will launch the raspi-config utility. Select “Interfacing Options” :

Raspi-Config - Interfacing

Highlight the “SPI” option and activate “<Select>”.Raspi-Config - Interfacing - SPI

Select and activate “<Yes>” :
Raspi-Config - Interfacing - SPI 1

Highlight and activate “<Ok>” :

Raspi-Config - Interfacing - SPI 2When prompted to reboot highlight and activate “<Yes>” :

Raspi-Config - Reboot Prompt

The Raspberry Pi will reboot and the interface will be enabled.

Method 2 – Using “Raspberry Pi Configuration”

If your Pi boots to the desktop you can either open a Terminal window and use Method 2 or use the graphical tool “Raspberry Pi Configuration”. This is found under Menu > Preferences > Raspberry Pi Configuration

Raspberry Pi Configuration launch from menu

Then you simply need to select the “Interfaces” tab and set SPI to “Enabled” :

Raspberry Pi Configuration - Interfaces Tab - SPI

Click the “OK” button. If prompted to reboot select “Yes” so that the changes will take effect.

Raspberry Pi Configuration - Reboot Prompt

The Raspberry Pi will reboot and the SPI interface will be enabled.

Method 3 – Enabling By Editing A File Manually

This process assumes you are using the latest Raspbian build from the official downloads page. You can update your current image using :

sudo apt-get update
sudo apt-get upgrade

To enable hardware SPI on the Pi we need to make a modification to a system file :

sudo nano /boot/config.txt

Add the following line at the bottom :


Use CTRL-X, then Y, then RETURN to save the file and exit. Reboot using the following :

sudo reboot

Step 2 – Checking If SPI Is Enabled (Optional)

To check if the SPI module is loaded by the system run the following command :


You should see “spi_bcm2708″ or “spi_bcm2835” listed in the output. You can use the following command to filter the list and make it easier to spot the spi entry :

lsmod | grep spi_

SPI is now enabled.

Step 3 – Install Python SPI Wrapper

In order to read data from the SPI bus in Python we need some additional libraries. These may already be installed but you can check using :

sudo apt-get install -y python-dev python3-dev

and :

sudo apt-get install -y python-spidev python3-spidev

Then to finish we can download ‘py-spidev’ and compile it ready for use :

cd ~
git clone https://github.com/Gadgetoid/py-spidev.git
cd py-spidev
sudo python setup.py install
sudo python3 setup.py install
cd ~

You should now be ready to either communicate with add-on boards using their own libraries (e.g. the PiFace) or other SPI devices (e.g. the MCP3008 ADC).

A full list of tutorials featuring this interface can be found by clicking here.

Finally, there is more technical information about SPI on the Wikipedia page if you are interested.



  1. Hi ; had my spi working before , recently updated my firmware and I now get error: spi_bcm2708 not found . I have followed your steps to getting spidev. It still isn’t listed on lsmod. There is spi_bcm2835 and i2c_bcm2708 . Any suggestions on my next step ?

  2. I’m having the same problem on all my raspis.
    I can’t make it work.
    Activation via raspi-config fails because it can’t load the driver.
    gpio load spi fails with the same message.
    Did something change in raspian?

    • I tested this with the 2015-09-24 version of Raspbian when I setup my Temperature Logger MkII. It is always worth downloading the latest image and writing a fresh SD card.

  3. It worked for me only with the last method. Thanks a lot. I spend a whole day trying to figure out how to solve this error. Thank you

  4. Matthew Najmon on

    From the Python SPI Wrapper section:
    “sudo apt-get install python3-spidev python-spidev”

    When I tried running that on my pi (immediately after running apt-get update and apt-get upgrade), I got an error:

    The following packages have unmet dependencies:
    python3-spidev : Depends: python3 (>= 3.4~) but 3.2.3-6 is to be installed
    E: Unable to correct problems, you have held broken packages

    What does this mean? Best I can tell, it seems to be dependent on a version of python3 that’s newer than what’s on that repository. Is this something I screwed up? Does the package have an incorrect dependency on the repository? How do I fix this?

    • The default Python 3 on Raspbian at this time is 3.5.3. I would re-write the SD card with a fresh copy of Raspbian as it will be quicker than trying to work out why you’ve got 3.2.3.

  5. I certainly may be clueless, but the detailed instructions are great, but for me I think they are missing one item:

    – first time through this tutorial, when I did the “sudo python setup.py install”, I get a C error:
    line 20:20 missing #include
    – I happen to have the Donald Norris book (where he copied your excellent tutorial and gave you attribution). He had an extra install line “sudo apt-get install python-dev”
    – did I miss that on this web page? anyway, after that installation of python-dev, the “sudo python setup.py install” worked perfectly, no errors.


    • python-dev and python3-dev should already be installed in the latest Raspbian image. I would always recommend starting with a fresh install of Raspbian.

    • Those pins are already GPIO pins. Just disable SPI,I2C and UART in raspi-config and the pins will be normal GPIO pins.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.