Skip to content

Commit cd26220

Browse files
authored
fix(example): EXT0 and EXT1 wakeup
Fixes the Deep Sleep wakup example to run with IDF5.1. The API has changed and a adjustment was necessary.
1 parent b77b38e commit cd26220

File tree

1 file changed

+51
-35
lines changed

1 file changed

+51
-35
lines changed

libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
/*
2-
Deep Sleep with External Wake Up
3-
=====================================
4-
This code displays how to use deep sleep with
5-
an external trigger as a wake up source and how
6-
to store data in RTC memory to use it over reboots
7-
8-
This code is under Public Domain License.
9-
10-
Hardware Connections
11-
======================
12-
Push Button to GPIO 33 pulled down with a 10K Ohm
13-
resistor
14-
15-
NOTE:
16-
======
17-
Only RTC IO can be used as a source for external wake
18-
source. They are pins: 0,2,4,12-15,25-27,32-39.
19-
20-
Author:
21-
Pranav Cherukupalli <cherukupallip@gmail.com>
2+
Deep Sleep with External Wake Up
3+
=====================================
4+
This code displays how to use deep sleep with
5+
an external trigger as a wake up source and how
6+
to store data in RTC memory to use it over reboots
7+
8+
This code is under Public Domain License.
9+
10+
Hardware Connections
11+
======================
12+
Push Button to GPIO 33 pulled down with a 10K Ohm
13+
resistor
14+
15+
NOTE:
16+
======
17+
Only RTC IO can be used as a source for external wake
18+
source. They are pins: 0,2,4,12-15,25-27,32-39.
19+
20+
Author:
21+
Pranav Cherukupalli <cherukupallip@gmail.com>
2222
*/
23+
#include "driver/rtc_io.h"
2324

24-
#define BUTTON_PIN_BITMASK 0x200000000 // 2^33 in hex
25-
25+
#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex
26+
#define USE_EXT0_WAKEUP 1 // 1 = EXT0 wakeup, 0 = EXT1 wakeup
2627
RTC_DATA_ATTR int bootCount = 0;
2728

2829
/*
29-
Method to print the reason by which ESP32
30-
has been awaken from sleep
30+
Method to print the reason by which ESP32
31+
has been awaken from sleep
3132
*/
3233
void print_wakeup_reason() {
3334
esp_sleep_wakeup_cause_t wakeup_reason;
@@ -56,20 +57,35 @@ void setup() {
5657
print_wakeup_reason();
5758

5859
/*
59-
First we configure the wake up source
60-
We set our ESP32 to wake up for an external trigger.
61-
There are two types for ESP32, ext0 and ext1 .
62-
ext0 uses RTC_IO to wakeup thus requires RTC peripherals
63-
to be on while ext1 uses RTC Controller so does not need
64-
peripherals to be powered on.
65-
Note that using internal pullups/pulldowns also requires
66-
RTC peripherals to be turned on.
60+
First we configure the wake up source
61+
We set our ESP32 to wake up for an external trigger.
62+
There are two types for ESP32, ext0 and ext1 .
63+
ext0 uses RTC_IO to wakeup thus requires RTC peripherals
64+
to be on while ext1 uses RTC Controller so does not need
65+
peripherals to be powered on.
66+
Note that using internal pullups/pulldowns also requires
67+
RTC peripherals to be turned on.
6768
*/
69+
#if USE_EXT0_WAKEUP
6870
esp_sleep_enable_ext0_wakeup(GPIO_NUM_33, 1); //1 = High, 0 = Low
69-
71+
// Configure pullup/downs via RTCIO to tie wakeup pins to inactive level during deepsleep.
72+
// EXT0 resides in the same power domain (RTC_PERIPH) as the RTC IO pullup/downs.
73+
// No need to keep that power domain explicitly, unlike EXT1.
74+
rtc_gpio_pullup_dis(GPIO_NUM_33);
75+
rtc_gpio_pulldown_en(GPIO_NUM_33);
76+
77+
#else // EXT1 WAKEUP
7078
//If you were to use ext1, you would use it like
71-
//esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ANY_HIGH);
72-
79+
esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(GPIO_NUM_33), ESP_EXT1_WAKEUP_ANY_HIGH);
80+
/*
81+
If there are no external pull-up/downs, tie wakeup pins to inactive level with internal pull-up/downs via RTC IO
82+
during deepsleep. However, RTC IO relies on the RTC_PERIPH power domain. Keeping this power domain on will
83+
increase some power comsumption. However, if we turn off the RTC_PERIPH domain or if certain chips lack the RTC_PERIPH
84+
domain, we will use the HOLD feature to maintain the pull-up and pull-down on the pins during sleep.
85+
*/
86+
rtc_gpio_pulldown_en(GPIO_NUM_33); // GPIO33 is tie to GND in order to wake up in HIGH
87+
rtc_gpio_pullup_dis(GPIO_NUM_33); // Disable PULL_UP in order to allow it to wakeup on HIGH
88+
#endif
7389
//Go to sleep now
7490
Serial.println("Going to sleep now");
7591
esp_deep_sleep_start();

0 commit comments

Comments
 (0)