I have a game that needs SPI. In the installation instructions, I noted that SPI has to be enabled via raspi-config.

Now, I'd like to check in a shell script whether the user has activated SPI or not. How can I query the SPI state?


You can use raspi-config non-interactively to get the SPI status:

sudo raspi-config nonint get_spi

Which returns 0 (enabled) or 1 (disabled)

Similarly, enable with:

sudo raspi-config nonint do_spi 0
  • Thanks - corrected – ben_nuttall May 28 '19 at 15:06

SPI does not have to be enabled by raspi-config. It is just a convenient way of doing so on Raspbian.

Try something like the following to check if the kernel SPI device exists.


if [[ -e /dev/spidev0.0 ]]
then echo "SPI exists"
else echo "no SPI"

This isn't fool proof as you don't need to use the kernel driver to use SPI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.