🛠 Simple Automation with M5Stamp Timer Power 2

M5Stamp Timer Power 2 (PY32L020) · debutant · Apprenez à configurer le réveil programmé pour contrôler un périphérique externe tout en minimisant la consommation d'énergie.

Objectives

This tutorial guides you through creating a basic automation system using the M5Stamp Timer Power 2. The goal is to understand how the PY32L020 microcontroller can wake up an external circuit at regular intervals and then enter deep sleep to preserve battery life. This is a key skill for autonomous IoT devices.

Required Hardware

Steps

  1. Environment Setup: Open Arduino IDE. Go to Tools -> Manage Libraries, search for "M5Stack Timer Power" and install the latest version. Select "M5Stamp Timer Power 2" in Tools -> Board.
  1. Basic Wiring: The module uses castellated pins. For this test, connect EXT_5V_INOUT to a stable power source if testing on battery, or leave it floating if powering via USB on DC 5V pins. Ensure 3V3_DCDC_OUT is available to power a small sensor or LED.
  1. Code Writing: Copy the code below. It configures a wake-up every 10 seconds. Note the default I2C address 0x6E.
#include <M5TimerPower.h>

// Default I2C address
#define TIMER_ADDR 0x6E

void setup() {
  Serial.begin(115200);
  // Initialize I2C communication
  Wire.begin();
  
  // Initialize Timer Power module
  M5TimerPower.begin(TIMER_ADDR);
  
  // Set programmed wake-up (e.g., 10 seconds)
  // Exact function depends on library version,
  // check the "WakeUpTest" example.
  M5TimerPower.setWakeUpInterval(10); 
}

void loop() {
  // Code runs here upon wake-up
  Serial.println("Wake up! Action in progress...");
  
  // Simulate action (e.g., turn on LED on programmable GPIO)
  // digitalWrite(LED_PIN, HIGH);
  
  delay(1000); // Work time
  
  // Return to deep sleep
  Serial.println("Entering sleep...");
  M5TimerPower.deepSleep();
}
  1. Upload: Connect the board to the computer via USB. Upload the code. Open the Serial Monitor at 115200 bauds.

Verification

Observe the Serial Monitor. You should see "Wake up!" followed by "Entering sleep...". The module should then consume very little (approx. 6.72uA in off mode). If you have a multimeter in series with the battery, you should see the current drop drastically after sleep, then briefly increase every 10 seconds. Also, verify that the 3V3_DCDC_OUT output remains stable if a peripheral is connected.

Further Reading

Explore external interrupt (IRQ) features to wake the module with a push button instead of a timer. You can also adjust the charging current (650mA vs 180mA) based on your battery to optimize lifespan. Try combining multiple outputs (LDO and DCDC) to power different sensors with distinct voltages.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials