From e2e2e0554ea84e97cc8738704e135078ff2f908e Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 5 Jan 2019 20:00:00 -0500 Subject: [PATCH] python serial read. --- code/python_serial/serial.pi | 35 ++++++++++++++++++++++++++ code/python_serial/temperaturedata.csv | 2 ++ 2 files changed, 37 insertions(+) create mode 100755 code/python_serial/serial.pi create mode 100644 code/python_serial/temperaturedata.csv diff --git a/code/python_serial/serial.pi b/code/python_serial/serial.pi new file mode 100755 index 0000000..1a8825d --- /dev/null +++ b/code/python_serial/serial.pi @@ -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" diff --git a/code/python_serial/temperaturedata.csv b/code/python_serial/temperaturedata.csv new file mode 100644 index 0000000..99c4cae --- /dev/null +++ b/code/python_serial/temperaturedata.csv @@ -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