pdf-icon

Arduino Guide

Power Management

Class Name: Power

*Functions related to power management might involve registers of the IP5306 chip. For any uncertainties, you can refer to the IP5306 register manual .*

*The IP5306 chip does not support communication with older M5STACK hardware. When using features, also consider support for uncontrollable situations.*

Use in order: initialization, communication check, and control, as shown in the example below:

  M5.Power.begin();
  if(!M5.Power.canControl()) {
    //can't control.
    return;
  }
  M5.Power.lightSleep(SLEEP_SEC(5));

begin()

Description:

Initializes the Power class.

Syntax:

void begin();

Example:

#include <M5Stack.h>

void setup() {
    M5.begin();
    M5.Power.begin();
}

void loop() {}

setPowerBoostOnOff()

Description:

Changes the method of turning the device on/off with the power button.

Note:
The device will not power off when connected via USB.

Syntax:

bool setPowerBoostOnOff(bool en);
en Functionality
true Long press to turn on/off
false Double press to turn on/off

Return Value:

Value Functionality
true Control succeeded
false Control failed

Example:

#include <M5Stack.h>

void setup() {
    M5.begin();
    M5.Power.begin();
    if (M5.Power.setPowerBoostOnOff(false)) {
        M5.Lcd.println("Changed power on/off method");
    } else {
        M5.Lcd.println("Failed to change power on/off method");
    }
}

void loop() {}

setPowerBoostKeepOn()

Description:

Changes the power on/off method. The power will not turn off when connected via USB.

Syntax:

bool setPowerBoostKeepOn(bool en);
en Functionality
true Short press for on/off
false Follow the setPowerBoostOnOff() method

Return Value:

Value Functionality
true Control succeeded
false Control failed

setPowerVin()

Description:

Decides whether to power on again when external sources like USB are disconnected.

Syntax:

bool setPowerVin(bool en);
Value Functionality
true Power will turn on again
false Power will not turn on again

Return Value:

Value Functionality
true Control succeeded
false Control failed

setPowerWLEDSet()

Description:

Sets the mode to turn on the power LED. Not controllable via this function for M5GO due to lack of wiring to IP5306.

Syntax:

bool setPowerWLEDSet(bool en);
Value Functionality
true Double press to turn on LED
false Hold to turn on LED

Return Value:

Value Functionality
true Control succeeded
false Control failed

setPowerBtnEn()

Description:

Sets whether to accept power button actions.

Regarding behavior when not accepting button actions: If the power is on, the power button only accepts CPU reset. If no power is provided, it's not possible to turn the power on.

Syntax:

bool setPowerBtnEn(bool en);
Value Functionality
true Accept power actions
false Do not accept power control

Return Value:

Value Functionality
true Control succeeded
false Control failed

setLowPowerShutdownTime()

Description:

Sets the wait time until IP5306 decides to save energy and turns off the power.

Syntax:

bool setLowPowerShutdownTime(ShutdownTime time);
Value Functionality
SHUTDOWN_8S Wait 8 seconds
SHUTDOWN_16S Wait 16 seconds
SHUTDOWN_32S Wait 32 seconds
SHUTDOWN_64S Wait 64 seconds

Return Value:

| Value | Function

| ality | | ----- | ----------------- | | true | Control succeeded | | false | Control failed |

setPowerBoostKeepOn()

Description:

This function enables/disables the always-on boost output mode.

Syntax:

bool setPowerBoostKeepOn(bool en);
Value Functionality
true Always provide power output
false Do not always provide power output

Return Value:

Value Functionality
true Control succeeded
false Control failed

setAutoBootOnLoad()

Description:

Sets whether to auto-boot when there is a power consumption on the secondary side of IP5306.

Syntax:

bool setAutoBootOnLoad(bool en);
Value Functionality
true Enable auto-boot feature
false Disable auto-boot feature

Return Value:

Value Functionality
true Control succeeded
false Control failed

setCharge()

Description:

This function enables/disables charging mode. After the battery is full, toggling charge enable -> disable -> enable may allow charging to resume.

Syntax:

