🛠 Configure M5Stamp Timer Power 2 I/O
Objectives
This tutorial guides you through using the 5 programmable IO pins on the M5Stamp Timer Power 2 (SKU S021). Unlike standard boards, this module uses the PY32L020 microcontroller to manage power while offering flexible interfaces. We will configure a GPIO as an output to control an LED and use PWM to modulate a signal, demonstrating I/O versatility without compromising low power consumption (6.72uA in shutdown).
Required Hardware
- 1x M5Stamp Timer Power 2 Module (S021)
- 1x USB-C cable for power and programming
- 1x LED with current-limiting resistor (330Ω) or test module
- 1x Connecting cables (Dupont)
- Software: Arduino IDE or PY32-compatible platform (e.g., M5Burner for initial flashing)
Steps
- Physical Connection: Connect VBUS (5V) and GND to your power source. To test an output, connect the selected IO pin (e.g., IO0) to the LED anode via the resistor, and the cathode to GND.
- Software Configuration: Open your IDE. Ensure the board is recognized as a PY32L020 device. Include necessary libraries for this module's specific pin management.
#include <Arduino.h>
// Pin definitions based on module schematic
#define LED_PIN 0 // Programmable IO0
#define PWM_PIN 1 // IO1 for PWM
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(PWM_PIN, OUTPUT);
// Initialize serial for debugging if needed
Serial.begin(115200);
}
- Program the Main Loop: In
loop(), we will toggle the GPIO state and vary the PWM duty cycle. Note that the module manages internal power (3V3_DCDC_OUT) for connected peripherals if needed.
void loop() {
// Simple GPIO activation
digitalWrite(LED_PIN, HIGH);
delay(500);
digitalWrite(LED_PIN, LOW);
delay(500);
// PWM Modulation (analog) on IO1
for(int i = 0; i <= 255; i++) {
analogWrite(PWM_PIN, i);
delay(5);
}
for(int i = 255; i >= 0; i--) {
analogWrite(PWM_PIN, i);
delay(5);
}
}
- Power Management: To optimize consumption, ensure unused pins are set to high impedance (INPUT_FLOATING) or pull-down inputs if inactive, to prevent leakage currents that would increase consumption beyond the 12.27uA standby rate.
Verification
Observe the LED blinking and progressive brightness variation (if connected to the PWM pin). Use a multimeter to verify output voltage matches expected logic levels (0V or ~3.3V). Also, check that module consumption remains low when I/Os are inactive.
Further Reading
Explore the module's I2C interface (address 0x6E) to read battery status or configure charge thresholds via the M5PM1. You can also test external interrupts (IRQ) on IOs to wake the module from shutdown mode, crucial for battery-powered applications.