This code should get the current value of door pin, and set the wake from deepsleep edge based on the pin value high or low and then put the device into deepsleep awaiting the trigger edge.
There is a 10K pull-down on pin 34 and the switch pulls it high.
The purpose is to wake up and sleep again each time the interrupt is triggered on a different edge.
The time.sleeps() are just to give time to view the output and should not have any other effect other than de-bouncing, but given that the esp32 startup time is 2 seconds, debouncing should not be needed.
It appears to work the first time deepsleep is fired, but thereafter door.value() always reads 0 even though the switch is closed and pulled high !
boot.py
Code: Select all
import machine as mc, time
time.sleep(1)
door = mc.Pin(34,mc.Pin.IN)
edge = 5- door.value()
edgeMc = {
5:'WAKE_HIGH',
4:'WAKE_LOW'
}[edge] or 'BAD'
print('door:{}, edge:{}, edgeMc: {}'.format(door.value(), edge, edgeMc))
door.irq(trigger = edge, wake = mc.DEEPSLEEP)
time.sleep(5)
mc.deepsleep(60000)
Code: Select all
door:0, edge:5, edgeMc: WAKE_HIGH
Code: Select all
door:1, edge:4, edgeMc: WAKE_LOW
Code: Select all
door:0, edge:5, edgeMc: WAKE_HIGH
door:0, edge:5, edgeMc: WAKE_HIGH
door:0, edge:5, edgeMc: WAKE_HIGH
door:0, edge:5, edgeMc: WAKE_HIGH
door:0, edge:5, edgeMc: WAKE_HIGH
door:0, edge:5, edgeMc: WAKE_HIGH