bool setCharge(bool en);
Value Functionality
true Begin charging command
false Stop charging command

Return Value:

Value Functionality
true Control succeeded
false Control failed

isChargeFull()

Description:

Checks if the battery is fully charged.

Syntax:

bool isChargeFull();

Return Value:

Value Functionality
true Fully charged
false Not fully charged

canControl()

Description:

This function checks if the battery controller is present via I2C communication.

Syntax:

bool canControl();

Return Value:

Value Functionality
true Power controller found
false Power controller not found

isCharging()

Description:

Checks if charging is in progress.

Syntax:

bool isCharging();

Return Value:

Value Functionality
true Charging
false Not charging

getBatteryLevel()

Description:

Returns the battery level.

Syntax:

int8_t getBatteryLevel();

Return Value:

Returns battery level as 0/25/50/75/100. Returns -1 if unable to check the remaining capacity.

setWakeupButton()

Description:

Sets the wake-up port upon sleep return.

Syntax:

void setWakeupButton(uint8_t button);
Value Functionality
button Port number

Example:

setWakeupButton(BUTTON_A_PIN);

reset()

Description:

Performs a CPU reset.

Syntax:

void reset();

isResetbySoftware()

Description:

Determines if the current activation state is after a CPU reset. (Applies if executing reset() or an equivalent process such as RTOS.)

Syntax:

bool isResetbySoftware();

Return Value:

Value Functionality
true Reset by software
false Due to other reasons

isResetbyWatchdog()

Description:

Determines if the current activation state is after a watchdog timer.

Syntax:

bool isResetbyWatchdog();

Return Value:

Value Functionality
true Reset by watchdog
false Due to other reasons

isResetbyDeepsleep()

Description:

Determines if the current wake state is after deepSleep().

Syntax:

bool isResetbyDeepsleep();

Return Value:

Value Functionality
true After deepSleep()
false Due to other reasons

isResetbyPowerSW()

Description:

Determines if the current start-up state is after turning on the power switch.

Syntax:

bool isResetbyPowerSW();

Return Value:

Value Functionality
true Reset by power switch
false Due to other reasons

deepSleep()

Description:

This function transitions to deep sleep mode. It wakes up after a specified time or

when a port state changes. Upon wake-up, the CPU restarts, not running from the next line.

Syntax:

void deepSleep();

Example:

To save power for 5 seconds then restart:

deepSleep(SLEEP_SEC(5));

lightSleep()

Description:

This function transitions to light sleep mode. It wakes up after a specified time or when a port changes. Upon returning, it runs from the next line. Compared to deepSleep(), it lacks power-saving functionality.

Syntax:

void lightSleep(uint64_t time_in_us);

Example:

To save power for 5 seconds then restart:

lightSleep(SLEEP_SEC(5));

powerOFF()

Description:

Turns off the power. Uses the power-saving feature to turn off IP5306 after 8 seconds. Shuts off power provided to the circuit side.

Syntax:

void powerOFF();
Note:
M5Stack cannot be forcibly powered off. Hence, this function achieves it through the power-saving feature of IP5306. If the user consumes current in the circuit, IP5306 cannot determine to turn off the power.
On This Page
begin()
setPowerBoostOnOff()
setPowerBoostKeepOn()
setPowerVin()
setPowerWLEDSet()
setPowerBtnEn()
setLowPowerShutdownTime()
setPowerBoostKeepOn()
setAutoBootOnLoad()
setCharge()
isChargeFull()
canControl()
isCharging()
getBatteryLevel()
setWakeupButton()
reset()
isResetbySoftware()
isResetbyWatchdog()
isResetbyDeepsleep()
isResetbyPowerSW()
deepSleep()
lightSleep()
powerOFF()
Q&A
Submit a question
Select question category*
Arduino
MicroPython
UIFlow1
UIFlow2
EzData
M5Burner
Software
Hardware
Other
Product name
Product version
Question description*
(Supports pasting screenshots.)
Attachments
Add Files
Email*
Submit
OK

M5Stack Support

Hi, this is M5Stack Support. How can I help you today?