-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Deep Sleep Example Fix #9904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Deep Sleep Example Fix #9904
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
/* | ||
Deep Sleep with External Wake Up | ||
===================================== | ||
This code displays how to use deep sleep with | ||
an external trigger as a wake up source and how | ||
to store data in RTC memory to use it over reboots | ||
|
||
This code is under Public Domain License. | ||
|
||
Hardware Connections | ||
====================== | ||
Push Button to GPIO 33 pulled down with a 10K Ohm | ||
resistor | ||
|
||
NOTE: | ||
====== | ||
Only RTC IO can be used as a source for external wake | ||
source. They are pins: 0,2,4,12-15,25-27,32-39. | ||
|
||
Author: | ||
Pranav Cherukupalli <[email protected]> | ||
Deep Sleep with External Wake Up | ||
===================================== | ||
This code displays how to use deep sleep with | ||
an external trigger as a wake up source and how | ||
to store data in RTC memory to use it over reboots | ||
|
||
This code is under Public Domain License. | ||
|
||
Hardware Connections | ||
====================== | ||
Push Button to GPIO 33 pulled down with a 10K Ohm | ||
resistor | ||
|
||
NOTE: | ||
====== | ||
Only RTC IO can be used as a source for external wake | ||
source. They are pins: 0,2,4,12-15,25-27,32-39. | ||
|
||
Author: | ||
Pranav Cherukupalli <[email protected]> | ||
*/ | ||
#include "driver/rtc_io.h" | ||
|
||
#define BUTTON_PIN_BITMASK 0x200000000 // 2^33 in hex | ||
|
||
#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex | ||
#define USE_EXT0_WAKEUP 1 // 1 = EXT0 wakeup, 0 = EXT1 wakeup | ||
#define WAKEUP_GPIO GPIO_NUM_33 // Only RTC GPIO are allowed - this is a ESP32 example | ||
RTC_DATA_ATTR int bootCount = 0; | ||
|
||
/* | ||
Method to print the reason by which ESP32 | ||
has been awaken from sleep | ||
Method to print the reason by which ESP32 | ||
has been awaken from sleep | ||
*/ | ||
void print_wakeup_reason() { | ||
esp_sleep_wakeup_cause_t wakeup_reason; | ||
|
@@ -56,20 +58,35 @@ void setup() { | |
print_wakeup_reason(); | ||
|
||
/* | ||
First we configure the wake up source | ||
We set our ESP32 to wake up for an external trigger. | ||
There are two types for ESP32, ext0 and ext1 . | ||
ext0 uses RTC_IO to wakeup thus requires RTC peripherals | ||
to be on while ext1 uses RTC Controller so does not need | ||
peripherals to be powered on. | ||
Note that using internal pullups/pulldowns also requires | ||
RTC peripherals to be turned on. | ||
First we configure the wake up source | ||
We set our ESP32 to wake up for an external trigger. | ||
There are two types for ESP32, ext0 and ext1 . | ||
ext0 uses RTC_IO to wakeup thus requires RTC peripherals | ||
to be on while ext1 uses RTC Controller so does not need | ||
peripherals to be powered on. | ||
Note that using internal pullups/pulldowns also requires | ||
RTC peripherals to be turned on. | ||
*/ | ||
esp_sleep_enable_ext0_wakeup(GPIO_NUM_33, 1); //1 = High, 0 = Low | ||
|
||
#if USE_EXT0_WAKEUP | ||
esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1); //1 = High, 0 = Low | ||
// Configure pullup/downs via RTCIO to tie wakeup pins to inactive level during deepsleep. | ||
// EXT0 resides in the same power domain (RTC_PERIPH) as the RTC IO pullup/downs. | ||
// No need to keep that power domain explicitly, unlike EXT1. | ||
rtc_gpio_pullup_dis(WAKEUP_GPIO); | ||
rtc_gpio_pulldown_en(WAKEUP_GPIO); | ||
|
||
#else // EXT1 WAKEUP | ||
//If you were to use ext1, you would use it like | ||
//esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ANY_HIGH); | ||
|
||
esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH); | ||
/* | ||
If there are no external pull-up/downs, tie wakeup pins to inactive level with internal pull-up/downs via RTC IO | ||
during deepsleep. However, RTC IO relies on the RTC_PERIPH power domain. Keeping this power domain on will | ||
increase some power comsumption. However, if we turn off the RTC_PERIPH domain or if certain chips lack the RTC_PERIPH | ||
domain, we will use the HOLD feature to maintain the pull-up and pull-down on the pins during sleep. | ||
*/ | ||
rtc_gpio_pulldown_en(WAKEUP_GPIO); // GPIO33 is tie to GND in order to wake up in HIGH | ||
rtc_gpio_pullup_dis(WAKEUP_GPIO); // Disable PULL_UP in order to allow it to wakeup on HIGH | ||
#endif | ||
//Go to sleep now | ||
Serial.println("Going to sleep now"); | ||
esp_deep_sleep_start(); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.