Skip to content

Instantly share code, notes, and snippets.

@reinvented
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save reinvented/54606f01c0f5fa8d7211 to your computer and use it in GitHub Desktop.
Save reinvented/54606f01c0f5fa8d7211 to your computer and use it in GitHub Desktop.
TIny script to log data from a Grid Insight AMRUSB-1
#!/usr/bin/env python
import serial, sys
from time import strftime
print "Connecting to AMRUSB-1. Press Control+C to abort."
logfilename = 'amrusb-1-' + strftime("%Y%m%d%H%M%S") + 'log'
f = open(logfilename, 'w')
ser = serial.Serial('/dev/ttyACM0')
while True:
try:
line = ser.readline()
logline = strftime("%Y-%m-%d %H:%M:%S") + "\t" + line
sys.stdout.write(logline)
f.write(logline)
except (KeyboardInterrupt, SystemExit):
f.close()
print "Exiting..."
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment