Your Name 5 years ago
parent
commit
03dc935e22
2 changed files with 37 additions and 0 deletions
  1. +35
    -0
      code/python_serial/serial.pi
  2. +2
    -0
      code/python_serial/temperaturedata.csv

+ 35
- 0
code/python_serial/serial.pi View File

@ -0,0 +1,35 @@
#!/usr/bin/python
'''
Original data collection script by Ben Kenney - July 2012
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:
"value1,value2"
It assumes that the Arduino shows up in /dev/ttyACM0 on the Raspberry Pi which should happen if you're using Debian.
'''
import serial
from time import strftime
from datetime import datetime, time
ser = serial.Serial('/dev/ttyACM0',9600)
startTime = datetime.now()
try:
while 1:
line=ser.readline().rstrip()
# temp,outsidetemp=line.split(",")
# we have more data.
# I don't know what they are yet...
read1,read2,read3=line.split(",");
now = datetime.now()
elapsedTime = now-startTime
elapsedSeconds = (elapsedTime.microseconds+(elapsedTime.days*24*3600+elapsedTime.seconds)*10**6)/10**6
#this is the original
#
# f=open('/home/pi/sensors/sensordata/temperaturedata.csv','a')
#
f=open('./temperaturedata.csv','a')
print >>f,("%s,%s,%s,%s,%s"%(now.strftime("%Y-%m-%d %H:%M:%S"),elapsedSeconds,read1,read2,read3))
f.close()
except KeyboardInterrupt:
print "\ndone"

+ 2
- 0
code/python_serial/temperaturedata.csv View File

@ -0,0 +1,2 @@
2019-01-05 19:59:18,27,112105,0.37,194.46
2019-01-05 19:59:48,58,104586,0.35,181.49

Loading…
Cancel
Save