I find myself in a situation where this is to expensive, in terms of time, to execute:
There is only need to check temperature every 2 sec or so, however, during the 750ms above the ESP32 needs to be reading values from an ADC and making decisions based on this every 100ms ---- I.E. The program cannot wait around for 750ms.import time, ds18x20
ds = ds18x20.DS18X20(ow)
roms = ds.scan()
ds.convert_temp()
time.sleep_ms(750)
for rom in roms:
print(ds.read_temp(rom))
Would it be possible to use timer based callbacks to initiate scanning, and another to read values 750ms later? Perhaps an expert would consider the code below and let me know what's wrong with it?
I only expect a stock of DS18B20's to arrive in the next few days. Help in the interim would be greatly appreciated.import time, ds18x20
from machine import Timer
ds = ds18x20.DS18X20(ow)
def (scan_ow):
global roms
roms = ds.scan()
ds.convert_temp()
tim.init(period=750, mode=Timer.ONE_SHOT, callback=read_ow)
def (read_ow):
global roms
for rom in roms:
print(ds.read_temp(rom))
tim = Timer(-1)
tim.init(period=1000, mode=Timer.PERIODIC, callback=scan_ow)
I = 0
latest_temp = 0
roms = 0
while True:
# Do other import stuff...
# ...like count to infinity...
pass
pass
pass
pass
pass
time.sleep_ms(1000)
print (I)
I = I + 1