1

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?

4

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

sudo raspi-config nonint get_spi

Which returns 1 (enabled) or 0 (disabled)

Similarly, enable with:

sudo raspi-config nonint set_spi 1
  • Wow. That's awesome. Didn't know that this exists. It may solve so many problems! – Thomas Weller Apr 18 at 16:45
  • It seems the numbers are exactly opposite. 1=disabled, 0=enabled – Thomas Weller Apr 25 at 9:02
  • The command to enable is sudo raspi-config nonint do_spi 0 – Thomas Weller Apr 25 at 9:07
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, privacy policy and cookie policy

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