I'm doing a preliminary script for reading the serial port when i send the "1" over serial for infinite time every 3 minutes. I need a thread script because this it will have to be integrated with others function together serial . The serial port is connected to an arduino with sensor but i'm not sure program is formally corrected. Anyone can help me please? Thanks
#!/usr/bin/python
import time
import serial
import threading
import time
import io
ser=serial.Serial('/dev/ttyUSB0', 57600, timeout=3)
def printit():
threading.Timer(180.0, printit).start()
ser.write(b'1\n')
lettura=ser.readline()
print lettura
try:
printit()
except:
print "Error: unable to start thread"
while 1:
pass