first feature complete implementation
This commit is contained in:
parent
8723ef3c0c
commit
0e138e1c43
1 changed files with 81 additions and 16 deletions
97
gbmanager.py
97
gbmanager.py
|
@ -2,9 +2,9 @@ from machine import Pin, I2C
|
||||||
from onewire import OneWire
|
from onewire import OneWire
|
||||||
from ds18x20 import DS18X20
|
from ds18x20 import DS18X20
|
||||||
from time import sleep_ms
|
from time import sleep_ms
|
||||||
from machine_i2c_lcd import I2cLcd
|
|
||||||
from lcd_api import LcdApi
|
from lcd_api import LcdApi
|
||||||
#from pico_i2c_lcd import I2cLcd
|
from pico_i2c_lcd import I2cLcd
|
||||||
|
import _thread
|
||||||
|
|
||||||
# Relais
|
# Relais
|
||||||
relais = Pin(15, machine.Pin.OUT, value = 1)
|
relais = Pin(15, machine.Pin.OUT, value = 1)
|
||||||
|
@ -15,18 +15,34 @@ temp_sensor = DS18X20(OneWire(Pin(16)))
|
||||||
sensor_id = temp_sensor.scan()[0]
|
sensor_id = temp_sensor.scan()[0]
|
||||||
|
|
||||||
# LCD Display
|
# LCD Display
|
||||||
#i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=100000)
|
|
||||||
#lcd = I2cLcd(i2c, 0x27, 2, 16)
|
|
||||||
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
|
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
|
||||||
lcd_addr = 39
|
|
||||||
I2C_ADDR = 0x27
|
I2C_ADDR = 0x27
|
||||||
I2C_NUM_ROWS = 2
|
I2C_NUM_ROWS = 2
|
||||||
I2C_NUM_COLS = 16
|
I2C_NUM_COLS = 16
|
||||||
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
|
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
|
||||||
|
|
||||||
# Text in Zeilen
|
# Custom characters
|
||||||
line_top = 'Soll: '
|
degree = (
|
||||||
line_bot = 'Ist : '
|
0b00111,
|
||||||
|
0b00101,
|
||||||
|
0b00111,
|
||||||
|
0b00000,
|
||||||
|
0b00000,
|
||||||
|
0b00000,
|
||||||
|
0b00000,
|
||||||
|
0b00000,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Buttons
|
||||||
|
button1 = Pin(2, Pin.IN, Pin.PULL_DOWN)
|
||||||
|
button2 = Pin(3, Pin.IN, Pin.PULL_DOWN)
|
||||||
|
button3 = Pin(4, Pin.IN, Pin.PULL_DOWN)
|
||||||
|
global button1_pressed
|
||||||
|
global button2_pressed
|
||||||
|
global button3_pressed
|
||||||
|
button1_pressed = False
|
||||||
|
button2_pressed = False
|
||||||
|
button3_pressed = False
|
||||||
|
|
||||||
def ctrl_relais(active = True):
|
def ctrl_relais(active = True):
|
||||||
if active:
|
if active:
|
||||||
|
@ -35,17 +51,66 @@ def ctrl_relais(active = True):
|
||||||
else:
|
else:
|
||||||
relais.value(1)
|
relais.value(1)
|
||||||
led_onboard.off()
|
led_onboard.off()
|
||||||
|
|
||||||
|
def button_reader_thread():
|
||||||
|
global button1_pressed
|
||||||
|
global button2_pressed
|
||||||
|
global button3_pressed
|
||||||
|
while True:
|
||||||
|
if button1.value() == 1:
|
||||||
|
button1_pressed = True
|
||||||
|
if button2.value() == 1:
|
||||||
|
button2_pressed = True
|
||||||
|
if button3.value() == 1:
|
||||||
|
button3_pressed = True
|
||||||
|
sleep_ms(100)
|
||||||
|
|
||||||
|
lcd.backlight_on()
|
||||||
|
lcd.clear()
|
||||||
|
lcd.custom_char(0, degree)
|
||||||
|
|
||||||
|
temp_tgt = 28.0
|
||||||
|
temp_gap = 0.5
|
||||||
|
is_heating = False
|
||||||
|
heat_string = ""
|
||||||
|
system_on = False
|
||||||
|
system_on_string = ""
|
||||||
|
|
||||||
|
_thread.start_new_thread(button_reader_thread, ())
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
temp_sensor.convert_temp()
|
temp_sensor.convert_temp()
|
||||||
sleep_ms(750)
|
sleep_ms(750)
|
||||||
temp_curr = str(temp_sensor.read_temp(sensor_id))
|
temp_curr = temp_sensor.read_temp(sensor_id)
|
||||||
|
|
||||||
|
if button1_pressed == True:
|
||||||
|
temp_tgt -= 0.5
|
||||||
|
button1_pressed = False
|
||||||
|
if button2_pressed == True:
|
||||||
|
temp_tgt += 0.5
|
||||||
|
button2_pressed = False
|
||||||
|
if button3_pressed == True:
|
||||||
|
system_on = not system_on
|
||||||
|
button3_pressed = False
|
||||||
|
|
||||||
|
if system_on == True and temp_curr < temp_tgt - temp_gap:
|
||||||
|
is_heating = True
|
||||||
|
elif system_on == True and temp_curr > temp_tgt + temp_gap:
|
||||||
|
is_heating = False
|
||||||
|
else:
|
||||||
|
is_heating = False
|
||||||
|
ctrl_relais(is_heating)
|
||||||
|
|
||||||
|
if system_on == True:
|
||||||
|
system_on_string = "ON "
|
||||||
|
else:
|
||||||
|
system_on_string = "OFF"
|
||||||
|
|
||||||
|
if is_heating == True:
|
||||||
|
heat_string = ">H<"
|
||||||
|
else:
|
||||||
|
heat_string = " "
|
||||||
|
|
||||||
lcd.move_to(0, 0)
|
lcd.move_to(0, 0)
|
||||||
lcd.putstr(line_top + "\n" + line_bot + temp_curr + " °C")
|
lcd.putstr("ACT: {0:3.1f}".format(temp_curr) + chr(0) + "C " + heat_string +
|
||||||
sleep_ms(2000)
|
"\nTGT: {0:3.1f}".format(temp_tgt) + chr(0) + "C " + system_on_string)
|
||||||
|
|
||||||
#ctrl_relais(True)
|
|
||||||
#sleep_ms(5000)
|
|
||||||
#ctrl_relais(False)
|
|
||||||
#sleep_ms(5000)
|
|
Loading…
Reference in a new issue