lopy4 wakeup on change
I'm trying to figure how to wakeup a lopy4 when a float switch changes (either off-to-on or on-to-off).
import machine, time; from machine import Pin switch=Pin('P23', Pin.IN, Pin.PULL_UP) print ('switch', switch(), 'deepsleep') #read switch eg 0=on machine.pin_sleep_wakeup(pins=['P23'],mode=not switch(),enable_pull=1)#wakeup when switch changes eg 1=off machine.deepsleep()
works but feels clunky & if the switch changes state between the last line & the second last line it won't wakeup. Is there a way to detect a change other than specifying the change you expect before hand?
@kjm that’s a limitation of the ESP32 itself. There are two ways to wake up from deep sleep on pin state changes, and both require you to specify the target level.
There may be alternatives using the ULP co-processor, haven’t checked if that would actually be possible.