Deep sleep
Deep sleep is what lets an Inkplate 5V2 sketch run for months on a battery. E-Paper needs no power at all to hold the image it's showing, so the board can draw next to no current while it sleeps.
Simple deep sleep
Here's how deep sleep works:
#define uS_TO_S_FACTOR 1000000ULL // Conversion factor for micro seconds to seconds
#define TIME_TO_SLEEP 20 // How long ESP32 will be in deep sleep (in seconds)
void setup(){
// your code
///...
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); // Activate wake-up timer, wake up after 20s here
esp_deep_sleep_start(); // Put ESP32 into deep sleep. Program stops here.
}
esp_sleep_enable_timer_wakeup()
This function enables wakeup by timer.
Returns type: int
Returns value: Returns ESP error code
Function parameters:
| Type | Name | Description |
|---|---|---|
uint64_t | time_in_us | Wakeup time in microseconds. |
esp_deep_sleep_start()
This function enters deep sleep with the configured wakeup options.
Returns type: None
Wake on button press
To wake the board with the Wake button, call the ESP32 function esp_sleep_enable_ext0_wakeup() before putting it to sleep.
// Go to sleep for TIME_TO_SLEEP seconds
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
// Enable wakeup from deep sleep on GPIO 36 (wake button)
esp_sleep_enable_ext0_wakeup(GPIO_NUM_36, LOW);
// Go to sleep
esp_deep_sleep_start();
esp_sleep_enable_ext0_wakeup()
This function uses the external wakeup feature of the RTC_IO peripheral.
Returns type: int
Returns value: Returns ESP error constant
Function parameters:
| Type | Name | Description |
|---|---|---|
gpio_num_t | gpio_num | GPIO number used as a wakeup source. Only GPIOs with RTC functionality can be used. |
int | level | Input level which will trigger wakeup. |
Full examples
Full working versions of the sketches above, plus a few more ways to use deep sleep:
Inkplate5V2_Simple_Deep_Sleep.ino
This example shows how you can use the low power functionality of the Inkplate board.
Inkplate5V2_Wake_Up_Button.ino
Full example of how to implement the WAKE UP button with deep sleep on Inkplate 5V2.
Inkplate5V2_RTC_Alarm_With_Deep_Sleep.ino
This example shows how to use the RTC alarm interrupt with deep sleep.