Tag Archives: micropython

ESP32 DeepSleep

I have been fighting all day with an ESP32 module. It has 38 pins. Yesterday I got it to be able to get out of deep_sleep using a touch pin using MicroPython. Prior to that I was toggling the onboard LED with a touch pin. Copy the code and use it as you wish.

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

print('Entering Deep Sleep in 10 seconds.')
time.sleep(10)
print('Time is up.  Going to sleep')
machine.deepsleep()

I put in that time.sleep(10) so I could catch it while it was awake and be able to make changes to the code if needed.

TheMicroPython bin file I am using is esp32-20190113-v1.9.4-779-g5064df207.bin

I’ve decided to add some to the code.

The above code does not indicate when the ESP32 is awake unless you are reading the serial output. I decided to include an LED indicator for when the module is awake. The LED goes out when the module goes into sleep mode.

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

print('Entering Deep Sleep in 10 seconds.')
print('When the blue LED is on I am awake.')
led.value(1)
time.sleep(10)
print('Time is up.  Going to sleep')
machine.deepsleep()