Compare commits
15 Commits
01501e0122
...
b1782a703c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1782a703c | ||
|
|
befdbb89fb | ||
|
|
b12e78d6e6 | ||
|
|
7bbdbc8998 | ||
|
|
dbbf6f7b42 | ||
|
|
9275f3a5a3 | ||
|
|
065413bcd0 | ||
|
|
4970653c0c | ||
|
|
5619ac4e17 | ||
|
|
07083c6e71 | ||
|
|
974a914282 | ||
|
|
0a0a94ba51 | ||
|
|
ab811ae31b | ||
|
|
0f142124a8 | ||
|
|
879a21445d |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -138,3 +138,5 @@ dmypy.json
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# Secrets
|
||||
.creds*
|
||||
|
||||
13
README.md
13
README.md
@@ -1,3 +1,14 @@
|
||||
# garden
|
||||
|
||||
Python project for building an indoor garden with the Setlock ladies.
|
||||
Python project for building an indoor garden with the Setlock ladies.
|
||||
|
||||
## BCM Pin Assignments
|
||||
|
||||
| BCM Number | Device | Function |
|
||||
|------------|--------|----------|
|
||||
| 4 | Green Pushbutton | Sequence Start |
|
||||
| 27 | Yellow Pushbutton | Lamp |
|
||||
| 13 | Blue Pushbutton | Water Pump |
|
||||
| 26 | Relay 1 | N.O. Pump |
|
||||
| 20 | Relay 2 | *Unassigned* |
|
||||
| 21 | Relay 3 | N.O. Lamp |
|
||||
33
automatic/input.py
Normal file
33
automatic/input.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#! env/bin/python3
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
def get_pin_input():
|
||||
|
||||
# Pin Assignments
|
||||
PB1_BCM = 4 # Green
|
||||
PB2_BCM = 27 # Yellow
|
||||
PB3_BCM = 13 # Blue
|
||||
RELAY1_PIN = 26 # Water Pump
|
||||
RELAY2_PIN = 20 # Unassigned
|
||||
RELAY3_PIN = 21 # Lamp
|
||||
|
||||
# Get current time.
|
||||
now = datetime.now()
|
||||
hour = now.hour
|
||||
minute = now.minute
|
||||
|
||||
# Define alias variables for input devices.
|
||||
inputs = {
|
||||
'green_button' : GPIO.input(PB1_BCM),
|
||||
'yellow_button' : GPIO.input(PB2_BCM),
|
||||
'blue_button' : GPIO.input(PB3_BCM),
|
||||
'pump' : GPIO.input(RELAY1_PIN),
|
||||
'lamp' : GPIO.input(RELAY3_PIN),
|
||||
'hour' : hour,
|
||||
'minute' : minute,
|
||||
}
|
||||
|
||||
return inputs
|
||||
20
automatic/output.py
Normal file
20
automatic/output.py
Normal file
@@ -0,0 +1,20 @@
|
||||
#! env/bin/python3
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
def write_pin_output(outputs):
|
||||
|
||||
# Setup for Hardware
|
||||
RELAY1_PIN = 26 # Water Pump
|
||||
RELAY2_PIN = 20 # Unassigned
|
||||
RELAY3_PIN = 21 # Lamp
|
||||
|
||||
# Write outputs.
|
||||
if outputs['detect']:
|
||||
time.sleep(1.0)
|
||||
|
||||
GPIO.output(RELAY1_PIN, outputs['pump'])
|
||||
GPIO.output(RELAY2_PIN, False)
|
||||
GPIO.output(RELAY3_PIN, outputs['lamp'])
|
||||
69
automatic/routine.py
Normal file
69
automatic/routine.py
Normal file
@@ -0,0 +1,69 @@
|
||||
#! env/bin/python3
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
from input import get_pin_input
|
||||
from state_trans import check_state
|
||||
from output import write_pin_output
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
|
||||
# Pin Assignments
|
||||
PB1_BCM = 4 # Green
|
||||
PB2_BCM = 27 # Yellow
|
||||
PB3_BCM = 13 # Blue
|
||||
RELAY1_PIN = 26 # Water Pump
|
||||
RELAY2_PIN = 20 # Unassigned
|
||||
RELAY3_PIN = 21 # Lamp
|
||||
|
||||
# Setup the Inputs to use the internal pull-down.
|
||||
GPIO.setup(PB1_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(PB2_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(PB3_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
|
||||
# Setup the Outputs.
|
||||
GPIO.setup(RELAY1_PIN, GPIO.OUT)
|
||||
GPIO.setup(RELAY2_PIN, GPIO.OUT)
|
||||
GPIO.setup(RELAY3_PIN, GPIO.OUT)
|
||||
|
||||
try:
|
||||
|
||||
auto_mode = False
|
||||
|
||||
while True:
|
||||
|
||||
# Detect user input.
|
||||
inputs = get_pin_input()
|
||||
|
||||
# Activate auto mode if the Green PB is pressed.
|
||||
if auto_mode or inputs['green_button'] == True:
|
||||
|
||||
inputs['mode'] = "AUTO"
|
||||
auto_mode = True
|
||||
|
||||
# Activate manual mode if the Yellow or Blue PB's are pressed.
|
||||
if not auto_mode or inputs['yellow_button'] == True or inputs['blue_button'] == True:
|
||||
|
||||
inputs['mode'] = "MANUAL"
|
||||
auto_mode = False
|
||||
|
||||
# Make any transitions based on mode and inputs.
|
||||
outputs = check_state(inputs)
|
||||
|
||||
# Write the outputs which correspond to the desired state.
|
||||
write_pin_output(outputs)
|
||||
|
||||
# Avoid maxxing out a single thread.
|
||||
time.sleep(0.1)
|
||||
|
||||
# Cleanup on Exit.
|
||||
finally:
|
||||
GPIO.output(RELAY1_PIN, False)
|
||||
GPIO.output(RELAY2_PIN, False)
|
||||
GPIO.output(RELAY3_PIN, False)
|
||||
GPIO.cleanup()
|
||||
|
||||
68
automatic/state_trans.py
Normal file
68
automatic/state_trans.py
Normal file
@@ -0,0 +1,68 @@
|
||||
#! env/bin/python3
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
def check_state(inputs):
|
||||
|
||||
# Define alias variables for input devices.
|
||||
green_button = inputs['green_button']
|
||||
yellow_button = inputs['yellow_button']
|
||||
blue_button = inputs['blue_button']
|
||||
|
||||
# Define state variables for each of the output devices.
|
||||
pump_state = inputs['pump']
|
||||
lamp_state = inputs['lamp']
|
||||
|
||||
# Get mode and schedule information.
|
||||
mode = inputs['mode']
|
||||
hour = inputs['hour']
|
||||
minute = inputs['minute']
|
||||
|
||||
# Determine state.
|
||||
|
||||
# Assume no change in state.
|
||||
pump_out = pump_state
|
||||
lamp_out = lamp_state
|
||||
|
||||
# Automatic mode.
|
||||
if mode == "AUTO":
|
||||
|
||||
detect = False
|
||||
|
||||
if 6 < hour < 22:
|
||||
lamp_out = True
|
||||
pump_out = True
|
||||
else:
|
||||
lamp_out = False
|
||||
pump_out = False
|
||||
|
||||
# Manual mode.
|
||||
if mode == "MANUAL":
|
||||
|
||||
detect = False
|
||||
|
||||
# Pump Flip-Flop
|
||||
if not detect and blue_button and pump_state:
|
||||
pump_out = False
|
||||
detect = True
|
||||
if not detect and blue_button and not pump_state:
|
||||
pump_out = True
|
||||
detect = True
|
||||
# Lamp Flip-Flop
|
||||
if not detect and yellow_button and lamp_state:
|
||||
lamp_out = False
|
||||
detect = True
|
||||
if not detect and yellow_button and not lamp_state:
|
||||
lamp_out = True
|
||||
detect = True
|
||||
|
||||
# Define alias variables for input devices.
|
||||
outputs = {
|
||||
'detect' : detect,
|
||||
'pump' : pump_out,
|
||||
'lamp' : lamp_out,
|
||||
}
|
||||
|
||||
return outputs
|
||||
73
db_tools/db_writer.py
Normal file
73
db_tools/db_writer.py
Normal file
@@ -0,0 +1,73 @@
|
||||
#! env/bin/python3
|
||||
|
||||
# import the psycopg2 database adapter for PostgreSQL
|
||||
import psycopg2
|
||||
from psycopg2.extras import Json
|
||||
import json
|
||||
import sys
|
||||
|
||||
def connect_db(db: str,host: str,user: str,passwd: str):
|
||||
try:
|
||||
# declare a new PostgreSQL connection object
|
||||
conn = psycopg2.connect(
|
||||
dbname = db,
|
||||
user = user,
|
||||
host = host,
|
||||
password = passwd,
|
||||
# attempt to connect for 3 seconds then raise exception
|
||||
connect_timeout = 3
|
||||
)
|
||||
|
||||
except (Exception, psycopg2.Error) as err:
|
||||
#print ("\npsycopg2 connect error:", err)
|
||||
conn = None
|
||||
return conn
|
||||
|
||||
def get_db_creds(file: str):
|
||||
with open(file) as cred_file:
|
||||
creds = json.load(cred_file)
|
||||
return creds
|
||||
|
||||
def insert_data(conn, data):
|
||||
|
||||
# insert a new vendor into the vendors table
|
||||
sql = """
|
||||
INSERT INTO
|
||||
air(datetime, temperature, humidity)
|
||||
VALUES
|
||||
(%s, %s, %s)
|
||||
"""
|
||||
|
||||
try:
|
||||
# open cursor on our db connection
|
||||
cur = conn.cursor()
|
||||
|
||||
# execute the INSERT statement
|
||||
data = (data["datetime"], data["temperature"], data["humidity"])
|
||||
cur.execute(sql,data)
|
||||
|
||||
# commit the changes to the database
|
||||
conn.commit()
|
||||
|
||||
# close communication with the database
|
||||
cur.close()
|
||||
|
||||
except (Exception, psycopg2.DatabaseError) as error:
|
||||
print(error)
|
||||
|
||||
finally:
|
||||
if conn is not None:
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
data = {
|
||||
"datetime": "2021-10-23 01:58:08.205911",
|
||||
"temperature": "73.4",
|
||||
"humidity": "49.2"
|
||||
}
|
||||
|
||||
creds = get_db_creds("./.creds.json")
|
||||
|
||||
conn = connect_db(creds["db"], creds["host"], creds["user"], creds["passwd"])
|
||||
|
||||
insert_data(conn, data)
|
||||
548
dht22/log.csv
Normal file
548
dht22/log.csv
Normal file
@@ -0,0 +1,548 @@
|
||||
10/18/21 15:52:11,48.10,73.94
|
||||
10/18/21 15:52:27,48.30,73.76
|
||||
10/18/21 15:52:42,48.30,73.76
|
||||
10/18/21 15:52:57,48.30,73.76
|
||||
10/18/21 15:53:12,48.30,73.76
|
||||
10/18/21 15:53:27,48.30,73.94
|
||||
10/18/21 15:53:42,48.30,73.76
|
||||
10/18/21 15:53:58,48.30,73.76
|
||||
10/18/21 15:54:13,48.30,73.76
|
||||
10/18/21 15:54:28,48.30,73.76
|
||||
10/18/21 15:54:43,48.30,73.76
|
||||
10/18/21 15:54:58,48.40,73.76
|
||||
10/18/21 15:55:13,48.30,73.76
|
||||
10/18/21 15:55:29,48.30,73.76
|
||||
10/18/21 15:55:44,48.40,73.76
|
||||
10/18/21 15:55:59,48.40,73.76
|
||||
10/18/21 15:56:14,48.30,73.76
|
||||
10/18/21 15:56:29,48.30,73.76
|
||||
10/18/21 15:56:44,48.30,73.76
|
||||
10/18/21 15:57:00,48.30,73.76
|
||||
10/18/21 15:57:15,48.30,73.76
|
||||
10/18/21 15:57:30,48.40,73.76
|
||||
10/18/21 15:57:45,48.40,73.76
|
||||
10/18/21 15:58:00,48.40,73.76
|
||||
10/18/21 15:58:16,48.40,73.76
|
||||
10/18/21 15:58:31,48.30,73.76
|
||||
10/18/21 15:58:46,48.30,73.76
|
||||
10/18/21 15:59:01,48.30,73.76
|
||||
10/18/21 15:59:16,48.20,73.76
|
||||
10/18/21 15:59:31,48.20,73.76
|
||||
10/18/21 15:59:47,48.20,73.76
|
||||
10/18/21 16:00:02,48.10,73.94
|
||||
10/18/21 16:00:17,48.10,73.94
|
||||
10/18/21 16:00:32,48.20,73.94
|
||||
10/18/21 16:00:48,48.10,73.94
|
||||
10/18/21 16:01:03,48.10,73.94
|
||||
10/18/21 16:01:18,48.20,73.94
|
||||
10/18/21 16:01:33,48.00,73.94
|
||||
10/18/21 16:01:48,48.00,73.94
|
||||
10/18/21 16:02:03,48.00,73.94
|
||||
10/18/21 16:02:19,48.10,73.94
|
||||
10/18/21 16:02:34,48.10,73.94
|
||||
10/18/21 16:02:49,48.10,73.94
|
||||
10/18/21 16:03:04,48.00,73.94
|
||||
10/18/21 16:03:19,47.90,73.94
|
||||
10/18/21 16:03:35,48.00,73.94
|
||||
10/18/21 16:03:50,48.00,73.76
|
||||
10/18/21 16:04:05,47.90,73.76
|
||||
10/18/21 16:04:20,48.00,73.76
|
||||
10/18/21 16:04:35,48.00,73.76
|
||||
10/18/21 16:04:50,48.00,73.76
|
||||
10/18/21 16:05:06,48.00,73.76
|
||||
10/18/21 16:05:21,48.00,73.76
|
||||
10/18/21 16:05:36,48.00,73.76
|
||||
10/18/21 16:05:51,48.00,73.76
|
||||
10/18/21 16:06:06,48.00,73.76
|
||||
10/18/21 16:06:21,48.00,73.76
|
||||
10/18/21 16:06:37,47.90,73.76
|
||||
10/18/21 16:06:52,48.00,73.76
|
||||
10/18/21 16:07:07,48.00,73.76
|
||||
10/18/21 16:07:22,47.90,73.76
|
||||
10/18/21 16:07:37,47.90,73.76
|
||||
10/18/21 16:07:53,47.90,73.76
|
||||
10/18/21 16:08:08,47.90,73.76
|
||||
10/18/21 16:08:23,48.00,73.76
|
||||
10/18/21 16:08:38,47.90,73.76
|
||||
10/18/21 16:08:53,47.90,73.76
|
||||
10/18/21 16:09:08,47.90,73.76
|
||||
10/18/21 16:09:24,47.90,73.76
|
||||
10/18/21 16:09:39,48.00,73.76
|
||||
10/18/21 16:09:54,47.90,73.76
|
||||
10/18/21 16:10:09,48.00,73.76
|
||||
10/18/21 16:10:24,48.00,73.76
|
||||
10/18/21 16:10:40,48.00,73.76
|
||||
10/18/21 16:10:55,48.00,73.76
|
||||
10/18/21 16:11:10,47.90,73.76
|
||||
10/18/21 16:11:25,47.90,73.76
|
||||
10/18/21 16:11:40,47.90,73.76
|
||||
10/18/21 16:11:56,47.90,73.76
|
||||
10/18/21 16:12:11,48.00,73.76
|
||||
10/18/21 16:12:26,48.00,73.76
|
||||
10/18/21 16:12:41,47.90,73.76
|
||||
10/18/21 16:12:56,47.90,73.76
|
||||
10/18/21 16:13:11,47.90,73.76
|
||||
10/18/21 16:13:27,48.00,73.76
|
||||
10/18/21 16:13:42,48.00,73.76
|
||||
10/18/21 16:13:57,48.00,73.76
|
||||
10/18/21 16:14:12,48.00,73.76
|
||||
10/18/21 16:14:27,47.90,73.76
|
||||
10/18/21 16:14:42,48.00,73.76
|
||||
10/18/21 16:14:58,48.00,73.76
|
||||
10/18/21 16:15:13,48.10,73.58
|
||||
10/18/21 16:15:28,48.20,73.76
|
||||
10/18/21 16:15:43,48.30,73.58
|
||||
10/18/21 16:15:58,48.30,73.58
|
||||
10/18/21 16:16:13,48.40,73.58
|
||||
10/18/21 16:16:29,48.40,73.58
|
||||
10/18/21 16:16:44,48.40,73.58
|
||||
10/18/21 16:16:59,48.30,73.58
|
||||
10/18/21 16:17:14,48.30,73.58
|
||||
10/18/21 16:17:29,48.40,73.58
|
||||
10/18/21 16:17:45,48.40,73.58
|
||||
10/18/21 16:18:00,48.40,73.58
|
||||
10/18/21 16:18:15,48.40,73.58
|
||||
10/18/21 16:18:30,48.40,73.58
|
||||
10/18/21 16:18:45,48.40,73.58
|
||||
10/18/21 16:19:00,48.40,73.58
|
||||
10/18/21 16:19:16,48.50,73.58
|
||||
10/18/21 16:19:31,48.50,73.58
|
||||
10/18/21 16:19:46,48.50,73.58
|
||||
10/18/21 16:20:01,48.50,73.58
|
||||
10/18/21 16:20:16,48.50,73.58
|
||||
10/18/21 16:20:32,48.50,73.58
|
||||
10/18/21 16:20:47,48.50,73.58
|
||||
10/18/21 16:21:02,48.50,73.58
|
||||
10/18/21 16:21:17,48.50,73.58
|
||||
10/18/21 16:21:32,48.60,73.58
|
||||
10/18/21 16:21:47,48.50,73.58
|
||||
10/18/21 16:22:03,48.50,73.58
|
||||
10/18/21 16:22:18,48.60,73.58
|
||||
10/18/21 16:22:33,48.60,73.58
|
||||
10/18/21 16:22:48,48.50,73.40
|
||||
10/18/21 16:23:03,48.60,73.40
|
||||
10/18/21 16:23:18,48.60,73.40
|
||||
10/18/21 16:23:34,48.60,73.40
|
||||
10/18/21 16:23:49,48.60,73.40
|
||||
10/18/21 16:24:04,48.60,73.58
|
||||
10/18/21 16:24:19,48.60,73.40
|
||||
10/18/21 16:24:34,48.70,73.40
|
||||
10/18/21 16:24:50,48.60,73.40
|
||||
10/18/21 16:25:05,48.70,73.40
|
||||
10/18/21 16:25:20,48.60,73.40
|
||||
10/18/21 16:25:35,48.60,73.40
|
||||
10/18/21 16:25:50,48.70,73.40
|
||||
10/18/21 16:26:05,48.70,73.40
|
||||
10/18/21 16:26:21,48.70,73.40
|
||||
10/18/21 16:26:36,48.60,73.40
|
||||
10/18/21 16:26:51,48.60,73.40
|
||||
10/18/21 16:27:06,48.80,73.40
|
||||
10/18/21 16:27:21,48.60,73.40
|
||||
10/18/21 16:27:36,48.70,73.40
|
||||
10/18/21 16:27:52,48.70,73.40
|
||||
10/18/21 16:28:07,48.70,73.40
|
||||
10/18/21 16:28:22,48.60,73.40
|
||||
10/18/21 16:28:37,48.50,73.40
|
||||
10/18/21 16:28:52,48.50,73.40
|
||||
10/18/21 16:29:08,48.50,73.40
|
||||
10/18/21 16:29:23,48.50,73.40
|
||||
10/18/21 16:29:38,48.40,73.58
|
||||
10/18/21 16:29:53,48.30,73.40
|
||||
10/18/21 16:30:08,48.30,73.40
|
||||
10/18/21 16:30:23,48.30,73.58
|
||||
10/18/21 16:30:39,48.30,73.58
|
||||
10/18/21 16:30:54,48.30,73.58
|
||||
10/18/21 16:31:09,48.20,73.58
|
||||
10/18/21 16:31:24,48.20,73.58
|
||||
10/18/21 16:31:39,48.20,73.58
|
||||
10/18/21 16:31:55,48.20,73.58
|
||||
10/18/21 16:32:10,48.20,73.58
|
||||
10/18/21 16:32:25,48.20,73.58
|
||||
10/18/21 16:32:40,48.10,73.58
|
||||
10/18/21 16:32:55,48.20,73.58
|
||||
10/18/21 16:33:10,48.10,73.58
|
||||
10/18/21 16:33:26,48.10,73.58
|
||||
10/18/21 16:33:41,48.10,73.58
|
||||
10/18/21 16:33:56,48.20,73.58
|
||||
10/18/21 16:34:11,48.10,73.58
|
||||
10/18/21 16:34:26,48.20,73.58
|
||||
10/18/21 16:34:41,48.10,73.58
|
||||
10/18/21 16:34:57,48.10,73.58
|
||||
10/18/21 16:35:12,48.10,73.58
|
||||
10/18/21 16:35:27,48.10,73.58
|
||||
10/18/21 16:35:42,48.10,73.58
|
||||
10/18/21 16:35:57,48.10,73.58
|
||||
10/18/21 16:36:12,48.10,73.58
|
||||
10/18/21 16:36:28,48.20,73.58
|
||||
10/18/21 16:36:43,48.10,73.58
|
||||
10/18/21 16:36:58,48.20,73.58
|
||||
10/18/21 16:37:13,48.10,73.58
|
||||
10/18/21 16:37:28,48.10,73.58
|
||||
10/18/21 16:37:43,48.10,73.58
|
||||
10/18/21 16:37:59,48.10,73.58
|
||||
10/18/21 16:38:14,48.10,73.58
|
||||
10/18/21 16:38:29,48.00,73.40
|
||||
10/18/21 16:38:44,48.10,73.58
|
||||
10/18/21 16:38:59,48.10,73.58
|
||||
10/18/21 16:39:14,48.10,73.58
|
||||
10/18/21 16:39:30,48.10,73.40
|
||||
10/18/21 16:39:45,48.10,73.40
|
||||
10/18/21 16:40:00,48.10,73.40
|
||||
10/18/21 16:40:15,48.10,73.58
|
||||
10/18/21 16:40:30,48.10,73.40
|
||||
10/18/21 16:40:45,48.10,73.40
|
||||
10/18/21 16:41:01,48.10,73.40
|
||||
10/18/21 16:41:16,48.10,73.40
|
||||
10/18/21 16:41:31,48.10,73.58
|
||||
10/18/21 16:41:46,48.00,73.40
|
||||
10/18/21 16:42:01,48.00,73.40
|
||||
10/18/21 16:42:17,48.00,73.58
|
||||
10/18/21 16:42:32,48.00,73.58
|
||||
10/18/21 16:42:47,47.90,73.40
|
||||
10/18/21 16:43:02,48.00,73.40
|
||||
10/18/21 16:43:17,48.00,73.58
|
||||
10/18/21 16:43:32,48.00,73.40
|
||||
10/18/21 16:43:48,48.00,73.58
|
||||
10/18/21 16:44:03,48.00,73.40
|
||||
10/18/21 16:44:18,48.00,73.40
|
||||
10/18/21 16:44:33,48.00,73.40
|
||||
10/18/21 16:44:48,48.00,73.58
|
||||
10/18/21 16:45:03,48.00,73.40
|
||||
10/18/21 16:45:19,48.00,73.40
|
||||
10/18/21 16:45:34,48.10,73.40
|
||||
10/18/21 16:45:49,48.20,73.40
|
||||
10/18/21 16:46:04,48.20,73.40
|
||||
10/18/21 16:46:19,48.30,73.40
|
||||
10/18/21 16:46:34,48.40,73.40
|
||||
10/18/21 16:46:50,48.30,73.40
|
||||
10/18/21 16:47:05,48.40,73.40
|
||||
10/18/21 16:47:20,48.40,73.40
|
||||
10/18/21 16:47:35,48.40,73.40
|
||||
10/18/21 16:47:50,48.50,73.40
|
||||
10/18/21 16:48:05,48.40,73.40
|
||||
10/18/21 16:48:21,48.40,73.40
|
||||
10/18/21 16:48:36,48.30,73.40
|
||||
10/18/21 16:48:51,48.50,73.40
|
||||
10/18/21 16:49:06,48.40,73.40
|
||||
10/18/21 16:49:21,48.60,73.40
|
||||
10/18/21 16:49:36,48.80,73.40
|
||||
10/18/21 16:49:52,48.90,73.40
|
||||
10/18/21 16:50:07,49.10,73.40
|
||||
10/18/21 16:50:22,49.40,73.40
|
||||
10/18/21 16:50:37,49.70,73.40
|
||||
10/18/21 16:50:52,49.80,73.40
|
||||
10/18/21 16:51:07,49.80,73.58
|
||||
10/18/21 16:51:23,49.70,73.58
|
||||
10/18/21 16:51:38,49.80,73.40
|
||||
10/18/21 16:51:53,49.90,73.58
|
||||
10/18/21 16:52:08,49.90,73.58
|
||||
10/18/21 16:52:23,49.80,73.58
|
||||
10/18/21 16:52:39,49.80,73.58
|
||||
10/18/21 16:52:54,49.70,73.58
|
||||
10/18/21 16:53:09,49.70,73.58
|
||||
10/18/21 16:53:24,49.70,73.58
|
||||
10/18/21 16:53:39,49.70,73.58
|
||||
10/18/21 16:53:54,49.80,73.58
|
||||
10/18/21 16:54:10,49.80,73.58
|
||||
10/18/21 16:54:25,49.80,73.76
|
||||
10/18/21 16:54:40,49.80,73.58
|
||||
10/18/21 16:54:55,49.70,73.76
|
||||
10/18/21 16:55:10,49.70,73.76
|
||||
10/18/21 16:55:25,49.70,73.76
|
||||
10/18/21 16:55:41,49.60,73.76
|
||||
10/18/21 16:55:56,49.60,73.76
|
||||
10/18/21 16:56:11,49.60,73.76
|
||||
10/18/21 16:56:26,49.40,73.76
|
||||
10/18/21 16:56:41,49.40,73.76
|
||||
10/18/21 16:56:56,49.40,73.76
|
||||
10/18/21 16:57:12,49.40,73.76
|
||||
10/18/21 16:57:27,49.40,73.76
|
||||
10/18/21 16:57:42,49.30,73.76
|
||||
10/18/21 16:57:57,49.30,73.76
|
||||
10/18/21 16:58:12,49.30,73.58
|
||||
10/18/21 16:58:27,49.30,73.76
|
||||
10/18/21 16:58:43,49.30,73.76
|
||||
10/18/21 16:58:58,49.20,73.58
|
||||
10/18/21 16:59:13,49.20,73.58
|
||||
10/18/21 16:59:28,49.20,73.76
|
||||
10/18/21 16:59:43,49.10,73.76
|
||||
10/18/21 16:59:59,49.10,73.76
|
||||
10/18/21 17:00:14,49.00,73.58
|
||||
10/18/21 17:00:29,49.00,73.58
|
||||
10/18/21 17:00:44,49.00,73.58
|
||||
10/18/21 17:00:59,49.00,73.58
|
||||
10/18/21 17:01:15,49.00,73.58
|
||||
10/18/21 17:01:30,49.00,73.58
|
||||
10/18/21 17:01:45,49.00,73.58
|
||||
10/18/21 17:02:00,48.90,73.58
|
||||
10/18/21 17:02:15,48.90,73.58
|
||||
10/18/21 17:02:30,48.90,73.58
|
||||
10/18/21 17:02:46,48.90,73.58
|
||||
10/18/21 17:03:01,48.90,73.58
|
||||
10/18/21 17:03:16,48.90,73.58
|
||||
10/18/21 17:03:31,48.90,73.58
|
||||
10/18/21 17:03:46,48.90,73.58
|
||||
10/18/21 17:04:02,48.80,73.58
|
||||
10/18/21 17:04:17,48.80,73.58
|
||||
10/18/21 17:04:32,48.80,73.58
|
||||
10/18/21 17:04:47,48.80,73.58
|
||||
10/18/21 17:05:02,48.70,73.58
|
||||
10/18/21 17:05:17,48.80,73.58
|
||||
10/18/21 17:05:33,48.70,73.58
|
||||
10/18/21 17:05:48,48.70,73.58
|
||||
10/18/21 17:06:03,48.70,73.58
|
||||
10/18/21 17:06:18,48.80,73.58
|
||||
10/18/21 17:06:33,48.70,73.58
|
||||
10/18/21 17:06:48,48.70,73.58
|
||||
10/18/21 17:07:04,48.70,73.58
|
||||
10/18/21 17:07:19,48.70,73.58
|
||||
10/18/21 17:07:34,48.80,73.58
|
||||
10/18/21 17:07:49,48.80,73.58
|
||||
10/18/21 17:08:04,48.80,73.76
|
||||
10/18/21 17:08:20,48.70,73.76
|
||||
10/18/21 17:08:35,48.70,73.76
|
||||
10/18/21 17:08:50,48.80,73.76
|
||||
10/18/21 17:09:05,48.80,73.76
|
||||
10/18/21 17:09:20,48.80,73.76
|
||||
10/18/21 17:09:36,48.70,73.76
|
||||
10/18/21 17:09:51,48.70,73.76
|
||||
10/18/21 17:10:06,48.70,73.76
|
||||
10/18/21 17:10:21,48.70,73.76
|
||||
10/18/21 17:10:36,48.70,73.76
|
||||
10/18/21 17:10:51,48.70,73.76
|
||||
10/18/21 17:11:07,48.80,73.76
|
||||
10/18/21 17:11:22,48.70,73.76
|
||||
10/18/21 17:11:37,48.70,73.76
|
||||
10/18/21 17:11:52,48.70,73.76
|
||||
10/18/21 17:12:07,48.70,73.76
|
||||
10/18/21 17:12:23,48.60,73.76
|
||||
10/18/21 17:12:38,48.70,73.76
|
||||
10/18/21 17:12:53,48.70,73.76
|
||||
10/18/21 17:13:08,48.60,73.76
|
||||
10/18/21 17:13:23,48.60,73.76
|
||||
10/18/21 17:13:38,48.70,73.94
|
||||
10/18/21 17:13:54,48.70,73.94
|
||||
10/18/21 17:14:09,48.60,73.76
|
||||
10/18/21 17:14:24,48.70,73.76
|
||||
10/18/21 17:14:39,48.60,73.76
|
||||
10/18/21 17:14:54,48.60,73.94
|
||||
10/18/21 17:15:09,48.60,73.94
|
||||
10/18/21 17:15:25,48.60,73.94
|
||||
10/18/21 17:15:40,48.60,73.94
|
||||
10/18/21 17:15:55,48.50,73.94
|
||||
10/18/21 17:16:10,48.50,73.94
|
||||
10/18/21 17:16:25,48.50,73.76
|
||||
10/18/21 17:16:40,48.40,73.94
|
||||
10/18/21 17:16:56,48.40,73.94
|
||||
10/18/21 17:17:11,48.50,73.76
|
||||
10/18/21 17:17:26,48.50,73.76
|
||||
10/18/21 17:17:41,48.60,73.94
|
||||
10/18/21 17:17:56,48.50,73.76
|
||||
10/18/21 17:18:11,48.60,73.76
|
||||
10/18/21 17:18:27,48.60,73.94
|
||||
10/18/21 17:18:42,48.50,73.94
|
||||
10/18/21 17:18:57,48.60,73.94
|
||||
10/18/21 17:19:12,48.60,73.76
|
||||
10/18/21 17:19:27,48.60,73.76
|
||||
10/18/21 17:19:42,48.60,73.76
|
||||
10/18/21 17:19:58,48.60,73.76
|
||||
10/18/21 17:20:13,48.60,73.76
|
||||
10/18/21 17:20:28,48.60,73.76
|
||||
10/18/21 17:20:43,48.60,73.76
|
||||
10/18/21 17:20:58,48.70,73.76
|
||||
10/18/21 17:21:14,48.70,73.76
|
||||
10/18/21 17:21:29,48.70,73.76
|
||||
10/18/21 17:21:44,48.70,73.76
|
||||
10/18/21 17:21:59,48.70,73.76
|
||||
10/18/21 17:22:14,48.80,73.76
|
||||
10/18/21 17:22:30,48.80,73.76
|
||||
10/18/21 17:22:45,48.80,73.76
|
||||
10/18/21 17:23:00,48.80,73.76
|
||||
10/18/21 17:23:15,48.80,73.76
|
||||
10/18/21 17:23:30,48.90,73.94
|
||||
10/18/21 17:23:45,48.80,73.76
|
||||
10/18/21 17:24:01,48.90,73.76
|
||||
10/18/21 17:24:16,48.90,73.76
|
||||
10/18/21 17:24:31,48.90,73.76
|
||||
10/18/21 17:24:46,48.90,73.76
|
||||
10/18/21 17:25:01,49.00,73.94
|
||||
10/18/21 17:25:17,49.00,73.76
|
||||
10/18/21 17:25:32,49.00,73.76
|
||||
10/18/21 17:25:47,49.00,73.94
|
||||
10/18/21 17:26:02,49.00,73.94
|
||||
10/18/21 17:26:17,49.00,73.76
|
||||
10/18/21 17:26:32,49.00,73.76
|
||||
10/18/21 17:26:48,49.00,73.76
|
||||
10/18/21 17:27:03,49.00,73.76
|
||||
10/18/21 17:27:18,49.10,73.76
|
||||
10/18/21 17:27:33,49.10,73.76
|
||||
10/18/21 17:27:48,49.10,73.76
|
||||
10/18/21 17:28:04,49.10,73.76
|
||||
10/18/21 17:28:19,49.10,73.76
|
||||
10/18/21 17:28:34,49.10,73.76
|
||||
10/18/21 17:28:49,49.10,73.76
|
||||
10/18/21 17:29:04,49.20,73.76
|
||||
10/18/21 17:29:19,49.20,73.76
|
||||
10/18/21 17:29:35,49.10,73.76
|
||||
10/18/21 17:29:50,49.10,73.76
|
||||
10/18/21 17:30:05,49.10,73.76
|
||||
10/18/21 17:30:20,49.10,73.76
|
||||
10/18/21 17:30:35,49.10,73.76
|
||||
10/18/21 17:30:50,49.10,73.76
|
||||
10/18/21 17:31:06,49.10,73.76
|
||||
10/18/21 17:31:21,49.00,73.76
|
||||
10/18/21 17:31:36,49.10,73.76
|
||||
10/18/21 17:31:51,49.00,73.76
|
||||
10/18/21 17:32:06,49.10,73.76
|
||||
10/18/21 17:32:22,49.10,73.76
|
||||
10/18/21 17:32:37,49.00,73.76
|
||||
10/18/21 17:32:52,49.10,73.76
|
||||
10/18/21 17:33:07,49.00,73.76
|
||||
10/18/21 17:33:22,49.10,73.76
|
||||
10/18/21 17:33:37,49.10,73.76
|
||||
10/18/21 17:33:53,49.00,73.76
|
||||
10/18/21 17:34:08,49.00,73.76
|
||||
10/18/21 17:34:23,49.00,73.76
|
||||
10/18/21 17:34:38,49.00,73.76
|
||||
10/18/21 17:34:53,49.00,73.76
|
||||
10/18/21 17:35:09,49.00,73.76
|
||||
10/18/21 17:35:24,49.00,73.76
|
||||
10/18/21 17:35:39,49.00,73.76
|
||||
10/18/21 17:35:54,49.00,73.76
|
||||
10/18/21 17:36:09,48.90,73.76
|
||||
10/18/21 17:36:25,49.00,73.76
|
||||
10/18/21 17:36:40,48.90,73.76
|
||||
10/18/21 17:36:55,48.90,73.76
|
||||
10/18/21 17:37:10,48.90,73.76
|
||||
10/18/21 17:37:25,48.90,73.76
|
||||
10/18/21 17:37:40,48.90,73.76
|
||||
10/18/21 17:37:56,48.90,73.76
|
||||
10/18/21 17:38:11,48.90,73.76
|
||||
10/18/21 17:38:26,48.90,73.76
|
||||
10/18/21 17:38:41,48.90,73.76
|
||||
10/18/21 17:38:56,48.90,73.76
|
||||
10/18/21 17:39:11,48.80,73.76
|
||||
10/18/21 17:39:27,48.80,73.76
|
||||
10/18/21 17:39:42,48.80,73.76
|
||||
10/18/21 17:39:57,48.80,73.76
|
||||
10/18/21 17:40:12,48.80,73.76
|
||||
10/18/21 17:40:27,48.80,73.76
|
||||
10/18/21 17:40:43,48.70,73.76
|
||||
10/18/21 17:40:58,48.80,73.76
|
||||
10/18/21 17:41:13,48.70,73.76
|
||||
10/18/21 17:41:28,48.70,73.76
|
||||
10/18/21 17:41:43,48.70,73.76
|
||||
10/18/21 17:41:58,48.70,73.76
|
||||
10/18/21 17:42:14,48.70,73.76
|
||||
10/18/21 17:42:29,48.60,73.76
|
||||
10/18/21 17:42:44,48.70,73.76
|
||||
10/18/21 17:42:59,48.60,73.76
|
||||
10/18/21 17:43:14,48.60,73.76
|
||||
10/18/21 17:43:29,48.70,73.76
|
||||
10/18/21 17:43:45,48.60,73.76
|
||||
10/18/21 17:44:00,48.60,73.76
|
||||
10/18/21 17:44:15,48.60,73.76
|
||||
10/18/21 17:44:30,48.60,73.76
|
||||
10/18/21 17:44:45,48.60,73.76
|
||||
10/18/21 17:45:00,48.60,73.76
|
||||
10/18/21 17:45:16,48.60,73.76
|
||||
10/18/21 17:45:31,48.60,73.76
|
||||
10/18/21 17:45:46,48.60,73.76
|
||||
10/18/21 17:46:01,48.60,73.76
|
||||
10/18/21 17:46:16,48.60,73.76
|
||||
10/18/21 17:46:31,48.60,73.58
|
||||
10/18/21 17:46:47,48.60,73.76
|
||||
10/18/21 17:47:02,48.50,73.76
|
||||
10/18/21 17:47:17,48.60,73.58
|
||||
10/18/21 17:47:32,48.60,73.58
|
||||
10/18/21 17:47:47,48.60,73.58
|
||||
10/18/21 17:48:02,48.60,73.58
|
||||
10/18/21 17:48:18,48.70,73.76
|
||||
10/18/21 17:48:33,48.70,73.58
|
||||
10/18/21 17:48:48,48.60,73.58
|
||||
10/18/21 17:49:03,48.70,73.76
|
||||
10/18/21 17:49:18,48.70,73.76
|
||||
10/18/21 17:49:33,48.70,73.76
|
||||
10/18/21 17:49:49,48.80,73.58
|
||||
10/18/21 17:50:04,48.80,73.58
|
||||
10/18/21 17:50:19,48.80,73.76
|
||||
10/18/21 17:50:34,48.80,73.76
|
||||
10/18/21 17:50:49,48.80,73.58
|
||||
10/18/21 17:51:05,48.90,73.58
|
||||
10/18/21 17:51:20,48.80,73.58
|
||||
10/18/21 17:51:35,48.90,73.58
|
||||
10/18/21 17:51:50,48.90,73.76
|
||||
10/18/21 17:52:05,48.90,73.76
|
||||
10/18/21 17:52:20,48.90,73.76
|
||||
10/18/21 17:52:36,48.80,73.76
|
||||
10/18/21 17:52:51,49.00,73.76
|
||||
10/18/21 17:53:06,48.90,73.76
|
||||
10/18/21 17:53:21,49.00,73.76
|
||||
10/18/21 17:53:36,48.90,73.76
|
||||
10/18/21 17:53:51,48.90,73.76
|
||||
10/18/21 17:54:07,48.90,73.76
|
||||
10/18/21 17:54:22,49.00,73.76
|
||||
10/18/21 17:54:37,48.90,73.76
|
||||
10/18/21 17:54:52,48.90,73.76
|
||||
10/18/21 17:55:07,48.80,73.76
|
||||
10/18/21 17:55:23,48.90,73.76
|
||||
10/18/21 17:55:38,48.90,73.76
|
||||
10/18/21 17:55:53,48.80,73.76
|
||||
10/18/21 17:56:08,48.90,73.76
|
||||
10/18/21 17:56:23,48.90,73.76
|
||||
10/18/21 17:56:38,48.90,73.76
|
||||
10/18/21 17:56:54,48.90,73.76
|
||||
10/18/21 17:57:09,48.90,73.76
|
||||
10/18/21 17:57:24,48.90,73.76
|
||||
10/18/21 17:57:39,48.90,73.76
|
||||
10/18/21 17:57:54,48.90,73.76
|
||||
10/18/21 17:58:09,48.90,73.76
|
||||
10/18/21 17:58:25,48.90,73.76
|
||||
10/18/21 17:58:40,49.00,73.76
|
||||
10/18/21 17:58:55,49.00,73.76
|
||||
10/18/21 17:59:10,49.10,73.76
|
||||
10/18/21 17:59:25,49.10,73.76
|
||||
10/18/21 17:59:41,49.10,73.76
|
||||
10/18/21 17:59:56,49.00,73.76
|
||||
10/18/21 18:00:11,49.00,73.76
|
||||
10/18/21 18:00:26,49.00,73.76
|
||||
10/18/21 18:00:41,49.00,73.76
|
||||
10/18/21 18:00:56,49.00,73.76
|
||||
10/18/21 18:01:12,49.00,73.76
|
||||
10/18/21 18:01:27,49.00,73.76
|
||||
10/18/21 18:01:42,48.90,73.76
|
||||
10/18/21 18:01:57,49.00,73.76
|
||||
10/18/21 18:02:12,49.00,73.76
|
||||
10/18/21 18:02:27,49.00,73.76
|
||||
10/18/21 18:02:43,49.00,73.58
|
||||
10/18/21 18:02:58,49.00,73.76
|
||||
10/18/21 18:03:13,49.00,73.76
|
||||
10/18/21 18:03:28,49.00,73.76
|
||||
10/18/21 18:03:43,49.00,73.76
|
||||
10/18/21 18:03:59,49.00,73.58
|
||||
10/18/21 18:04:14,49.00,73.58
|
||||
10/18/21 18:04:29,49.00,73.58
|
||||
10/18/21 18:04:44,49.00,73.76
|
||||
10/18/21 18:04:59,49.00,73.76
|
||||
10/18/21 18:05:14,49.00,73.58
|
||||
10/18/21 18:05:30,49.00,73.58
|
||||
10/18/21 18:05:45,49.00,73.76
|
||||
10/18/21 18:06:00,49.00,73.58
|
||||
10/18/21 18:06:15,49.00,73.58
|
||||
10/18/21 18:06:30,49.00,73.58
|
||||
10/18/21 18:06:46,49.00,73.76
|
||||
10/18/21 18:07:01,49.00,73.76
|
||||
10/18/21 18:07:16,49.00,73.58
|
||||
10/18/21 18:07:31,48.90,73.58
|
||||
10/18/21 18:07:46,48.90,73.58
|
||||
10/18/21 18:08:02,48.90,73.58
|
||||
10/18/21 18:08:17,48.90,73.58
|
||||
10/18/21 18:08:32,48.90,73.58
|
||||
10/18/21 18:08:47,48.90,73.58
|
||||
10/18/21 18:09:02,48.80,73.58
|
||||
10/18/21 18:09:17,48.80,73.58
|
||||
10/18/21 18:09:33,48.80,73.58
|
||||
10/18/21 18:09:48,48.70,73.58
|
||||
10/18/21 18:10:03,48.70,73.58
|
||||
10/18/21 18:10:18,48.70,73.58
|
||||
10/18/21 18:10:33,48.60,73.58
|
||||
|
40
dht22/print_DHT22.py
Executable file
40
dht22/print_DHT22.py
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import adafruit_dht
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def get_sensor_data(dht22):
|
||||
try:
|
||||
temperature = 9./5. * dht22.temperature + 32.
|
||||
humidity = dht22.humidity
|
||||
return temperature, humidity
|
||||
except RuntimeError as e:
|
||||
print("Reading from DHT failure: ", e.args)
|
||||
return None
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Setup for Hardware
|
||||
DHT22_PIN = 4
|
||||
dht_device = adafruit_dht.DHT22(4)
|
||||
file = '/home/pi/code/garden/dht22/log.csv'
|
||||
|
||||
with open(file,'a') as f:
|
||||
|
||||
try:
|
||||
while True:
|
||||
data = get_sensor_data(dht22=dht_device)
|
||||
if data:
|
||||
temperature, humidity = get_sensor_data(dht22=dht_device)
|
||||
current_time = datetime.now().strftime("%D %H:%M:%S")
|
||||
print(f'{humidity:.2f}% {temperature:.2f}degF')
|
||||
f.write(f'{current_time},{humidity:.2f},{temperature:.2f}\n')
|
||||
time.sleep(14.9)
|
||||
else:
|
||||
time.sleep(0.1)
|
||||
|
||||
finally:
|
||||
GPIO.cleanup()
|
||||
23
dht22/requirements.txt
Normal file
23
dht22/requirements.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
Adafruit-Blinka==6.15.0
|
||||
adafruit-circuitpython-dht==3.6.2
|
||||
Adafruit-DHT==1.4.0
|
||||
Adafruit-PlatformDetect==3.16.0
|
||||
Adafruit-PureIO==1.1.9
|
||||
black==21.9b0
|
||||
click==8.0.3
|
||||
importlib-metadata==4.8.1
|
||||
mypy-extensions==0.4.3
|
||||
pathspec==0.9.0
|
||||
pkg-resources==0.0.0
|
||||
platformdirs==2.4.0
|
||||
pyftdi==0.53.3
|
||||
pyserial==3.5
|
||||
pyusb==1.2.1
|
||||
regex==2021.10.8
|
||||
rpi-ws281x==4.3.0
|
||||
RPi.GPIO==0.7.0
|
||||
sysv-ipc==1.1.0
|
||||
tomli==1.2.1
|
||||
typed-ast==1.4.3
|
||||
typing-extensions==3.10.0.2
|
||||
zipp==3.6.0
|
||||
28
functional_decription.md
Normal file
28
functional_decription.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Functional Description - Garden Logic
|
||||
|
||||
### Table of Contents
|
||||
1. Routines
|
||||
1. Scan Inputs
|
||||
2. Collect Program State
|
||||
3. Manipulate Program State
|
||||
4. Write Outputs
|
||||
5. Log to Database
|
||||
2. References
|
||||
|
||||
|
||||
## Routines
|
||||
|
||||
### Scan Inputs
|
||||
`./input/inputs.py`
|
||||
|
||||
### Collect Program State
|
||||
`./states/state.py`
|
||||
|
||||
### Manipulate Program State
|
||||
`./states/state.py`
|
||||
|
||||
### Write Outputs
|
||||
`./output/outputs.py`
|
||||
|
||||
### Log to Database
|
||||
`./logging/db.py`
|
||||
77
manual/manual.py
Normal file
77
manual/manual.py
Normal file
@@ -0,0 +1,77 @@
|
||||
#! env/bin/python3
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
# Setup for Hardware
|
||||
PB1_BCM = 4 # Green
|
||||
PB2_BCM = 27 # Yellow
|
||||
PB3_BCM = 13 # Blue
|
||||
RELAY1_PIN = 26 # Water Pump
|
||||
RELAY2_PIN = 20 # Unassigned
|
||||
RELAY3_PIN = 21 # Lamp
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
|
||||
# Setup the Inputs to use the internal pull-down.
|
||||
GPIO.setup(PB1_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(PB2_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(PB3_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
|
||||
# Setup the outputs to be initialized as OFF.
|
||||
GPIO.setup(RELAY1_PIN, GPIO.OUT)
|
||||
GPIO.output(RELAY1_PIN, False)
|
||||
GPIO.setup(RELAY2_PIN, GPIO.OUT)
|
||||
GPIO.output(RELAY2_PIN, False)
|
||||
GPIO.setup(RELAY3_PIN, GPIO.OUT)
|
||||
GPIO.output(RELAY3_PIN, False)
|
||||
|
||||
# Define alias variables for input devices.
|
||||
green_button = False
|
||||
yellow_button = False
|
||||
blue_button = False
|
||||
|
||||
# Define state variables for each of the output devices.
|
||||
pump_state = False
|
||||
lamp_state = False
|
||||
|
||||
# Begin detected presses.
|
||||
try:
|
||||
while True:
|
||||
|
||||
# Detect inputs.
|
||||
detect = False
|
||||
green_button = GPIO.input(PB1_BCM)
|
||||
yellow_button = GPIO.input(PB2_BCM)
|
||||
blue_button = GPIO.input(PB3_BCM)
|
||||
|
||||
# Determine state.
|
||||
if not detect and blue_button and pump_state:
|
||||
pump_state = False
|
||||
detect = True
|
||||
if not detect and blue_button and not pump_state:
|
||||
pump_state = True
|
||||
detect = True
|
||||
# Lamp
|
||||
if not detect and yellow_button and lamp_state:
|
||||
lamp_state = False
|
||||
detect = True
|
||||
if not detect and yellow_button and not lamp_state:
|
||||
lamp_state = True
|
||||
detect = True
|
||||
|
||||
# Write outputs.
|
||||
if detect:
|
||||
time.sleep(1.0)
|
||||
GPIO.output(RELAY1_PIN, pump_state)
|
||||
GPIO.output(RELAY3_PIN, lamp_state)
|
||||
|
||||
# Avoid running a single thread maxxed out.
|
||||
time.sleep(0.1)
|
||||
|
||||
finally:
|
||||
GPIO.cleanup()
|
||||
40
pb/pb.py
Executable file
40
pb/pb.py
Executable file
@@ -0,0 +1,40 @@
|
||||
#! env/bin/python3
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Setup for Hardware
|
||||
PB1_BCM = 4 # Green
|
||||
PB2_BCM = 27 # Yellow
|
||||
PB3_BCM = 13 # Blue
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
|
||||
# Use the internal pull-down.
|
||||
GPIO.setup(PB1_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(PB2_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(PB3_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
|
||||
# Begin detected presses.
|
||||
i = 0
|
||||
try:
|
||||
while True:
|
||||
# Green
|
||||
if GPIO.input(PB1_BCM):
|
||||
i += 1
|
||||
print(f"Hi Gabby! Did you push the GREEN button? i = {i}")
|
||||
# Yellow
|
||||
if GPIO.input(PB2_BCM):
|
||||
i += 1
|
||||
print(f"Hi Gabby! Did you push the YELLOW button? i = {i}")
|
||||
# Blue
|
||||
if GPIO.input(PB3_BCM):
|
||||
i += 1
|
||||
print(f"Hi Gabby! Did you push the BLUE button? i = {i}")
|
||||
time.sleep(0.1)
|
||||
|
||||
finally:
|
||||
GPIO.cleanup()
|
||||
13
pb/requirements.txt
Normal file
13
pb/requirements.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
black==21.9b0
|
||||
click==8.0.3
|
||||
importlib-metadata==4.8.1
|
||||
mypy-extensions==0.4.3
|
||||
pathspec==0.9.0
|
||||
pkg-resources==0.0.0
|
||||
platformdirs==2.4.0
|
||||
regex==2021.10.8
|
||||
RPi.GPIO==0.7.0
|
||||
tomli==1.2.1
|
||||
typed-ast==1.4.3
|
||||
typing-extensions==3.10.0.2
|
||||
zipp==3.6.0
|
||||
37
relay/relay.py
Normal file
37
relay/relay.py
Normal file
@@ -0,0 +1,37 @@
|
||||
#! env/bin/python3
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Setup for Hardware
|
||||
RELAY1_PIN = 26
|
||||
RELAY2_PIN = 20
|
||||
RELAY3_PIN = 21
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
|
||||
# Setup the output pin; initialize OFF.
|
||||
GPIO.setup(RELAY1_PIN, GPIO.OUT)
|
||||
GPIO.output(RELAY1_PIN, False)
|
||||
GPIO.setup(RELAY2_PIN, GPIO.OUT)
|
||||
GPIO.output(RELAY2_PIN, False)
|
||||
GPIO.setup(RELAY3_PIN, GPIO.OUT)
|
||||
GPIO.output(RELAY3_PIN, False)
|
||||
|
||||
|
||||
# Short toggle.
|
||||
i = 0
|
||||
try:
|
||||
time.sleep(10.0)
|
||||
GPIO.output(RELAY1_PIN, True)
|
||||
GPIO.output(RELAY3_PIN, True)
|
||||
time.sleep(60.0)
|
||||
GPIO.output(RELAY1_PIN, False)
|
||||
GPIO.output(RELAY3_PIN, False)
|
||||
time.sleep(1.0)
|
||||
|
||||
finally:
|
||||
GPIO.cleanup()
|
||||
13
relay/requirements.txt
Normal file
13
relay/requirements.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
black==21.9b0
|
||||
click==8.0.3
|
||||
importlib-metadata==4.8.1
|
||||
mypy-extensions==0.4.3
|
||||
pathspec==0.9.0
|
||||
pkg-resources==0.0.0
|
||||
platformdirs==2.4.0
|
||||
regex==2021.10.8
|
||||
RPi.GPIO==0.7.0
|
||||
tomli==1.2.1
|
||||
typed-ast==1.4.3
|
||||
typing-extensions==3.10.0.2
|
||||
zipp==3.6.0
|
||||
13
requirements.txt
Normal file
13
requirements.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
black==21.9b0
|
||||
click==8.0.3
|
||||
importlib-metadata==4.8.1
|
||||
mypy-extensions==0.4.3
|
||||
pathspec==0.9.0
|
||||
pkg-resources==0.0.0
|
||||
platformdirs==2.4.0
|
||||
regex==2021.10.8
|
||||
RPi.GPIO==0.7.0
|
||||
tomli==1.2.1
|
||||
typed-ast==1.4.3
|
||||
typing-extensions==3.10.0.2
|
||||
zipp==3.6.0
|
||||
Reference in New Issue
Block a user