Hydroponics

Copying one code from a Raspberry Pi to another. Trying to set up a second hydroponics system.

#!/usr/bin/env python

import RPi.GPIO
import time
import sys

# The Raspberry Pi pins used to control the power strips
setPin = 3

RPi.GPIO.setmode(RPi.GPIO.BCM)


runTime = int(sys.argv[1])

timeUnit = 'sec'

try:
    timeUnit = sys.argv[2]
    if timeUnit == 'min':
        runTime *= 60
except:
    print("")
    print('Defaulting time units to "sec" (other option: "min")')
    print('> ' + sys.argv[0] + ' sec')
    print("")

    
#Set up the pin as an output    
RPi.GPIO.setup(setPin, RPi.GPIO.OUT)


print('')
startTime = time.strftime('%a, %d %b %y: %H:%M:%S', time.localtime())
print("Start pump at:", startTime)

#Turn pin on
RPi.GPIO.output(setPin, True)
print('on')

for i in range(runTime):
    time.sleep(1)
    if i%10 == 0:
        print( '{t}/{n} sec. ({p:.1f}%)'.format(t=i, n=runTime, p=100.0*i/runTime) )

#Turn pin off
RPi.GPIO.output(setPin, False)
print('off')
endTime = time.strftime('%a, %d %b %y: %H:%M:%S', time.localtime())
print("End pumping at:", endTime)
The hydroponics system in the science lab.

Leave a Reply