Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import serial
- import platform
- import glob
- import time
- filename = "Electrometer " + str(int(time.time())) + ".txt"
- print "617 Programmable Electrometer Reader"
- print "(C) 2016 Daniel Centore"
- print ""
- print "Instructions (Windows):"
- print " * Find the Arduino COM port using device manager"
- print " * Type the COM port in below (ex COM6)"
- print ""
- print "Instructions (Linux)"
- print " * Find the Arduino port by using ls in /dev/"
- print " * Type the full port name below (ex /dev/ttyACM4)"
- print ""
- print "Instructions (All)"
- print " * File data will appear in the file \"" + filename + "\""
- print " * Press Ctrl+C to quit data collection"
- print ""
- port = raw_input("Pick a port: ")
- ser = serial.Serial(port, 9600)
- # Discard the early data
- millis = int(round(time.time() * 1000))
- newMillis = int(round(time.time() * 1000))
- while newMillis < millis + 200:
- ser.readline()
- newMillis = int(round(time.time() * 1000))
- f = open(filename, "w");
- while True:
- dataPoint = ser.readline()
- try:
- data = float(dataPoint)
- # Do whatever you want with the data point here
- f.write(str(data) + "\n")
- print data
- except ValueError:
- print "BAD_DATA"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement