I typically send a bunch of information back and forth between Arduino and Raspberry PI.
Data such as Odometry, Range Findings, Environmental information, and health of the Rover.
Today, I'm doing this via SPI, but the question was asked about how this is done via Serial, and specifically how to read and process the Arduino Serial Data in python, on the Raspberry PI.
So here is how *I've* tackled this (your mileage may vary, this is just an example)
(I send a CRLF terminated line starting with a data type descriptor: in this case "SNSR" for sensor data)
On the Raspberry Pi Python Side:
(Caveat: this is just a snippet from my code... it will not function fully as is:)
- I import Serial
- I declare a function to read and parse a line from Serial
- I set up the serial port and open it.
- I then wait for incoming data in my main loop. If the first field matches what I'm looking for, I update my variables.