Advertisement
Guest User

Hydroponics with TKInter final

a guest
Feb 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.13 KB | None | 0 0
  1. from Tkinter import *
  2. import serial
  3. import RPi.GPIO as GPIO
  4. import cayenne.client
  5. import time
  6. import datetime
  7. LEDontime = 22
  8. LEDofftime = 6
  9. GPIO.setmode(GPIO.BCM)
  10. GPIO.setwarnings(False)
  11. pins = [26, 19, 13, 06]
  12. GPIO.setup(pins, GPIO.OUT)
  13. pHDown = 26
  14. pHUp = 19
  15. TEC = 13
  16. LED = 06
  17. GPIO.output(pins, GPIO.LOW)
  18. time.sleep(0.5)
  19. GPIO.output(pins, GPIO.HIGH)
  20. time.sleep(0.5)
  21. GPIO.output(pins, GPIO.LOW)
  22. time.sleep(0.5)
  23. GPIO.output(pins, GPIO.HIGH)
  24. time.sleep(0.5)
  25. pHCounter = 0
  26.  
  27.  
  28. print "clearing up relays"
  29.  
  30. ser=serial.Serial("/dev/ttyUSB0",9600) #change USB as found from ls /dev/tty/USB*
  31. ser.baudrate=9600
  32. MQTT_USERNAME = "61334000-fc63-11e7-848a-61efd1c01e7d"
  33. MQTT_PASSWORD = "ca292be60d160c1e96bf6074bdf77710949036a6"
  34. MQTT_CLIENT_ID = "33b92b50-125a-11e8-b42d-698bd45831f1"
  35.  
  36.  
  37. client = cayenne.client.CayenneMQTTClient()
  38.  
  39. client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
  40. #GET SENSOR VALUES
  41. value = ser.readline()
  42. time.sleep(5)
  43. print value
  44. pH = float(value[1:4])
  45. strpH = value[1:4]
  46. humidity = float(value[5:10])
  47. strhumidity = value[5:10]
  48. temp = float(value[11:16])
  49. strtemp = value[11:16]
  50. wtemp = float(value[17:])
  51. strwtemp = value[17:]
  52. realTime = datetime.datetime.now().strftime("%H:%M")
  53.  
  54.  
  55.  
  56.  
  57.  
  58. window = Tk()
  59.  
  60. window.title("Greenhouse Based Hydroponics - Sensor Data")
  61.  
  62. window.geometry('900x400')
  63.  
  64. ########
  65.  
  66. timelbl = Label(window, text=realTime, font=("Arial Bold", 30))
  67.  
  68. timelbl.grid(column=1, row=0)
  69.  
  70. def clock():
  71.  
  72. global pHCounter
  73. newCounter = pHCounter + 1
  74. pHCounter = newCounter
  75. hourTime = datetime.datetime.now().strftime("%H")
  76.  
  77. if (int(hourTime) >= LEDontime):
  78. print "Grow lights are now off"
  79. GPIO.output(LED, GPIO.LOW)
  80. if (int(hourTime) >= LEDofftime) and (int(hourTime) < LEDontime):
  81. print "Grow lights are now ON"
  82. GPIO.output(LED, GPIO.LOW)
  83.  
  84.  
  85.  
  86. client.loop()
  87. value=ser.readline()
  88.  
  89. pH = float(value[1:5])
  90. humidity = float(value[6:11])
  91. temp = float(value[12:17])
  92. wtemp = float(value[18:])
  93. #print(value)
  94. #print(value[1:5])
  95. #print(value[5:10])
  96. #print(value[10:15])
  97.  
  98.  
  99. #-------- allow 15 ph tests before adjusting ph
  100. if pHCounter >= 15:
  101.  
  102. if pH < 5:
  103. print "ph is below 5"
  104. print pH
  105. GPIO.output(pHUp, GPIO.LOW)
  106. GPIO.output(pHDown, GPIO.HIGH)
  107. if pH > 6 and pH < 7:
  108. print pH
  109. print "ph is safe range"
  110. GPIO.output(pHUp, GPIO.HIGH)
  111. GPIO.output(pHDown, GPIO.HIGH)
  112.  
  113. if pH > 7:
  114. print "abovep h"
  115. GPIO.output(pHUp, GPIO.HIGH)
  116. GPIO.output(pHDown, GPIO.LOW)
  117.  
  118.  
  119.  
  120.  
  121.  
  122. client.celsiusWrite(1, temp)
  123. client.luxWrite(2, humidity)
  124. client.luxWrite(3, pH)
  125.  
  126. print ("pH Tests done: " + str(newCounter))
  127. client.celsiusWrite(4, wtemp)
  128.  
  129.  
  130.  
  131.  
  132. ################################
  133.  
  134.  
  135. value = ser.readline()
  136.  
  137. strpH = value[1:4]
  138. print strpH
  139. pHlbl.configure(text=strpH)
  140.  
  141. strtemp = value[12:17]
  142. print strtemp
  143. templbl.configure(text=strtemp)
  144.  
  145. strhumidity = value[6:11]
  146. print strhumidity
  147. humlbl.configure(text=strhumidity)
  148.  
  149. strwtemp = value[18:]
  150. print strwtemp
  151. wtemplbl.configure(text=strwtemp)
  152.  
  153. time = time = datetime.datetime.now().strftime("Time: %H:%M:%S")
  154. timelbl.config(text=time)
  155. window.after(7000, clock)
  156.  
  157.  
  158. ###############
  159.  
  160. pHlbl = Label(window, text=strpH, font=("Arial Bold", 30))
  161.  
  162. pHlbl.grid(column=0, row=2)
  163.  
  164. ideallbl = Label(window, text="Ideal pH range is 6.0 - 7.0", font=("Arial Bold", 10))
  165.  
  166. ideallbl.grid(column=0, row=3)
  167. def pHclick():
  168. value = ser.readline()
  169. strpH = value[1:4]
  170. print strpH
  171. pHlbl.configure(text=strpH)
  172.  
  173. pHbtn = Button(window, text=" Update pH ", command= pHclick ,bg="powder blue", fg="black", font=("Arial Bold", 12))
  174.  
  175. pHbtn.grid(column=1, row=2)
  176.  
  177. ###############
  178.  
  179. templbl = Label(window, text=strtemp, font=("Arial Bold", 30))
  180.  
  181. templbl.grid(column=0, row=4)
  182.  
  183. def tempclick():
  184. value = ser.readline()
  185. strtemp = value[12:17]
  186. print strtemp
  187. templbl.configure(text=strtemp)
  188.  
  189. tempbtn = Button(window, text=" Update room temp ", command = tempclick,bg="burlywood1", fg="black", font=("Arial Bold", 12))
  190.  
  191. tempbtn.grid(column=1, row=4)
  192.  
  193.  
  194. ###############
  195.  
  196. humlbl = Label(window, text=strhumidity, font=("Arial Bold", 30))
  197.  
  198. humlbl.grid(column=0, row=6)
  199.  
  200. def humclick():
  201. value = ser.readline()
  202. strhumidity = value[6:11]
  203. print strhumidity
  204. humlbl.configure(text=strhumidity)
  205. print "humidity update"
  206.  
  207. humbtn = Button(window, text="Update relative humidity reading ", command= humclick,bg="light salmon", fg="black", font=("Arial Bold", 12))
  208.  
  209. humbtn.grid(column=1, row=6)
  210.  
  211.  
  212. ###############
  213.  
  214.  
  215. wtemplbl = Label(window, text=strwtemp, font=("Arial Bold", 30))
  216.  
  217. wtemplbl.grid(column=0, row=8)
  218.  
  219. def wtempclick():
  220. value=ser.readline()
  221. strwtemp = value[18:]
  222. print strwtemp
  223. wtemplbl.configure(text=strwtemp)
  224.  
  225. wtempbtn = Button(window, text=" Update nutrient solution temp ", command = wtempclick,bg="steelblue1", fg="black", font=("Arial Bold", 12))
  226.  
  227. wtempbtn.grid(column=1, row=8)
  228.  
  229.  
  230. ###################
  231.  
  232. '''
  233. bufferlbl = Label(window, text="pH Buffer status : ", font=("Arial Bold", 30))
  234.  
  235. bufferlbl.grid(column=0, row=10)
  236. bufferTxt = "Buffer status standby"
  237. def bufferclick():
  238. if pH < 6:
  239. bufferTxt = "Up buffer is ON"
  240. print "ph less than 6"
  241. if pH > 7:
  242. bufferTxt = "Down buffer is ON"
  243. print "ph greater than 7"
  244. if (pH>6) and (pH<7):
  245. bufferTxt = "Buffers are OFF"
  246. print "ph ideal range"
  247. statuslbl.configure(text=bufferTxt)
  248.  
  249.  
  250. statuslbl = Button(window, text = bufferTxt, font=("Arial Bold", 15),bg="palevioletred2", command=bufferclick)
  251.  
  252. statuslbl.grid(column=1, row=10)'''
  253.  
  254. #########################
  255.  
  256. plantlbl = Label(window, text="Plant grown : ", font=("Arial Bold", 30))
  257.  
  258. plantlbl.grid(column=0, row=12)
  259.  
  260. plant2lbl = Label(window, text=" Lettuce ", font=("Arial bold", 20),bg="darkolivegreen2",fg="black")
  261.  
  262. plant2lbl.grid(column=1, row=12)
  263.  
  264. ###################################### NAMES
  265.  
  266. name = Button(window, text=" SMART GREENHOUSE HYDROPONICS", bg="darkolivegreen3", fg="black", font=("Arial Bold", 12))
  267.  
  268. name.grid(column=2, row=2)
  269. name = Button(window, text=" WITH IOT INTEGRATION ", bg="darkolivegreen3", fg="black", font=("Arial Bold", 12))
  270.  
  271. name.grid(column=2, row=3)
  272.  
  273. plantlbl = Label(window, text="Researchers: ", font=("Arial Bold", 15))
  274.  
  275. plantlbl.grid(column=2, row=4)
  276.  
  277. name = Label(window, text="Reuben Anthony Renes", font=("Arial Bold", 15))
  278.  
  279. name.grid(column=2, row=6)
  280.  
  281. name2lbl = Label(window, text="Christian Rey Ylaya", font=("Arial Bold", 15))
  282.  
  283. name2lbl.grid(column=2, row=8)
  284.  
  285. name3lbl = Label(window, text="Nikki Jimenez", font=("Arial Bold", 15))
  286.  
  287. name3lbl.grid(column=2, row=10)
  288.  
  289. clock()
  290.  
  291. window.mainloop()
  292.  
  293.  
  294. ################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement