You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.2 KiB

5 years ago
  1. #!/usr/bin/python
  2. '''
  3. Original data collection script by Ben Kenney - July 2012
  4. This program reads data coming from the serial port and saves that data to a text file. It expects data in the following format with a comma (,) as a separator:
  5. "value1,value2"
  6. It assumes that the Arduino shows up in /dev/ttyACM0 on the Raspberry Pi which should happen if you're using Debian.
  7. '''
  8. import serial
  9. from time import strftime
  10. from datetime import datetime, time
  11. ser = serial.Serial('/dev/ttyACM0',9600)
  12. startTime = datetime.now()
  13. try:
  14. while 1:
  15. line=ser.readline().rstrip()
  16. # temp,outsidetemp=line.split(",")
  17. # we have more data.
  18. # I don't know what they are yet...
  19. read1,read2,read3=line.split(",");
  20. now = datetime.now()
  21. elapsedTime = now-startTime
  22. elapsedSeconds = (elapsedTime.microseconds+(elapsedTime.days*24*3600+elapsedTime.seconds)*10**6)/10**6
  23. #this is the original
  24. #
  25. # f=open('/home/pi/sensors/sensordata/temperaturedata.csv','a')
  26. #
  27. f=open('./temperaturedata.csv','a')
  28. print >>f,("%s,%s,%s,%s,%s"%(now.strftime("%Y-%m-%d %H:%M:%S"),elapsedSeconds,read1,read2,read3))
  29. f.close()
  30. except KeyboardInterrupt:
  31. print "\ndone"