- Enable SPI on Raspberry PI
- Enable SPI for use in Python
Enable SPI on Rasperry PI
From the command line type:
sudo nano /etc/modprobe.d/raspi-blacklist.conf
Comment out the blacklist spi-bcm2708 by prefixing it with #
Press and hold 'CTRL' and press 'O', then press 'ENTER', then close nano with 'CTRL' + 'X'
You will need to reboot the type:
sudo reboot
When it has restarted you can test if it is working by typing 'lsmod', this display kernel modules loaded, you can wee from the image below the spi_bcm2708 module is now loaded,
SPI is now enabled on the Raspberry PI
Enable SPI for use in Python
To enable SPI to be used in python you need to install the python module for interfacing with SPI.
You will need internet access so you can download the code from github.
git clone https://github.com/doceme/py-spidev
Once you have cloned the py-spidev you will need to change to the directory and use python to install the module.
cd py-spidev
sudo python setup.py install
It is now possible to use import spidev more information can be found here http://tightdev.net/SpiDev_Doc.pdf
import spidev
Is there a difference between spidev (3.2) and the library 'python-periphery', or the 'py-libbcm2835' library? They all seem to do spi, however not sure if they have different applications or if they are just deprecated libraries?
ReplyDeleteInterestingly, the spidev documentation says you can set the number of bits per word(transfer) , 8..16, however according to the pi documentation, the spi peripheral connected to the header only supports 8/9! So perhaps spidev is a generic driver whose functionality may or may not be fully supported by the rpi?
BTW, doesn't a python list ([0x90,0,0,0,0]) consist of ints and not bytes? Does the driver take this into account and convert it to 8-bit bytes before sending?