🛠 Power Optimization with Deep Sleep and RTC Wake-up on ToughC5

M5Stack ToughC5 Weatherproof IoT Dev Kit (ESP32-C5) · avance · Configurez le mode veille profonde du M5Stack ToughC5 pour atteindre une consommation de 10,41 µA tout en garantissant un réveil précis grâce au RTC RX8130CE.

Objectifs

In outdoor IoT deployments powered by batteries, every microampere counts. This advanced tutorial aims to configure the M5Stack ToughC5 to minimize standby power consumption while ensuring precise timing via the RX8130CE RTC module. We will learn to disable non-essential interfaces (Wi-Fi, BLE, display) and program a precise periodic wake-up.

Required Hardware

Steps

Ensure your M5Stack library is up to date. For advanced mode, it is often preferable to use low-level functions or verify that standard libraries do not keep clocks active. ``cpp #include <M5ToughC5.h> #include <RTC.h> // Specific library for RX8130CE ``

  1. Development Environment Configuration

Before sleeping, save necessary state in retained RAM (RTC memory) if available, or in Flash if data must persist after total power loss. Configure the RTC for a future wake-up. ```cpp void setup() { M5.begin(); // Initialize RX8130CE RTC Rtc.begin(); // Turn off ILI9342C display to save power M5.Display.setBrightness(0); M5.Display.sleep();

  1. RTC Initialization and GPIO Preparation

// Disable radio interfaces (Wi-Fi/BLE) WiFi.mode(WIFI_OFF); BLEDevice::deinit(true);

// Configure a GPIO pin as external wake-up source (optional) // or use internal timer for periodic wake-up } ```

The RISC-V core of the ESP32-C5 consumes very little in sleep, but external peripherals (Flash, PSRAM, sensors) must be put to sleep. Use the deep sleep function specifying a duration or wake-up source. ```cpp void loop() { uint64_t deepSleepTimeUs = 60000000; // Example: 60 seconds

  1. Programming Deep Sleep Mode

// Disable non-essential peripherals // Note: Check C5-specific registers to cut power to PSRAM // if code does not run from RAM.

// Call deep sleep function // On ESP32-C5, ensure the RTC remains powered by the battery esp_deep_sleep(deepSleepTimeUs); } ```

On each wake-up, code resumes at the beginning of setup(). It is crucial to check the wake-up reason to decide whether to perform a heavy task (data transmission) or return immediately to sleep. ```cpp void setup() { M5.begin(); esp_sleep_wakeup_cause_t wakeup_reason; wakeup_reason = esp_sleep_get_wakeup_cause();

  1. Wake-up Handling and Resume

if (wakeup_reason == ESP_SLEEP_WAKEUP_TIMER) { // Timer wake-up: execute task M5.Display.setBrightness(100); M5.Display.clear(); M5.Display.print("Wake up!"); delay(2000); M5.Display.setBrightness(0); } // Return to sleep via loop() } ```

Verification

To validate optimization, disconnect USB power and connect a multimeter in series with the battery. In deep sleep, consumption should drop close to 10.41 µA (manufacturer spec). Verify that the screen is off and LEDs are not blinking. Use a serial command (if enabled during sleep) or a indicator LED connected to a GPIO to confirm that wake-up occurs at the scheduled time.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials