#!/usr/bin/python #Based off the tutorial by adafruit here: # http://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/software import subprocess import glob import time import RPi.GPIO as GPIO import serial import re HEATER_PIN = 22 PUMP_PIN = 24 def getTempStr(tempStrFile): fin = open(tempStrFile) contents = fin.read() fin.close() return contents def DecideHeater(): GPIO.setmode(GPIO.BCM) GPIO.setup(HEATER_PIN, GPIO.OUT) GPIO.setup(PUMP_PIN, GPIO.OUT) htrStatus = getTempStr('/home/pi/mytherm/heaterStatus.txt') if (htrStatus == 'ON'): GPIO.output(HEATER_PIN, False) elif (htrStatus == 'OFF'): GPIO.output(HEATER_PIN, True) def DecidePump(): GPIO.setmode(GPIO.BCM) GPIO.setup(HEATER_PIN, GPIO.OUT) GPIO.setup(PUMP_PIN, GPIO.OUT) currentTemp = float(getTempStr('/home/pi/mytherm/temp.txt')) setPoint = float(getTempStr('/home/pi/mytherm/setTemp.txt')) if (currentTemp > setPoint): temp_file = open('/home/pi/mytherm/pumpStatus.txt', 'w') temp_file.write('OFF') temp_file.close() GPIO.output(PUMP_PIN, True) elif (currentTemp < (setPoint - 1)): GPIO.output(PUMP_PIN, False) temp_file = open('/home/pi/mytherm/pumpStatus.txt', 'w') temp_file.write('ON') temp_file.close() GPIO.setmode(GPIO.BCM) GPIO.setup(HEATER_PIN, GPIO.OUT) GPIO.setup(PUMP_PIN, GPIO.OUT) GPIO.output(HEATER_PIN, True) GPIO.output(PUMP_PIN, True) while True : DecideHeater() DecidePump() time.sleep(5)