Arduino Quick Start
Basic/Gray/M5GO battery status related APIs and example program.
#include "M5Unified.h"
void setup()
{
auto cfg = M5.config();
M5.begin(cfg);
M5.Display.setTextDatum(middle_center);
M5.Display.setTextColor(TFT_BLACK);
M5.Display.setTextFont(&fonts::Orbitron_Light_24);
M5.Display.setTextSize(1);
}
void loop()
{
M5.Display.clear(TFT_WHITE);
bool isCharging = M5.Power.isCharging();
int vol_per = M5.Power.getBatteryLevel();
M5.Display.setCursor(0, 30);
M5.Display.printf("Charging: %s \n\n", isCharging ? "Yes" : "No");
M5.Display.setCursor(0, 60);
M5.Display.printf("BAT: %d%%", vol_per);
delay(5000);
}
The program will display whether the battery is charging and its percentage on the screen, refreshing every 5 seconds. Due to hardware limitations, the Basic/Gray/M5GO cannot read battery voltage or current information.
The battery status part of Basic/Gray/M5GO uses the Power_Class
from the M5Unified
library. For more information, please refer to the documentation below: