Simple deep sleep slideshow
What this example shows
Deep sleep is a low-power state where the ESP32 stops running your program until something wakes it up. This example draws one of three pictures, refreshes the screen, then sleeps for 20 seconds. A timer wakes the board, and it shows the next picture.
Deep sleep restarts the program from the beginning on every wake-up, so the whole sketch lives in setup() and loop() stays empty. RAM is lost during deep sleep. The picture counter is declared with RTC_DATA_ATTR, which keeps it in RTC memory so it survives. The sketch runs in 3-bit (grayscale) mode, which needs full refreshes, because partial updates rely on RAM contents that deep sleep erases.
Example code
The sketch includes three image header files. Convert three images with the Soldered Image Converter and save the results next to the sketch as picture1.h, picture2.h and picture3.h. The sketch will not compile without them. In the Arduino IDE, choose the Inkplate 10 board under Tools, Board, Inkplate Boards before you upload.
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
#if !defined(ARDUINO_INKPLATE10) && !defined(ARDUINO_INKPLATE10V2)
#error "Wrong board selection for this example, please select e-radionica Inkplate10 or Soldered Inkplate10 in the boards menu."
#endif
#include "Inkplate.h" //Include Inkplate library to the sketch
#include "driver/rtc_io.h" //ESP32 library used for deep sleep and RTC wake up pins
#include "picture1.h" //Include .h files of 3 pictures. All three pictures were converted using Inkplate Image Converter
#include "picture2.h"
#include "picture3.h"
const uint8_t *pictures[] = {picture1, picture2,
picture3}; // This array of pinters holds address of every picture in the memory,
// so we can easly select it by selecting index in array
#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)
RTC_DATA_ATTR int slide = 0;
Inkplate display(INKPLATE_3BIT); // Create an object on Inkplate library and also set library into 3 Bit mode (gray)
void setup()
{
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
display.clearDisplay(); // Clear frame buffer of display
display.image.draw(
pictures[slide], 50, 0, 1100,
825); // Display selected picture at X=50, Y=0, 1100 pixels wide and 825 pixels high
display.display(); // Refresh the screen with new picture
slide++; // Update counter for pictures. With this variable, we choose what picture is going to be displayed on
// screen
if (slide > 2)
slide = 0; // We do not have more than 3 images, so roll back to zero
// Uncomment this line if your Inkplate is older than Aug 2021 as older Inkplates have ESP32 wrover-e chips
// rtc_gpio_isolate(GPIO_NUM_12); // Isolate/disable GPIO12 on ESP32 (only to reduce power consumption in sleep)
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.
}
void loop()
{
// Nothing! If you use deep sleep, whole program should be in setup() because each time the board restarts, not in a
// loop()! loop() must be empty!
}
Trimmed from Inkplate10_Simple_Deep_Sleep.ino: the file header comment is left out. One comment that described the picture size as 800x600 pixels is reworded to match the image.draw() call (1100 x 825 at X=50). The code is otherwise unchanged.
Functions used
Inkplate(uint8_t mode)returns NoneCreates the Inkplate object and chooses the display mode. `INKPLATE_1BIT` is black and white and supports partial updates. `INKPLATE_3BIT` is grayscale and only supports full updates.
ReturnsConstructor; no return value.
Parameters
| Type | Name | Description |
|---|---|---|
uint8_t | mode | Display mode: INKPLATE_1BIT (0) or INKPLATE_3BIT (1). |
display.begin()returns voidInitializes the library, the peripherals and the frame buffers. Call it once in `setup()`, later calls are ignored.
ReturnsNothing.
display.clearDisplay()returns voidClears the frame buffer in memory. It does not clear the panel itself, call `display()` afterwards to do that.
ReturnsNothing.
display.image.draw(const uint8_t *buf, int x, int y, int16_t w, int16_t h, uint8_t c = 1, uint8_t bg = 0xFF)returns boolDraws an image stored as an array in memory, such as a header file made with the image converter. In 3-bit mode it draws the array as a grayscale bitmap.
Returns`1` if the image was drawn, `0` if not.
Parameters
| Type | Name | Description |
|---|---|---|
const uint8_t * | buf | Pointer to the image array. |
int | x | X position of the upper left corner of the image. |
int | y | Y position of the upper left corner of the image. |
int16_t | w | Image width in pixels. |
int16_t | h | Image height in pixels. |
uint8_t | c | Image color, used in 1-bit mode. Defaults to 1. |
uint8_t | bg | Background color, used in 1-bit mode. The default 0xFF means no background is drawn. |
display.display(bool _leaveOn = 0)returns voidRefreshes the whole panel from the frame buffer (a full update).
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
bool | _leaveOn | If true, the e-paper supply stays on after the update, which saves time on the next update. Defaults to 0. |
esp_sleep_enable_timer_wakeup(uint64_t time_in_us)returns esp_err_tSets a timer that wakes the ESP32 from deep sleep. It comes from the ESP32 Arduino core, not from the Inkplate library.
ReturnsError code, not checked by the sketch.
Parameters
| Type | Name | Description |
|---|---|---|
uint64_t | time_in_us | Time until wake-up, in microseconds. The sketch multiplies seconds by uS_TO_S_FACTOR (1000000). |
esp_deep_sleep_start()returns voidPuts the ESP32 into deep sleep. The program stops here, and on wake-up it starts again from the beginning of `setup()`. It comes from the ESP32 Arduino core, not from the Inkplate library.
ReturnsDoes not return.
What to expect
The board shows the first picture, goes to deep sleep, and wakes up every 20 seconds. Each wake-up shows the next picture and loops back to the first after the third. The sketch does not use Serial.
Older boards
The sketch contains a commented-out rtc_gpio_isolate(GPIO_NUM_12) line. Its comment says to uncomment it if your Inkplate is older than August 2021, because older boards have an ESP32 WROVER-E chip. It only reduces power consumption during sleep.