at the risk of posting this to the wrong topic, I'm looking for some
help if possible - and I'm not able to create my own topic for some reason.
I have started working with micropython fairly recently, so please forgive my ignorance. I'm trying to implement something similar to matty trentini's uasyncio encoder example (https://gist.github.com/mattytrentini/1 ... b0a4284de9
More precisely, I'd like to do the following:
1) Use an encoder to change and set (with button push) a specific temperature (let's call it target temperature)
2) Use a DHT22 (and later potentially a thermocouple) to monitor the current temp
3) Alert (either with led, buzzer, etc to the fact that the target temp was reached)
4) Display information on an OLED
I understand that the encoder function and the temperature measurements have to run simultaneously for this to work - this is where
Here is what I have so far
Code: Select all
from machine import Pin, I2C
from rotary_irq_esp import RotaryIRQ
sensor = dht.DHT22(Pin(14))
r = RotaryIRQ(pin_num_clk=12,
led = machine.Pin(2, Pin.OUT)
async def blink(led):
async def encoder(r):
val_old = r.value()*0.5
val_new = r.value()*(0.5)
if val_old != val_new:
val_old = val_new
print('result =', val_new)
async def sensor_measure(sensor):
temp = sensor.temperature()
print('Temperature: %3.1f C' %temp)
loop = uasyncio.get_event_loop()
# this is now all running at the same time!!! progress!!
Display is not implemented yet. It seems to work BUT everything is running on an endless loop and the editor is showing me an infinite loop of constant temp measurements, which can be interrupted by turning the encoder. What I would like to happen is for the temperature measurements to happen and then when I turn the encoder the value shows up. Do I have to save the temp measurements in a list or variable to be able to compare to the target temperature?
Any help would be greatly appreciated here!