Skip to content

Commit

Permalink
smart mode wip
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine3000 committed Jun 12, 2023
1 parent 1536fc3 commit b083714
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 39 deletions.
4 changes: 2 additions & 2 deletions software/boot_out.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Adafruit CircuitPython 8.0.3 on 2023-02-23; Raspberry Pi Pico with rp2040
Adafruit CircuitPython 8.0.5 on 2023-03-31; Raspberry Pi Pico with rp2040
Board ID:raspberry_pi_pico
UID:E660D4A0A7364535
UID:E6614C30935A502C
6 changes: 2 additions & 4 deletions software/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,5 @@
modules.globals.time_sensor = time.time()

modules.heating_system.timer()

if modules.globals.fermenter_running:
modules.heating_system.update_target_temp(modules.globals.time_left, modules.globals.modes[modules.globals.modes_index])
modules.heating_system.heating_system(modules.globals.temp, modules.globals.temp_target, modules.globals.TEMP_MARGIN)
modules.heating_system.update_target_temp(modules.globals.time_left, modules.globals.modes[modules.globals.modes_index])
modules.heating_system.heating_system(modules.globals.temp, modules.globals.temp_target, modules.globals.TEMP_MARGIN)
2 changes: 1 addition & 1 deletion software/modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[
"Express",
[00, 01, 02],
[32, 25, 20]
[32, 29, 27]
],
[
"Tempeh (48h)",
Expand Down
11 changes: 4 additions & 7 deletions software/modules/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,12 @@ def display_screen(menu_on, manual_on, screen_index):
modules.globals.CONTENT_1_AREA.text = " Set: Timer"
modules.globals.CONTENT_5_AREA.text = modules.utilities.timer_unit(int(modules.globals.timer_hours))
elif screen_index == 3:
modules.globals.CONTENT_1_AREA.text = "I'm fermenting"
if not modules.globals.manual_on:
modules.globals.CONTENT_2_AREA.text = "in automatic mode."
else:
modules.globals.CONTENT_2_AREA.text = "in manual mode."
modules.globals.CONTENT_3_AREA.text = "Want to change?"
modules.globals.CONTENT_1_AREA.text = "Fermenting in mode"
modules.globals.CONTENT_2_AREA.text = "↳ {}".format(modules.globals.modes[modules.globals.modes_index][0])
modules.globals.CONTENT_3_AREA.text = "Want to change?"
modules.globals.CONTENT_5_AREA.text = modules.globals.bool_string
elif screen_index == 4:
modules.globals.CONTENT_1_AREA.text = "Domingo Fermenter"
modules.globals.CONTENT_2_AREA.text = modules.globals.SOFTWARE_VERSION
modules.globals.CONTENT_3_AREA.text = "domingoclub.com"
modules.globals.CONTENT_5_AREA.text = "⚙ ⚙ ⚙"
modules.globals.CONTENT_5_AREA.text = "⚙ ⚙ ⚙"
5 changes: 4 additions & 1 deletion software/modules/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def initialize():

global SOFTWARE_VERSION
SOFTWARE_VERSION = "software v0.9.8.3"
SOFTWARE_VERSION = "software v0.9.9.1"

global SENSOR

Expand Down Expand Up @@ -55,6 +55,9 @@ def initialize():
global screen_index
screen_index = 0

global total_increment
total_increment = 0

global menu_on
menu_on = False

Expand Down
25 changes: 14 additions & 11 deletions software/modules/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import board
import time
import modules.globals
import supervisor
import os


ENCODER = rotaryio.IncrementalEncoder(board.GP4, board.GP3)
Expand All @@ -30,22 +30,23 @@ def edit_handler(increment):
screen = modules.globals.SCREENS_INTRO[modules.globals.screen_index]
else:
screen = modules.globals.SCREENS_MENU[modules.globals.screen_index]
if screen == "select_mode" or screen == "change_mode":
modules.globals.modes_index += increment * 2
if screen == "select_mode":
modules.globals.modes_index += increment * 2
if modules.globals.modes_index >= len(modules.globals.modes):
modules.globals.modes_index = 0
elif modules.globals.modes_index < 0:
modules.globals.modes_index = len(modules.globals.modes) -1
else:
modules.globals.modes_index = int(modules.globals.modes_index)
if screen == "select_mode":
modules.globals.CONTENT_5_AREA.text = modules.globals.modes[modules.globals.modes_index][0]
modules.globals.CONTENT_5_AREA.text = modules.globals.modes[modules.globals.modes_index][0]
elif screen == "change_mode":
modules.globals.total_increment += increment * 2
print(modules.globals.total_increment)
if modules.globals.total_increment % 2 == 0:
modules.globals.bool_string = "Yes please"
else:
if modules.globals.modes_index % 2 == 0:
modules.globals.bool_string = "Yes please"
else:
modules.globals.bool_string = "No thanks"
modules.globals.CONTENT_5_AREA.text = modules.globals.bool_string
modules.globals.bool_string = "No thanks"
modules.globals.CONTENT_5_AREA.text = modules.globals.bool_string
elif screen == "define_temp":
update_temp_values(increment)
modules.globals.CONTENT_5_AREA.text = "{} C".format(modules.utilities.round_down(modules.globals.temp_target, 1))
Expand Down Expand Up @@ -128,6 +129,8 @@ def button_actions():
modules.globals.manual_on = False
modules.globals.edit_mode = True
modules.globals.modes_index = 0
modules.globals.temp_target = os.getenv('target_temperature')
modules.globals.timer_hours = os.getenv('timer_hours')
modules.menu.goto("select_mode", "Set!")
else:
modules.menu.goto("dashboard", "Set!")
Expand All @@ -139,4 +142,4 @@ def button_actions():
modules.globals.CONTENT_4_AREA.text = ""
modules.globals.CONTENT_5_AREA.text = ""
time.sleep(modules.globals.DELAY_ACTIONS)
modules.menu.goto(screen, "")
modules.menu.goto(screen, "")
21 changes: 12 additions & 9 deletions software/modules/heating_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def update_led(color, steps):
else: led_rewind = False
else:
led_counter = 120

if color == "red":
color_red = (led_counter, 0, 0, 0)
LED.color = color_red if LED_MODEL == "onboard" else LED.fill(color_red)
Expand All @@ -88,8 +88,8 @@ def update_led(color, steps):
elif color == "purple":
color_purple = (led_counter, 0, led_counter, 0)
LED.color = color_purple if LED_MODEL == "onboard" else LED.fill(color_purple)



def air_circulation(time_diff, interval, duration):
# fan on for x seconds every x seconds
Expand All @@ -111,6 +111,7 @@ def heating_system(temp, temp_target, temp_margin):
time_now = time.time()
time_diff = time_now - modules.globals.time_heater

print(modules.globals.fermenter_running)
if modules.globals.fermenter_running:
if not modules.globals.sensor_error:
if temp > temp_target + temp_margin * 2:
Expand Down Expand Up @@ -148,16 +149,17 @@ def heating_system(temp, temp_target, temp_margin):

update_status_sentence()
update_values()

else:
print('expired')
modules.globals.status_sentence = " Timer expired."
modules.globals.status_subsentence = "How did it go?"
update_led('white', 60)
HEAT.duty_cycle = 0
if temp >= modules.globals.TEMP_SAFE:
FAN.duty_cycle = modules.utilities.percent_to_duty_cycles(100)
else:
FAN.duty_cycle = 0
HEAT.duty_cycle = 0

def update_target_temp(time_left, mode):
if not modules.globals.manual_on:
Expand All @@ -166,8 +168,9 @@ def update_target_temp(time_left, mode):
for i in mode[1]:
iindex = index + 1 if index + 1 <= len(mode[1]) else index
if (mode[1][index] * 3600) < time_left_diff < (mode[1][iindex] * 3600):
# convert to percentage
modules.globals.temp_target = (mode[2][index] + mode[2][iindex]) / 2
print(modules.globals.temp_target)
# convert time to percentage
time_diff_percent = 100 * float(time_left_diff) / float((mode[1][iindex] * 3600) - (mode[1][index] * 3600))
# calculate in-between temp according to time percentage
new_tempeh_target = modules.utilities.map_range(time_diff_percent, 0, 100, mode[2][index], mode[2][iindex])
modules.globals.temp_target = modules.utilities.round_down(new_tempeh_target, 1)
index += 1

3 changes: 1 addition & 2 deletions software/modules/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if SENSOR_MODEL == "aht20":
import adafruit_ahtx0

SENSOR_I2C = busio.I2C(board.GP13, board.GP12, frequency = 30000)
SENSOR_I2C = busio.I2C(board.GP13, board.GP12)



Expand All @@ -26,4 +26,3 @@ def sensor_start():
modules.globals.SENSOR = adafruit_ahtx0.AHTx0(SENSOR_I2C)
except Exception as e:
print(e)

2 changes: 2 additions & 0 deletions software/modules/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ def timer_unit(hour):
time_unit = str(int(hour // 24)) + " days"
return time_unit

def map_range(x, in_min, in_max, out_min, out_max):
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
4 changes: 2 additions & 2 deletions software/settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
fermenter_model = "mini" # mini or lab
target_temperature = 30
timer_hours = 48
sensor_model = "aht20" # sht31d or mcp9808 or aht20
sensor_model = "sht31d" # sht31d or mcp9808 or aht20
display_orientation = "reversed" # normal or reversed
led_model = "external" # external or onboard
default_mode = "default" # default or manual
default_mode = "default" # default or manual

0 comments on commit b083714

Please sign in to comment.