• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

How to know which pin wake up the ESP32 from deepsleep.

Q&A Forum › Category: ESP32 › How to know which pin wake up the ESP32 from deepsleep.
0 Vote Up Vote Down
ongone93 asked 6 years ago

Hi Everyone,

I’m actually working on a project involving many imputs. I try to use the deepsleep mode of the ESP32 with Microphyton. I used the external wake up ext1(esp32.WAKEUP_ANY_HIGH) to enable the esp32 to wake up if any of the inputs goes high. I did try the code provided by Ruis in one of the project. I changed it a bit to  figure out which pin wake up the esp32.

I used two differents led to find out which pins wake up the microcontroller. The code is working but if anyone has a more Pythonic and less tedious code. Please share with us.

Here is my code:

import machine
import esp32
from machine import Pin
from time import sleep
wake1 = Pin(32, mode = Pin.IN)
wake2 = Pin(25, mode = Pin.IN)
red_led = Pin(13, Pin.OUT)
green_led = Pin(12, Pin.OUT)
string_value = "I'm going back to sleep.I'll wake up at the next external wake up"
esp32.wake_on_ext1(pins = (wake1, wake2), level = esp32.WAKEUP_ANY_HIGH)

Code:

import machine
import esp32
from machine import Pin
from time import sleep

wake1 = Pin(32, mode = Pin.IN)
wake2 = Pin(25, mode = Pin.IN)
#Pin_notification = wake2 = Pin(33, mode = Pin.IN)
red_led = Pin(13, Pin.OUT)
green_led = Pin(12, Pin.OUT)

string_value = "I'm going back to sleep.I'll wake up at the next external wake up"

#level parameter can be: esp32.WAKEUP_ANY_HIGH or esp32.WAKEUP_ALL_LOW
esp32.wake_on_ext1(pins = (wake1, wake2), level = esp32.WAKEUP_ANY_HIGH)


while True:
    if wake1.value() == 1 :
        print("Wake1 has been tripped")
        for x in range(5):
            red_led.value(1)
            sleep(0.5)
            red_led.value(0)
            sleep(0.5)
        print(string_value)
        break
    elif wake2.value() == 1:
        print("The second switch has been tripped")
        for x in range(5):
            green_led.value(1)
            sleep(0.5)
            green_led.value(0)
            sleep(0.5)
        print(string_value)
        break
    else:
        pass

print("I'm Off")

machine.deepsleep()
1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi.

Thank you for sharing your code.

In MicroPython, I still haven’t found a way to return the GPIO that caused the wake up as in Arduino IDE.
In Arduino IDE, you can call a function that returns the GPIO that caused the wake up. In MicroPython, I think that isn’t implemented yet (someone correct me if I’m wrong).

If anyone knows another way to detect the GPIO that caused the wake up, please share.

Regards,

Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.