ESP32: get which EXT1 pin caused wake

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: ESP32: get which EXT1 pin caused wake

Post by karfas » Sun Oct 17, 2021 7:23 am

@roberthh: This is great!
I propose to wait a week or so to collect some more opinions and then create a PR from your code.
For me, a tuple of pin numbers looks sufficient.

@sergei.nz: I don't care about convenience. A few lines of more user code to decode the bitmap is better than not having this information at all. My arguments were about consistency of the interface. The current micropython docs mention the term "bitmap" exactly twice (for memory management and some framebuffer function), so it just felt ugly/wrong for me to return the bitmap to users.
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: ESP32: get which EXT1 pin caused wake

Post by karfas » Sat Nov 06, 2021 9:38 am

karfas wrote:
Sun Oct 17, 2021 7:23 am
I propose to wait a week or so to collect some more opinions and then create a PR from your code.
@roberthh: is it OK for you when I create the PR and documentation change ?
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP32: get which EXT1 pin caused wake

Post by Roberthh » Sat Nov 06, 2021 10:37 am

Sure.

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: ESP32: get which EXT1 pin caused wake

Post by karfas » Sun Nov 14, 2021 10:43 am

A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: ESP32: get which EXT1 pin caused wake

Post by karfas » Sun Feb 27, 2022 6:14 pm

karfas wrote:
Sun Nov 14, 2021 10:43 am
New PR is in https://github.com/micropython/micropython/pull/7990
The PR is ready, tested and works (both GPIOs 2+4 connected to the same button):

Code: Select all

>>> import main1
Reset: Wakeup from deep sleep
wakeup_reason(): (2, 4)
Going to sleep
My test program:

Code: Select all

import machine
from machine import Pin, TouchPad
import time
import esp32
import esp

if machine.reset_cause() == machine.DEEPSLEEP_RESET:
    print("Reset: Wakeup from deep sleep")
else:
    print("Reset: Other reason")

print("wakeup_reason(): {}".format(machine.wake_ext1_pins()))

pin4 = Pin(4, mode = Pin.IN, pull = Pin.PULL_DOWN)
wake = Pin(2, mode = Pin.IN, pull = Pin.PULL_DOWN)
esp32.wake_on_ext1(pins = [wake,pin4], level = Pin.WAKE_HIGH)

time.sleep(2)
print('Going to sleep')
machine.deepsleep()
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

bwyld
Posts: 7
Joined: Tue Oct 19, 2021 3:03 pm

Re: ESP32: get which EXT1 pin caused wake

Post by bwyld » Tue Sep 05, 2023 2:40 pm

Just wondered if anyone had tested this with lightsleep() and/or on an ESP32S3?
I am having some difficulty using gpios to wake from light sleep and call the irq() callback associated with the pin.

Post Reply