Raspberry Pi and Arduino communications using SPI with Python and CPP

Аватар автора
Питоновый кодер
In an earlier I showed how you can control an Arduino from a Raspberry Pi using USB serial communications (UART). In this I show an alternative way to communicate between a Raspberry Pi and an Arduino by using the SPI (Serial Peripheral Interface) protocol. The advantage of SPI is that you can control multiple devices through one SPI bus. It can also be faster. It is however a little more complicated to understand and code and I¬ properly used the full-duplex feature in my example code. For more details and to download the source code see: The SPI ports on the Raspberry Pi are 3.3V only. They can be damaged by if a slave device raises a bus to 5V. If connecting to a 5V device then a level shifter should be used. Based on all models of the Raspberry Pi with 40pins, the pins for SPI0 are (physical pins): MOSI - pin 19 MISO - pin 21 SCLK - pin 23 CE0 - pin 24 CE1 - pin 26 Ground - pin 25 Different models of the Arduino have different capabilities and ports for SPI. The newer MKR series run at 3.3V, but the more common UNO runs at 5V. I tested this using a Freeduino UNO which has the advantage of being able to switch between 3.3V and 5V, but otherwise similar to the official Arduino. It did have the advantage of allowing me to test the connection was working using 3.3V prior to adding the level shifter. The ports on the Arduino UNO that are used are: MOSI - pin 11 MISO - pin 12 SCLK - pin 13 SS / CE - pin 10 (optional) Due to the voltage difference I suggest...

0/0


0/0

0/0

0/0