Skip to content

Instantly share code, notes, and snippets.

Created July 23, 2017 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e67e5721800ee74c0c4ed6a43fd87c37 to your computer and use it in GitHub Desktop.
Save anonymous/e67e5721800ee74c0c4ed6a43fd87c37 to your computer and use it in GitHub Desktop.
# -*- 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