pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

Fire Battery

APIs and sample programs for reading the status of the Fire Battery.

Sample 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
#include "M5Unified.h"

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

  M5.Display.clear();
  M5.Display.setCursor(0, 0);
  M5.Display.print("Fire Battery Status");
}

void loop() {
  M5.update();
  bool isCharging = M5.Power.isCharging();
  int batteryLevel = M5.Power.getBatteryLevel();  // 0 - 100 %

  M5.Display.setCursor(0, 50);
  M5.Display.printf("  isCharging: %-3s", isCharging ? "Yes" : "No");

  M5.Display.setCursor(0, 100);
  M5.Display.printf("batteryLevel: %3d %%", batteryLevel);

  delay(1000);
}

The program will display whether the battery is charging and the battery percentage on the screen, refreshing once every second.

Due to hardware limitations, the Fire cannot read battery voltage or current information. The battery percentage is displayed in only five levels (0%, 25%, 50%, 75%, 100%). For the correspondence between percentage and voltage, see the Product Page.

API

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

On This Page