pdf-icon

Arduino Quick Start

PaperS3 Battery Status

PaperS3 battery status related APIs and example program.

Example Program

Compilation Requirements

  • M5Stack board package version >= 2.1.4
  • Board selection = M5PaperS3
  • 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 31 32 33 34 35
#include <M5Unified.h>
#include <M5GFX.h>
void setup() {
M5.begin();
M5.Display.setRotation(0);
M5.Display.setFont(&fonts::FreeMonoBold18pt7b);
M5.Display.setCursor(0, 200);
M5.Display.print(" PaperS3 Realtime\n");
M5.Display.print(" Battery Status\n\n\n");
M5.Display.print(" Battery Charging:\n\n");
M5.Display.print(" Battery Level:\n\n");
M5.Display.print(" Battery Voltage:\n\n");
}
void loop() {
M5.update();
bool isCharging = M5.Power.isCharging();
int32_t batteryLevel = M5.Power.getBatteryLevel(); // 0 - 100 %
int16_t batteryVoltage = M5.Power.getBatteryVoltage(); // unit: mV
M5.Display.setCursor(380, 340);
M5.Display.printf("%s \n\n", isCharging ? "Yes" : "No");
M5.Display.setCursor(380, 410);
M5.Display.printf("%d %% \n\n", batteryLevel);
M5.Display.setCursor(380, 480);
M5.Display.printf("%d mV \n\n", batteryVoltage);
delay(2000);
}

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

API

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

On This Page