pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

Tab5 Power Manager

Tab5 Power Manager related APIs and example.

Example

Compilation Requirements

  • M5Stack board manager version >= 3.2.2
  • Board selection = M5Tab5
  • 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
#include "M5Unified.h"

void setup()
{
    auto cfg = M5.config();
    M5.begin(cfg);
    M5.Display.setRotation(3);
    M5.Display.setTextDatum(top_center);
    M5.Display.setFont(&fonts::FreeMonoBold24pt7b);
    M5.Display.clear(WHITE);
    M5.Display.drawString("Tab5 Power Manager", M5.Lcd.width() / 2, 0);
}

void loop()
{
    M5.Display.clear();
    bool bat_ischarging = M5.Power.isCharging();
    M5.Display.setCursor(0, 100);
    M5.Display.printf("Bat Charging: %s\n", bat_ischarging ? "Yes" : "No");
    int bat_vol = M5.Power.getBatteryVoltage();
    M5.Display.printf("Bat Voltage: %dmv\n", bat_vol);
    int bat_level = M5.Power.getBatteryLevel();
    M5.Display.printf("Bat Level: %d\n", bat_level);
    delay(1000);
}

Power Output Control

  • The 5V outputs of M5-Bus, HY2.0-4P, 2.54-10P Bus, and USB-A are enabled by default in M5.begin(). Users can configure them as needed using the following API:
M5.Power.setExtOutput(true);
// M5.Power.setExtOutput(false);
  • If you need to control the USB-A power or expansion port power individually, you can use the following API:
    • ext_PA:Controls M5-Bus / HY2.0-4P / 2.54-10P Bus (shared switch, independent control not supported)
    • ext_USB:Controls USB-A only
M5.Power.setExtOutput(false, m5::ext_port_mask_t::ext_PA);
M5.Power.setExtOutput(false, m5::ext_port_mask_t::ext_USB);

API

The Tab5 power management driver uses the Power_Class from the M5Unified library. For more related APIs, please refer to the following documentation:

On This Page