1515import adafruit_touchscreen
1616from adafruit_mcp9600 import MCP9600
1717
18+ TITLE = "EZ Make Oven Controller"
1819VERSION = "0.1"
1920
21+ print (TITLE , "version " , VERSION )
22+ time .sleep (2 )
23+
2024display_group = displayio .Group (max_size = 20 )
2125board .DISPLAY .show (display_group )
2226
@@ -100,12 +104,16 @@ def __init__(self, pin):
100104 with open ("/config.json" , mode = "r" ) as fpr :
101105 self .config = json .load (fpr )
102106 fpr .close ()
107+ self .sensor_status = False
103108 with open ("/profiles/" + self .config ["profile" ] + ".json" , mode = "r" ) as fpr :
104109 self .sprofile = json .load (fpr )
105110 fpr .close ()
106111 i2c = busio .I2C (board .SCL , board .SDA , frequency = 100000 )
107112 try :
108113 self .sensor = MCP9600 (i2c , self .config ["sensor_address" ], "K" )
114+ self .ontemp = self .sensor .temperature
115+ self .offtemp = self .ontemp
116+ self .sensor_status = True
109117 except ValueError :
110118 print ("temperature sensor not available" )
111119 self .ontime = 0
@@ -145,6 +153,8 @@ def check_state(self):
145153 temp = self .sensor .temperature
146154 except AttributeError :
147155 temp = 32 # sensor not available, use 32 for testing
156+ self .sensor_status = False
157+ # message.text = "Temperature sensor missing"
148158 self .beep .refresh ()
149159 if self .state == "wait" :
150160 self .enable (False )
@@ -205,20 +215,30 @@ def check_state(self):
205215 checkoven = True
206216 break
207217 checktime += 5
218+ if not checkoven :
219+ # hold oven temperature
220+ if self .state in ("start" , "preheat" , "soak" ) and self .offtemp > self .sensor .temperature :
221+ checkoven = True
208222 self .enable (checkoven )
209223
210224 # turn oven on or off
211225 def enable (self , enable ):
212- self .oven .value = enable
213- self .control = enable
214- if enable :
215- self .offtime = 0
216- self .ontime = time .monotonic ()
217- print ("oven on" )
218- else :
219- self .offtime = time .monotonic ()
220- self .ontime = 0
221- print ("oven off" )
226+ try :
227+ self .oven .value = enable
228+ self .control = enable
229+ if enable :
230+ self .offtime = 0
231+ self .ontime = time .monotonic ()
232+ self .ontemp = self .sensor .temperature
233+ print ("oven on" )
234+ else :
235+ self .offtime = time .monotonic ()
236+ self .ontime = 0
237+ self .offtemp = self .sensor .temperature
238+ print ("oven off" )
239+ except AttributeError :
240+ # bad sensor
241+ pass
222242
223243class Graph (object ):
224244 def __init__ (self ):
@@ -401,15 +421,15 @@ def format_time(seconds):
401421label_reflow .x = 0
402422label_reflow .y = - 20
403423pyportal .splash .append (label_reflow )
404- title_label = label .Label (font3 , text = "EZ Make Oven Controller" )
424+ title_label = label .Label (font3 , text = TITLE )
405425title_label .x = 5
406426title_label .y = 14
407427pyportal .splash .append (title_label )
408428# version_label = label.Label(font1, text=VERSION, color=0xAAAAAA)
409429# version_label.x = 300
410430# version_label.y = 40
411431# pyportal.splash.append(version_label)
412- message = label .Label (font2 , text = "Wait" , max_glyphs = 20 )
432+ message = label .Label (font2 , text = "Wait" , max_glyphs = 30 )
413433message .x = 100
414434message .y = 40
415435pyportal .splash .append (message )
@@ -462,9 +482,10 @@ def format_time(seconds):
462482print ("y range:" , sgraph .ymin , sgraph .ymax )
463483draw_profile (sgraph , oven .sprofile )
464484buttons = []
465- button = Button (x = 0 , y = 200 , width = 80 , height = 40 ,
466- label = "Start" , label_font = font2 )
467- buttons .append (button )
485+ if oven .sensor_status :
486+ button = Button (x = 0 , y = 200 , width = 80 , height = 40 ,
487+ label = "Start" , label_font = font2 )
488+ buttons .append (button )
468489
469490for b in buttons :
470491 pyportal .splash .append (b .group )
@@ -482,6 +503,8 @@ def format_time(seconds):
482503 oven_temp = int (oven .sensor .temperature )
483504 except AttributeError :
484505 oven_temp = 32 # testing
506+ oven .sensor_status = False
507+ message .text = "Bad/missing temp sensor"
485508 if oven .control != last_control :
486509 last_control = oven .control
487510 if oven .control :
@@ -503,46 +526,47 @@ def format_time(seconds):
503526 message .text = "Wait"
504527 button .label = "Wait"
505528 oven .set_state ("wait" )
506- if oven .state == "ready" :
507- status = "Ready"
508- if last_state != "ready" :
509- oven .beep .refresh ()
510- draw_profile (sgraph , oven .sprofile )
511- timer_data .text = format_time (0 )
512- if button .label != "Start" :
513- button .label = "Start"
514- if oven .state == "start" :
515- status = "Starting"
516- if last_state != "start" :
517- timer = time .monotonic ()
518- if oven .state == "preheat" :
519- if last_state != "preheat" :
520- timer = time .monotonic () # reset timer when preheat starts
521- status = "Preheat"
522- if oven .state == "soak" :
523- status = "Soak"
524- if oven .state == "reflow" :
525- status = "Reflow"
526- if oven .state == "cool" or oven .state == "wait" :
527- status = "Cool Down, Open Door"
528- if last_status != status :
529- message .text = status
530- last_status = status
531-
532- if oven_temp != last_temp :
533- last_temp = oven_temp
534- temp_data .text = str (oven_temp )
535- # update once per second when oven is active
536- if oven .state != "ready" and time .monotonic () - second_timer >= 1.0 :
537- second_timer = time .monotonic ()
538- oven .check_state ()
539- if oven .state == "preheat" and last_state != "preheat" :
540- timer = time .monotonic () # reset timer at start of preheat
541- timediff = int (time .monotonic () - timer )
542- timer_data .text = format_time (timediff )
543- print (oven .state )
544- if oven_temp >= 50 :
545- sgraph .draw_graph_point (int (timediff ), oven_temp ,
546- size = TEMP_SIZE , color = 3 )
547-
548- last_state = oven .state
529+ if oven .sensor_status :
530+ if oven .state == "ready" :
531+ status = "Ready"
532+ if last_state != "ready" :
533+ oven .beep .refresh ()
534+ draw_profile (sgraph , oven .sprofile )
535+ timer_data .text = format_time (0 )
536+ if button .label != "Start" :
537+ button .label = "Start"
538+ if oven .state == "start" :
539+ status = "Starting"
540+ if last_state != "start" :
541+ timer = time .monotonic ()
542+ if oven .state == "preheat" :
543+ if last_state != "preheat" :
544+ timer = time .monotonic () # reset timer when preheat starts
545+ status = "Preheat"
546+ if oven .state == "soak" :
547+ status = "Soak"
548+ if oven .state == "reflow" :
549+ status = "Reflow"
550+ if oven .state == "cool" or oven .state == "wait" :
551+ status = "Cool Down, Open Door"
552+ if last_status != status :
553+ message .text = status
554+ last_status = status
555+
556+ if oven_temp != last_temp and oven .sensor_status :
557+ last_temp = oven_temp
558+ temp_data .text = str (oven_temp )
559+ # update once per second when oven is active
560+ if oven .state != "ready" and time .monotonic () - second_timer >= 1.0 :
561+ second_timer = time .monotonic ()
562+ oven .check_state ()
563+ if oven .state == "preheat" and last_state != "preheat" :
564+ timer = time .monotonic () # reset timer at start of preheat
565+ timediff = int (time .monotonic () - timer )
566+ timer_data .text = format_time (timediff )
567+ print (oven .state )
568+ if oven_temp >= 50 :
569+ sgraph .draw_graph_point (int (timediff ), oven_temp ,
570+ size = TEMP_SIZE , color = 3 )
571+
572+ last_state = oven .state
0 commit comments