
Arduino Quick Start
StickS3 sleep/wakeup related APIs and example program.
#include "M5Unified.h"
void setup(void) {
M5.begin();
M5.Display.setTextDatum(middle_center);
M5.Display.setTextFont(&fonts::FreeMonoBoldOblique9pt7b);
M5.Display.setRotation(1);
M5.Display.drawString("BtnA to Sleep 5s", M5.Display.width() / 2, M5.Display.height() / 2);
}
void loop(void) {
M5.update();
if (M5.BtnA.wasPressed()) {
M5.Display.clear();
M5.Power.timerSleep(5);//sec
}
}The example program runs as follows:
The power management part of StickS3 uses the Power_Class from the M5Unified library. For more related APIs, you can refer to the following documentation:
StickS3 can be driven using the M5PM1 Arduino Library, enabling timed device wake-up through the PMIC. In this mode, power to peripherals such as the ESP32-S3 can be shut off, resulting in lower power consumption.
For more tutorials on using the StickS3 PMIC, please refer to StickS3 PMIC Configuration.
Description: After the device is powered on, press button A to configure a 10-second timer to trigger a wake-up.
#include <M5Unified.h>
#include <M5PM1.h>
#include <Wire.h>
M5PM1 pm1;
void setup(void)
{
M5.begin();
M5.Display.setRotation(1);
Serial.begin(115200);
auto pin_num_sda = M5.getPin(m5::pin_name_t::in_i2c_sda);
auto pin_num_scl = M5.getPin(m5::pin_name_t::in_i2c_scl);
M5_LOGI("getPin: SDA:%u SCL:%u", pin_num_sda, pin_num_scl);
Wire.end();
Wire.begin(pin_num_sda, pin_num_scl, 100000U);
// Initialize PM1
m5pm1_err_t err = pm1.begin(&Wire, M5PM1_DEFAULT_ADDR, pin_num_sda, pin_num_scl, M5PM1_I2C_FREQ_100K);
if (err == M5PM1_OK) {
Serial.println("PM1 initialization successful");
} else {
Serial.printf("PM1 initialization failed, error code: %d\n", err);
}
M5.Display.fillScreen(BLACK);
M5.Display.setTextSize(2);
M5.Display.setTextColor(WHITE);
M5.Display.setCursor(0, 10);
M5.Display.println("Timer Power Test");
M5.Display.println("BtnA: After 10s Wakeup");
}
void loop(void)
{
M5.update();
if (M5.BtnA.wasPressed()) {
M5.Display.fillScreen(BLACK);
M5.Display.setCursor(0, 10);
M5.Display.println("Shutdown");
M5.Display.println("After 10s");
M5.Display.println("Wakeup");
delay(1000);
pm1.timerSet(10, M5PM1_TIM_ACTION_POWERON);
}
}