Hi, Thanks for getting back to me.
I've decided to go down the python + gnuplot route.
Below is the code ive written.
Im still waiting for my Pi to test it on, but if you could have a quick scan and see if it looks correct I would be grateful.
Because I cannot work out how to get gnuplot to open the most recent file created i have (i think) made the program output my data as two files - gnu.log and tempTIMESTAMP.log - temp will be kept and gnu.log will be overwritten constantly.
I have then got gnuplot to open the gnu.log file, output the data to gnu.png and then called the original python script to copy this file to graphTIMSTAMP.png so that the time stamps match and it can make new graphs without overwriting the original data...
Or at least that the plan.
Again, any advice would we heard gratefully,
Steve
Python:
Code: Select all
# Copyright (c) 2012 Matthew Kirk
# Licensed under MIT License, see
# http://www.cl.cam.ac.uk/freshers/raspberrypi/tutorials/temperature/LICENSE
import RPi.GPIO as GPIO
import time
LED1_GPIO_PIN = 18
LED2_GPIO_PIN = 25
BUTTON_GPIO_PIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON_GPIO_PIN, GPIO.IN)
GPIO.setup(LED1_GPIO_PIN, GPIO.OUT)
GPIO.setup(LED2_GPIO_PIN, GPIO.OUT)
GPIO.output(LED1_GPIO_PIN, GPIO.HIGH)
while True:
if GPIO.input(BUTTON_GPIO_PIN):
break
while GPIO.input(BUTTON_GPIO_PIN):
pass
GPIO.output(LED1_GPIO_PIN, GPIO.LOW)
GPIO.output(LED2_GPIO_PIN, GPIO.HIGH)
timestamp = time.strftime("%Y-%m-%d-%H-%M-%S")
prog_start = time.time()
filename = "".join(["temperaturedata", timestamp, ".log"])
image = "".join(["graph", timestamp, ".png"])
datafile = open(filename, "w", 1)
gnu = open("gnu.log", "w", 1)
measurement_wait = 15
button_pressed = False
while True:
time_1 = time.time()
tfile = open("/sys/bus/w1/devices/10-000802824e58/w1_slave")
text = tfile.read()
tfile.close()
temperature_data = text.split()[-1]
temperature = float(temperature_data[2:])
temperature = temperature / 1000
datafile.write(str(time.time()-prog_start) + "\t" + str(temperature) + "\n")
gnu.write(str(time.time()-prog_start) + "\t" + str(temperature) + "\n")
time_2 = time.time()
if (time_2 - time_1) < measurement_wait:
no_of_sleeps = int(round((measurement_wait - (time_2 - time_1)) / 0.1))
for i in range(no_of_sleeps):
time.sleep(0.1)
if GPIO.input(BUTTON_GPIO_PIN):
button_pressed = True
break
if button_pressed:
break
datafile.close()
gnu.close()
import os
os.system("gnuplot temp.plt")
import shutil
shutil.copy(gnu.png, image)
GPIO.output(LED2_GPIO_PIN, GPIO.LOW)
GNUplot:
Code: Select all
set terminal png small size 900, 968 transparent# x000000
set output "gnu.png"
set time
set y2tics
set timestamp "%a %b %Y %H:%M:%S" bottom
set title "Temperature Profile" # 0.000000,0.000000 "";
set ylabel "Degrees Centigrade" # 0.000000,0.000000 ""
set xlabel "Time (seconds)"
set key below
plot 'gnu.log' using 1:2 with linespoints,\
set output