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()
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