Create a gist now

Instantly share code, notes, and snippets.

anonymous /test.py
Created Jul 23, 2017

What would you like to do?
# -*- coding: utf-8 -*-
import serial
from datetime import datetime
ser = serial.Serial(port='/dev/ttyACM0', baudrate=38400, timeout=0.5)
file = 'test.csv'
line = ser.read(1000)
#infinity loop
while True:
if( ser.inWaiting() > 0 ):
data = ser.read()
f = open(file, 'a')
f.write(data)
print data
if( '\n' in data ):
now = datetime.now().strftime('%Y/%m/%d %H:%M:%S, ')
f.write(now)
print now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment