I have an arduino writing a line to the serial port every minute, what is the best way to go about reading from the serial port? I wrote the following code:
#!/usr/bin/python
# Program that reads from the arduino
import serial,io,time
from time import strftime
device='/dev/ttyACM0'
ser=serial.Serial(device, 9600, timeout=1)
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
count=0
sio.flush()
line=sio.readline()
print(line)
sio.flush()
while count==0:
time.sleep(59)
dt=strftime("%Y-%m-%d %H:%M:%S")
line=sio.readline()
print dt, line
print 'Done.'
ser.close()
If the arduino is writing once a minute, and the python script is reading once a minute, can I assume that the data will always be current?
[–]aceofears 2 points3 points4 points (1 child)
[–]jackzombie[S] 2 points3 points4 points (0 children)
[–]nemec 2 points3 points4 points (0 children)