3

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?

2 Answers 2

7

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
1
  • Shouldn't it be sudo raspi-config nonint do_spi 1? Commented Aug 24, 2023 at 9:56
1

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.

#!/bin/bash

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

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 and acknowledge you have read our privacy policy.

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