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
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.