Once you have hardware tested and working, and you've also got WiFi connected - its time to explore deep sleep modes. When in deep sleep, the ESP32-S2 is basically completely off, it uses a tiny amount of power just to keep track of time so you can wake up after some amount of time.

When the ESP32-S2 comes back from deep-sleep it essentially does a hard-reset and begins over from scratch, so you don't get to keep your WiFi connection active. However, its pretty fast to re-connect so as long as you are only waking up about once a minute, your battery will last a lot longer!

Good Quality Sleep

Before you go into deep sleep, make sure you shut down the E-Ink display, NeoPixels, light sensor, and speaker with the following instructions:

display.powerDown();
digitalWrite(EPD_RESET, LOW); // hardware power down mode
digitalWrite(SPEAKER_SHUTDOWN, LOW); // off
digitalWrite(NEOPIXEL_POWER, HIGH); // off

Then enter deep sleep mode with

esp_sleep_enable_timer_wakeup(1000000);
esp_deep_sleep_start();

the esp_sleep_enable_timer_wakeup(10000000); line tells the ESP32-S2 to restart in 10000000 microseconds, a.k.a 10000 milliseconds or 10 seconds

Here's an example sketch that wakes up, turns on the speaker and NeoPixels, draws a bitmap onto the EPD and then goes to sleep for one second. We use this demo to do power monitoring tests.

#include <Adafruit_ThinkInk.h>
#include <Adafruit_NeoPixel.h>
#include "magtaglogo.h"

Adafruit_NeoPixel intneo = Adafruit_NeoPixel(4, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
ThinkInk_290_Grayscale4_T5 display(EPD_DC, EPD_RESET, EPD_CS, -1, -1);

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(115200);

  pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(BUTTON_B, INPUT_PULLUP);
  pinMode(BUTTON_C, INPUT_PULLUP);
  pinMode(BUTTON_D, INPUT_PULLUP);
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  
  // Neopixel power
  pinMode(NEOPIXEL_POWER, OUTPUT);
  pinMode(SPEAKER_SHUTDOWN, OUTPUT);
  digitalWrite(NEOPIXEL_POWER, LOW); // on
  digitalWrite(SPEAKER_SHUTDOWN, HIGH); // on

  intneo.begin();
  intneo.setBrightness(50);
  intneo.fill(100, 0, 100);
  intneo.show(); 

  display.begin(THINKINK_MONO);
  display.clearBuffer();
  display.drawBitmap(0, 38, magtaglogo_mono, MAGTAGLOGO_WIDTH, MAGTAGLOGO_HEIGHT, EPD_BLACK);
  display.display();
  delay(1500);
  display.powerDown();
  digitalWrite(EPD_RESET, LOW); // hardware power down mode
  
  digitalWrite(SPEAKER_SHUTDOWN, LOW); // off
  digitalWrite(NEOPIXEL_POWER, HIGH); // off
  esp_sleep_enable_timer_wakeup(1000000);
  esp_deep_sleep_start();
}

void loop() {
}

Be sure to download the sketch including the logo header file by clicking Download Project Zip and verify that in the Arduino IDE you have both tabs:

This example will go to deep sleep for only one second, you can change that by adjusting the number in this line:

esp_sleep_enable_timer_wakeup(1000000);

When using deep sleep, the power draw drops to about 250uA. These are the approximate current uses:

  • 40uA are used by the onboard green OK LED (you can remove the LED with a soldering iron)
  • 120uA are used by the EPD in deepsleep/reset mode (we couldnt figure out how to reduce this any more but tested suggestions are welcome!)
  • 50uA are used by the 3.3V regulator
  • 10uA are used by the VBat resistor divider
  • 30uA are used by the ESP32-S2 in deep sleep
USB power will be higher than this number because under USB power, we also power the battery charger. These current draws are only for battery usage and assume you have disabled NeoPixels, speaker, and EPD.

This guide was first published on Nov 10, 2020. It was last updated on Nov 10, 2020.

This page (Arduino Sleep) was last updated on Apr 20, 2021.

Text editor powered by tinymce.