pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

Fire Wakeup

APIs and example programs related to Fire sleep and wake functions.

Example Program

Compilation Requirements

  • M5Stack board manager version >= 3.2.2
  • Board option = M5Fire
  • M5Unified library version >= 0.2.8
  • M5GFX library version >= 0.2.11
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include <M5Unified.h>

int myIndex = 0;

void setup() {
  M5.begin();
  M5.Display.setRotation(1);
  M5.Display.setFont(&fonts::FreeMonoBold12pt7b);

  M5.Display.clear();
  M5.Display.println("Sleep & Wakeup Test");
}

void loop() {
  myIndex++;

  M5.Display.setCursor(0, 50);
  M5.Display.printf("   %4d", myIndex);
  delay(50);

  if (myIndex % 20 == 0) {
    M5.Power.lightSleep(5000000, false);    // in microseconds
    // M5.Power.deepSleep(5000000, false);  // in microseconds
    // M5.Power.timerSleep(5);              // in seconds

    M5.Display.setCursor(0, 0);
    M5.Display.println("Sleep & Wakeup Test");
  }

  if (myIndex >= 1000) {
    myIndex = 0;
  }
}

This program will display a counter starting from 0 and incrementing by 1. Each time it reaches a multiple of 20, the device will enter light sleep for 5 seconds and then wake up, continuing the program. If the program is modified to use timed sleep or deep sleep (like the two commented lines), the entire program will restart from the beginning after waking up.

API

The Fire sleep and wake functionality uses the Power_Class from the M5Unified library. For more related APIs, please refer to the following documentation:

On This Page