pdf-icon

Arduino Quick Start

2. Devices & Examples

Paper Battery Status

Paper battery status related APIs and example program.

Example Program

Compilation Requirements

  • M5Stack board package version >= 2.1.4
  • Board selection = M5Paper
  • M5Unified library version >= 0.2.5
  • M5GFX library version >= 0.2.7
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
#include <M5Unified.h>
#include <M5GFX.h>

void setup() {
  M5.begin();
  M5.Display.setRotation(0);
  M5.Display.setFont(&fonts::FreeMonoBold18pt7b);
  M5.Display.setEpdMode(epd_text);  // epd_quality, epd_text, epd_fast, epd_fastest
  M5.Display.clear();

  M5.Display.setCursor(0, 200);
  M5.Display.println("     Paper Realtime");
  M5.Display.println("     Battery Status\n\n");
  M5.Display.println(" Battery   Level:\n");
  M5.Display.println(" Battery Voltage:\n");
}

void loop() {
  M5.update();

  int32_t batteryLevel = M5.Power.getBatteryLevel();      // 0 - 100 %
  int16_t batteryVoltage = M5.Power.getBatteryVoltage();  // unit: mV

  M5.Display.setCursor(360, 340);
  M5.Display.printf(" %3d %%", batteryLevel);
  M5.Display.setCursor(360, 410);
  M5.Display.printf("%4d mV", batteryVoltage);

  delay(2000);
}

This program displays the battery percentage and voltage on the screen, refreshing every 2 seconds. Due to hardware limitations, Paper cannot read the battery charging status and battery current.

API

The battery status part of Paper uses the Power_Class from the M5Unified library. For more information, please refer to the documentation below:

On This Page