How to Enable SPI on Raspberry Pi: Step-by-Step Guide
To enable
SPI on a Raspberry Pi, run sudo raspi-config, navigate to Interface Options, then select SPI and enable it. Alternatively, add dtparam=spi=on to /boot/config.txt and reboot the Pi.Syntax
There are two main ways to enable SPI on Raspberry Pi:
- Using raspi-config tool: This is an interactive menu to enable SPI easily.
- Editing config.txt file: Manually add a line to enable SPI at boot.
Commands and file lines:
bash
sudo raspi-config # Navigate: Interface Options -> SPI -> Enable # Or edit /boot/config.txt and add: dtparam=spi=on
Example
This example shows how to enable SPI using the raspi-config tool and verify it is active.
bash
sudo raspi-config
# Use arrow keys to select Interface Options
# Select SPI and choose Yes to enable
# Exit raspi-config
# Reboot the Raspberry Pi
sudo reboot
# After reboot, check SPI devices
ls /dev/spi*Output
/dev/spidev0.0 /dev/spidev0.1
Common Pitfalls
Common mistakes when enabling SPI on Raspberry Pi include:
- Not rebooting after enabling SPI, so changes don't take effect.
- Forgetting to enable SPI in
raspi-configor missing thedtparam=spi=online inconfig.txt. - Trying to access SPI devices without proper permissions (run commands with
sudoor add user tospigroup).
bash
Wrong way (no reboot):
# sudo raspi-config
# Enable SPI
# Immediately try to use SPI without reboot
Right way:
# sudo raspi-config
# Enable SPI
# sudo reboot
# Then use SPI devicesQuick Reference
| Step | Command or Action | Description |
|---|---|---|
| 1 | sudo raspi-config | Open Raspberry Pi configuration tool |
| 2 | Interface Options → SPI → Enable | Enable SPI interface |
| 3 | sudo reboot | Restart Raspberry Pi to apply changes |
| 4 | ls /dev/spi* | Check SPI device files exist |
| Alternative | Add dtparam=spi=on to /boot/config.txt | Enable SPI manually via config file |
Key Takeaways
Enable SPI using sudo raspi-config under Interface Options for easiest setup.
Add dtparam=spi=on to /boot/config.txt as an alternative method.
Always reboot the Raspberry Pi after enabling SPI to activate changes.
Verify SPI is enabled by checking for /dev/spidev* device files.
Ensure proper permissions to access SPI devices, use sudo or add user to spi group.