Posts: 1
Joined: Wed Feb 22, 2017 8:25 pm

SPI communication with Arduino

Wed Feb 22, 2017 8:30 pm

I have been trying to figure out how to communicate with the Arduino Uno r3 through SPI using python but do not know how to approach it.

Posts: 9
Joined: Tue Jan 17, 2017 1:46 am
Location: Switzerland
Contact: Website

Re: SPI communication with Arduino

Thu Feb 23, 2017 2:15 am

I'd like to help you, but I'm not really sure what the question is...

I have an RPI talking to a nano over the USB and it is just typical serial comms. Where do you have the issue?

Posts: 1348
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: SPI communication with Arduino

Thu Feb 23, 2017 7:08 am

SPI comm to arduino is possible, pi as master, arduino slave.
When you say 'arduino', most possibly you mean 'UNO' ? This is a 5V-world, so SCK, MOSI and possibly CS are outputs for pi, can be connected. MISO is 5V from arduino UNO, you need a voltage shifter or divider to connect.
The atmel328 has no dedicated CS input for SPI. I usually use one of the interrupt pins to get the signal into the atmel.

On pi side, install python dev and spidev. Make SPI speed really slow for first experiments, even with hand crafted assembler code there is a limit at about 240k for multibyte transmissions.
On atmel side, enable interrupts for SPI system and keep the ISR short, only grab acquired data and place return data. The pause between bytes is 1,5 clocks, so no room for calculations in ISR.

Logic analyzer is useful for debugging.

Some example how to connect bare atmel328 to a pi, see

Return to “Python”