pdf-icon

Arduino入門

2. デバイス&サンプル

5. 拡張モジュール&サンプル

アクセサリー

6. アプリケーション

StickS3 Wakeup

StickS3 のスリープ / ウェイクアップ関連 API とサンプルプログラムについて。

サンプルプログラム

コンパイル要件

  • M5Stack ボードマネージャー版 >= 3.2.5
  • 開発ボード選択 = M5StickS3
  • M5Unified ライブラリ版 >= 0.2.12
  • M5GFX ライブラリ版 >= 0.2.18
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#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
  }
}

サンプルプログラムの動作例は以下の通りです:

API

StickS3 の電源管理部分では M5Unified ライブラリの Power_Class を使用しています。詳細は以下のドキュメントをご参照ください:

PMIC Timer Wakeup

StickS3 は、M5PM1 Arduino Library ドライバライブラリを使用して駆動でき、PMIC を介してデバイスのタイマー起動を実現します。このモードでは、ESP32-S3 などの周辺機器への電源供給を遮断できるため、消費電力が低減されます。

StickS3 PMIC の使用方法についての詳細なチュートリアルは、StickS3 PMIC 低電力構成を参照してください。

コンパイル要件

  • M5Stack ボードマネージャー版 >= 3.2.5
  • 開発ボード選択 = M5StickS3
  • M5Unified ライブラリ版 >= 0.2.12
  • M5GFX ライブラリ版 >= 0.2.18
  • M5PM1 ライブラリ版 >= 1.0.1

ケース説明:デバイスが起動した後、ボタン A をクリックして 10 秒タイマーを設定し、ウェイクアップをトリガーします。

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 36 37 38 39 40 41 42 43 44 45 46
#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);
    }
}
On This Page