Skip to content

Commit

Permalink
Merge branch 'master' of github.com:/aquarimeter/aquarimeter
Browse files Browse the repository at this point in the history
Conflicts:
	initialsetup.py
  • Loading branch information
robbyoconnor committed Dec 22, 2014
2 parents 4b4cf29 + 0cf89a4 commit eed8025
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 136 deletions.
41 changes: 27 additions & 14 deletions aquarimeter2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import time
import RPi.GPIO as GPIO
import picamera
import json
import requests
GPIO.setmode(GPIO.BCM)
DEBUG = 1

Expand All @@ -16,18 +18,29 @@
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'

auth_token = "whatever auth_token taken intial setup"
class aquarium(object):


def send_readings(self, ph, temp):
reading_data = {"auth_token":"HR6747C1iUM4XSRqKSsp",
"reading": {"ph":ph,
"temperature":temp}}
send_read = json.dumps(reading_data)
url = "url of site"
sent_data = requests.post(url, send_read)



#for reading from DS18B20 temperature connected to GPIO4
def read_temp_raw():
def read_temp_raw(self):
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines


# read SPI data from MCP3008 chip, 8 possible adc's (0 thru 7)
def readadc(adcnum, clockpin, mosipin, misopin, cspin):
def readadc(self,adcnum, clockpin, mosipin, misopin, cspin):
if ((adcnum > 7) or (adcnum < 0)):
return -1
GPIO.output(cspin, True)
Expand Down Expand Up @@ -62,25 +75,25 @@ def readadc(adcnum, clockpin, mosipin, misopin, cspin):
return adcout

#takes picture
def takePic():
def takePic(self):
with picamera.PiCamera() as camera:
camera.capture('/home/pi/Desktop/image.jpg')

#checks if anyhing is a good distance away to take a picture
def moveSens():
def moveSens(self):
pir_pot = readadc(pir_adc, SPICLK, SPIMOSI, SPIMISO, SPICS)
if pir_pot >150 and pir_pot < 650:
takePic()

#reads current ph
def readPh():
def readPh(self):
ph_pot = readadc(ph_adc, SPICLK, SPIMOSI, SPIMISO, SPICS)
ph_value = ph_pot*5/1024*3.5
return ph_value

#read temperature
def read_Temp():
lines = read_temp_raw()
def read_Temp(self):
lines = self.read_temp_raw()
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw()
Expand All @@ -93,21 +106,21 @@ def read_Temp():
return temp_f

# turn h bridge to heat
def heat_On():
def heat_On(self):
GPIO.output(A1, GPIO.HIGH)
GPIO.output(A2, GPIO.LOW)
GPIO.output(A3, GPIO.HIGH)
GPIO.output(A4, GPIO.LOW)

# turn h bridge to cool
def cool_On():
def cool_On(self):
GPIO.output(A1, GPIO.LOW)
GPIO.output(A2, GPIO.HIGH)
GPIO.output(A3, GPIO.LOW)
GPIO.output(A4, GPIO.HIGH)

#turn off any heating and cooling
def peltio_Off():
def peltio_Off(self):
GPIO.output(A1, GPIO.LOW)
GPIO.output(A2, GPIO.LOW)
GPIO.output(A3, GPIO.LOW)
Expand Down Expand Up @@ -140,14 +153,14 @@ def peltio_Off():


#set up values
ph_adc = 0;
ph_adc = 2;
pir_adc = 1;
ideal_temp = 75;
max_temp = 80;
min_temp = 70;
heat = False;
cool = False;

aqua = aquarium()
while True:
# read the analog pin for ph
ph_value = aqua.readPh()
Expand All @@ -157,7 +170,7 @@ def peltio_Off():

#read temp
temp_f = aqua.read_temp()
aqua.send_readings(ph_value, temp_f)
if temp_f < min_temp:
heat = True
#turn h bridge to heat
Expand Down
Loading

0 comments on commit eed8025

Please sign in to comment.