SHARE
TWEET

pyElectrometer

a guest Mar 19th, 2016 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import serial
  2. import platform
  3. import glob
  4. import time
  5.  
  6. filename = "Electrometer " + str(int(time.time())) + ".txt"
  7.  
  8. print "617 Programmable Electrometer Reader"
  9. print "(C) 2016 Daniel Centore"
  10. print ""
  11. print "Instructions (Windows):"
  12. print " * Find the Arduino COM port using device manager"
  13. print " * Type the COM port in below (ex COM6)"
  14. print ""
  15. print "Instructions (Linux)"
  16. print " * Find the Arduino port by using ls in /dev/"
  17. print " * Type the full port name below (ex /dev/ttyACM4)"
  18. print ""
  19. print "Instructions (All)"
  20. print " * File data will appear in the file \"" + filename + "\""
  21. print " * Press Ctrl+C to quit data collection"
  22. print ""
  23.  
  24. port = raw_input("Pick a port: ")
  25. ser = serial.Serial(port, 9600)
  26.  
  27. # Discard the early data
  28. millis = int(round(time.time() * 1000))
  29. newMillis = int(round(time.time() * 1000))
  30. while newMillis < millis + 200:
  31.     ser.readline()
  32.     newMillis = int(round(time.time() * 1000))
  33.  
  34. f = open(filename, "w");
  35.  
  36. while True:
  37.     dataPoint = ser.readline()
  38.     try:
  39.         data = float(dataPoint)
  40.  
  41.         # Do whatever you want with the data point here
  42.         f.write(str(data) + "\n")
  43.         print data
  44.  
  45.     except ValueError:
  46.         print "BAD_DATA"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top