-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaterGUI.py
More file actions
128 lines (108 loc) · 4 KB
/
Copy pathWaterGUI.py
File metadata and controls
128 lines (108 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import pandas as pd # For Data Manipulation
import seaborn as sns # For graphing
import matplotlib.pyplot as plt # Also for graphing
import PySimpleGUI as sg # For the GUI
import time # For the time and date
import RPi.GPIO as GPIO # For the watering buttons
# Setup the GPIO pins to turn the pumps on and off
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
PUMP1 = 24
PUMP2 = 25
GPIO.setup(PUMP1, GPIO.OUT)
GPIO.setup(PUMP2, GPIO.OUT)
#Set the outputs to low
GPIO.output(PUMP1, GPIO.LOW)
GPIO.output(PUMP2, GPIO.LOW)
#Function to turn the water pump on and then off
def waterPlant(pump):
GPIO.output(pump, GPIO.HIGH) # Turn the pump on for 4 seconds
time.sleep(4)
GPIO.output(pump, GPIO.LOW) # Turn the pump off
# Grab data from github, format it in pandas
data = pd.read_csv('https://raw.githubusercontent.com/Zaquen/SeniorProject/master/data.txt?token=ANH2CXFO4SBA6IWVOH4IHR273Y7K6')
data.columns = ['Timestamp', 'Soil_A', 'Soil_B', 'WaterLevel', 'Day_A', 'Day_B', 'Temp', 'Humid']
# Data manipulation, make it readable
# Make a new column for a date and time
# Make the soil moisture a percentage up to 500 as 100%
# Make the day sensors a percentage up to 1024 as 100%
# Drop the waterLevel column
data = data.drop(columns='WaterLevel')
data.Soil_A = (data.Soil_A / 500) * 100
data.Soil_B = (data.Soil_B / 500) * 100
data.Day_A = ((data.Day_A / 1024) * 100).round(2)
data.Day_B = ((data.Day_B / 1024) * 100).round(2)
data['Datetime'] = pd.to_datetime(data.Timestamp, unit='s')
data['Time'] = pd.to_datetime(data.Datetime).dt.time
#All of my graphs I want to show, save them to files for the GUI, then clear the plot
plot = sns.lineplot(data=data, y=data.Temp, x=data.Datetime) # Temp/Time
plot.set(xlabel='Time since 12/10')
plot.set(xticklabels=[])
plt.savefig('temp.png', bbox_inches='tight')
plt.clf()
plot = sns.lineplot(data=data, y=data.Humid, x=data.Datetime) # Humid/Time
plot.set(xlabel='Time since 12/10')
plot.set(xticklabels=[])
plt.savefig('humid.png', bbox_inches='tight')
plt.clf()
plot = sns.lineplot(data=data, y=data.Soil_A, x=data.Datetime) # SoilA/Time
plot.set(xlabel='Time since 12/10')
plot.set(xticklabels=[])
plt.savefig('soila.png', bbox_inches='tight')
plt.clf()
plot = sns.lineplot(data=data, y=data.Soil_B, x=data.Datetime) # SoilB/Time
plot.set(xlabel='Time since 12/10')
plot.set(xticklabels=[])
plt.savefig('soilb.png', bbox_inches='tight')
plt.clf()
plot = sns.lineplot(data=data, y=data.Day_A, x=data.Datetime) # DaylightA/Time
plot.set(xlabel='Time since 12/10')
plot.set(xticklabels=[])
plt.savefig('daya.png', bbox_inches='tight')
plt.clf()
plot = sns.lineplot(data=data, y=data.Day_B, x=data.Datetime) # DaylightB/Time
plot.set(xlabel='Time since 12/10')
plot.set(xticklabels=[])
plt.savefig('dayb.png', bbox_inches='tight')
plt.clf()
#Build the window
#Layout first
#Setup the 3 columns
column_left = [
[sg.Text("Plant A Moisture over Time")],[sg.Image('soila.png')],
[sg.Text("Plant A Daylight over Time")],[sg.Image('daya.png')],
[sg.Button('Water Plant A')],
]
column_center = [
[sg.Text("Temperature over Time")],[sg.Image('temp.png')],
[sg.Text('Humidity over Time')],[sg.Image('humid.png')],
]
column_right = [
[sg.Text("Plant B Moisture over Time")],[sg.Image('soilb.png')],
[sg.Text("Plant B Daylight over Time")],[sg.Image('dayb.png')],
[sg.Button('Water Plant B')],
]
layout = [
[
sg.Column(column_left),
sg.VSeperator(),
sg.Column(column_center),
sg.VSeperator(),
sg.Column(column_right),
]
]
# Create the Window
window = sg.Window(title='Plant Watering', layout=layout, location=(0,0),
element_justification='center', font="Helvetica 16", finalize=True)
# Create an event loop
while True:
event, values = window.read()
# Handle the case of Water Plant Buttons
if event == 'Water Plant A':
waterPlant(PUMP1)
if event == 'Water Plant B':
waterPlant(PUMP2)
# End program if user closes window
if event == sg.WIN_CLOSED:
break
window.close()