esp32 - Cannot Read Pin Value After Wake on Pin

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

esp32 - Cannot Read Pin Value After Wake on Pin

Post by devnull » Fri Jun 01, 2018 11:50 am

This is what I thought would be a simple toggling of the wake pin trigger edge, but it turns out not !

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)
Initially the switch was low:

Code: Select all

door:0, edge:5, edgeMc: WAKE_HIGH
Then switch was then enabled (high):

Code: Select all

door:1, edge:4, edgeMc: WAKE_LOW
Then, without changing the switch position, it just continuously loops, apparently unable to read the value of door any more:

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

Post Reply