← index #4060PR #16883
Related · medium · value 2.176
QUERY · ISSUE

ESP32 module wake on touch, wake on ext1

openby tahouseopened 2018-08-17updated 2019-05-28
port-esp32

Hi there,

I'm running MicroPython v1.9.4-409-g434975def and have successfully used a Pin irq to wake from deep sleep and can confirm the wake reason:

import machine
from machine import Pin, TouchPad, deepsleep
import time

wake = Pin(14, mode = Pin.IN, pull = Pin.PULL_DOWN)
wake.irq(trigger=Pin.WAKE_HIGH, wake = machine.DEEPSLEEP)

time.sleep(5)
deepsleep(5*1000)

after bringing Pin 14 line up to 3V3

Reset cause:  DEEPSLEEP_RESET
Wake reason:  PIN_WAKE/EXT0_WAKE

Now I'm trying to do the same but with a TouchPad input:


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

wake = Pin(14, mode = Pin.IN)
touch = TouchPad(wake)
touch.config(500)
esp32.wake_on_touch(True)

time.sleep(5)
deepsleep(5*1000)

(after 5 seconds and touching/untouching wire to Pin 14)

Reset cause:  DEEPSLEEP_RESET
Wake reason:  TIMER_WAKE

The range of my touch.read() values are around 700 when untouched, and down to around 100 when touched. I've tried adjusting the touch.config to various settings but I cannot get my ESP32 to wake from touch.. only from timer in this mode.

Lastly,
I've tried using wake_on_ext1

import machine
from machine import Pin, TouchPad
import time
import esp32
wake = Pin(14, mode = Pin.IN, pull = Pin.PULL_DOWN)
esp32.wake_on_ext1(pins = [wake], level = Pin.WAKE_HIGH)

time.sleep(5)
deepsleep(5*1000)

But this resets immediately regardless of whether I bring Pin 14 high or not (not in touch mode, mind you).

Reset cause:  DEEPSLEEP_RESET
Wake reason:  EXT1_WAKE

I've browsed through the esp32 module code, but I'm not sure if any of the wake modes work?

Any ideas?

CANDIDATE · PULL REQUEST

Support wakeup gpio source of ESP32C3 and I was tuned wakeup source one by one each soc.

closedby pop-aruaruopened 2025-03-09updated 2025-03-09

<!-- Thanks for submitting a Pull Request! We appreciate you spending the
time to improve MicroPython. Please provide enough information so that
others can review your Pull Request.

 Before submitting, please read:
 https://github.com/micropython/micropython/blob/master/CODEOFCONDUCT.md
 https://github.com/micropython/micropython/wiki/ContributorGuidelines

 Please check any CI failures that appear after your Pull Request is opened.

-->

Summary

I was add deepsleep wakeup by gpio on ESP32C3.

new function and const in esp32 module:

  • wake_on_gpio([machine.Pin],level])

level

  • WAKEUP_GPIO_HIGH
  • WAKEUP_GPIO_LOW

almost same esp32.wake_on_ext1 and esp32.wake_on_ext0

And I was tuned struct machine_rtc_config_t in machine_rtc.h file by soc selector in ports/esp32:

  • SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
  • SOC_PM_SUPPORT_EXT0_WAKEUP
  • SOC_PM_SUPPORT_EXT1_WAKEUP
  • SOC_ULP_SUPPORTED
  • SOC_TOUCH_SENSOR_SUPPORTED

And I also changed some files that came with it.

Testing

  • build test:
    build-ESP32_GENERIC
    build-ESP32_GENERIC_C3
    build-ESP32_GENERIC_C6
    build-ESP32_GENERIC_S2
    build-ESP32_GENERIC_S3

ESP_IDF_VERSION=5.2
on MAC-OS

  • deepsleep wakeup test:
    ESP32_GENERIC_C3 on seeed xiao-esp32c3

test micropython code

import time
import time
import esp32
from machine import Pin,deepsleep,PWM

pwm = PWM(5,freq=50)
hz0=400
pwm.duty_u16(0x800)
pwm.freq(hz0)
time.sleep(10) # you can connect while 10sec.
a=Pin(2,Pin.IN,pull=Pin.PULL_UP,hold=True)
b=Pin(3,Pin.IN,pull=Pin.PULL_UP,hold=True)
c=Pin(4,Pin.IN,pull=Pin.PULL_UP,hold=True)
esp32.wake_on_gpio([b,c],esp32.WAKEUP_GPIO_HIGH)
esp32.wake_on_gpio([a],esp32.WAKEUP_GPIO_LOW)
deepsleep(60_000) # 60sec
# deepsleep() # forever 

Trade-offs and Alternatives

Depending on the soc feature, the functions and constants available to the micropython esp32 module change.
Therefore, the python code becomes more device-dependent.

<!-- If the Pull Request has some negative impact (i.e. increased code size)
then please explain why you think the trade-off improvement is worth it.
If you can think of alternative ways to do this, please explain that here too.

 Delete this heading if not relevant (i.e. small fixes) -->

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied