Pioneers Project Autumn 2017

So my Pioneers have worked very hard on their project.  I have been trying to mentor rather than teach, guiding them in the right direction and offering support (but not the answers) when they needed it.  As a result the project did not get as far as I would have liked but they did it themselves, with the exception if the twitter API.

The lads have put together a really good piece of kit that with afew slight alterations I will be using to water my herbs in the kitchen, which never last more than a month because I forget to water them.

Please enjoy our video and the code for the project is attatched below.

#Water Sensor Python code 

import sys
 import time
 import RPi.GPIO as GPIO

# Use BCM GPIO references
 GPIO.setmode(GPIO.BCM)

StepPinForward=20
StepPinBackward=21
StepPinForward2=23
StepPinBackward2=24
GPIO.setup(StepPinForward, GPIO.OUT)
GPIO.setup(StepPinBackward, GPIO.OUT)

GPIO.setup(StepPinForward2, GPIO.OUT)
 GPIO.setup(StepPinBackward2, GPIO.OUT)
 import time
 import Adafruit_ADS1x15
 adc = Adafruit_ADS1x15.ADS1015()
 GAIN = 1

while True:
 print ("left " + str(adc.read_adc(0, gain=GAIN)))
 WaterSonsor= (adc.read_adc(0, gain=GAIN))
 if WaterSonsor<650:
    print ("switch motor on")
    GPIO.output(StepPinForward, GPIO.HIGH)

    while WaterSonsor<680:
       WaterSonsor= (adc.read_adc(0, gain=GAIN))
       print (adc.read_adc(0, gain=GAIN))
       time.sleep(0.5)
    print ("switch moter off")
    GPIO.output(StepPinForward, GPIO.LOW)

 print ("right" + str (adc.read_adc(1, gain=GAIN)))
 WaterSonsor2= (adc.read_adc(1, gain=GAIN))
 if WaterSonsor2<770:
     print ("switch motor on")
     GPIO.output(StepPinForward2, GPIO.HIGH)

     while WaterSonsor2<400:
        WaterSonsor2= (adc.read_adc(1, gain=GAIN))
        print (adc.read_adc(1, gain=GAIN))
        time.sleep(0.5)
     print ("switch moter off")
     GPIO.output(StepPinForward2, GPIO.LOW)
#Camera post to twitter Python code 
import sys
 from twython import Twython
 CONSUMER_KEY = 'KEY'
 CONSUMER_SECRET = 'SECRET'
 ACCESS_KEY = 'KEY'
 ACCESS_SECRET = 'SECRET'

twitter = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)

import RPi.GPIO as GPIO
import time
import picamera
import sys

camera = picamera.PiCamera()
time.sleep(1)
camera.vflip =True
camera.hflip=True

timestr = time.strftime("%Y%m%d-%H%M%S")
camera.capture(timestr +'.jpg')

camera.capture("tweet.jpg")
photo = open('tweet.jpg','rb')
response = twitter.upload_media(media=photo)
twitter.update_status(status='How are the crops geting on? We all have to eat in an apocalypse \#raspberrypioneers', media_ids=[response['media_id']])

quit()