🛠 Advanced I/O Control and Power Management on M5Stamp Timer Power 2

M5Stamp Timer Power 2 (PY32L020) · avance · Ce tutoriel explique comment configurer les 5 IO programmables pour l'acquisition de données et le contrôle de périphériques tout en minimisant la consommation grâce aux modes veille profonds du PY32L

Objectives

Learn to configure the 5 programmable IOs (GPIO, ADC, PWM) of the M5Stamp Timer Power 2 to interface with sensors or displays. Understand the interaction between power outputs (3V3_DCDC_OUT, 3V3_LDO_OUT) and the PY32L020 microcontroller logic. Optimize power consumption by leveraging deep sleep modes (6.72uA off, 12.27uA standby) with interrupt-based wake-up.

Materials Needed

Steps

  1. Environment Setup: Install PY32L020 support in Arduino IDE. Select the « M5Stamp Timer Power 2 » board and the correct serial port.
  2. Power Output Initialization: Before using IOs, enable voltage rails if needed via internal registers or dedicated pins. Note that 3V3_DCDC_OUT provides 0.6A while 3V3_LDO_OUT offers 0.4A. Ensure total load does not exceed these limits.
  3. GPIO Configuration: The 5 IOs are multiplexed. For a button, configure a pin as INPUT_PULLUP. For an LED, use OUTPUT. For an analog sensor, select the appropriate ADC channel.
// Example GPIO configuration
pinMode(IO_PIN_BTN, INPUT_PULLUP);
pinMode(IO_PIN_LED, OUTPUT);
analogReadResolution(12); // If supported
  1. PWM Implementation: Use a PWM-compatible pin to control LED brightness or motor speed. Check the default timer frequency of the PY32L020.
analogWrite(IO_PIN_PWM, 128); // 50% duty cycle
  1. Interrupt and Sleep Management: Configure a pin for falling-edge interrupt mode. Before entering sleep, save IO states and disable unnecessary clocks.
attachInterrupt(digitalPinToInterrupt(IO_PIN_BTN), wakeCallback, FALLING);
// Code to enter Deep Sleep mode
py32l020_enter_sleep();
  1. Data Reading: Read ADC values or GPIO states after wake-up. Wake-up can be scheduled (timer) or external (IRQ). Standby consumption is then 12.27uA at 4.2V.

Verification

To Go Further

Explore I2C communication (address 0x6E) to read M5PM1 chip parameters. Adjust charging current (650mA or 180mA) via dedicated pins to optimize battery life. Test stability of PY_3V3 outputs under variable load to avoid voltage drops.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials