0
0
Iot-protocolsHow-ToBeginner · 3 min read

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-config or missing the dtparam=spi=on line in config.txt.
  • Trying to access SPI devices without proper permissions (run commands with sudo or add user to spi group).
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 devices
📊

Quick Reference

StepCommand or ActionDescription
1sudo raspi-configOpen Raspberry Pi configuration tool
2Interface Options → SPI → EnableEnable SPI interface
3sudo rebootRestart Raspberry Pi to apply changes
4ls /dev/spi*Check SPI device files exist
AlternativeAdd dtparam=spi=on to /boot/config.txtEnable 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.