1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| import serial import time
ser = serial.Serial('/dev/ttyACM0', 115200) f = open('filename.csv', 'w', encoding = 'utf-8') t = time.time()
try: while True: if ser.in_waiting != 0: t1 = time.time() - t t2 = round(t1, 5) t3 = str(t2) sensor = ser.readline() print(t3) print(sensor.decode()) f.write(t3) f.write(',') f.write(sensor.decode()) except: f.close()
|