So for example, every 5 minutes or so, the arduino will send over a few hundred lines of data via serial to the raspberry pi that looks like:
536
366
478
322
366
743
477
.....and so on
My question is: Using python on my raspberry pi, how can I "listen" for when the arduino sends over these data points, and store them in a list?
I have tried this code below, and it seems to only grab and print the first data point sent over, then stops.
Code: Select all
import serial
def read_Serial():
ser = serial.Serial('/dev/ttyACM0', 38400)
ser.flushInput()
ser_bytes = ser.readline()
decoded_bytes = str(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
print(decoded_bytes)
read_Serial()
Ideally the loop would be something like:
- listening for serial values
- captures serial values when sent, and stores as a list
- begins listening again for next batch of serial values
- captures serial values when sent, overwrites previous list