🛠 Controlling GPIOs with M5Stamp Timer Power 2

M5Stamp Timer Power 2 (PY32L020) · debutant · Apprenez à configurer les broches d'entrée/sortie pour piloter une LED ou lire un bouton sur le module de gestion d'alimentation.

Objectives

This tutorial aims to understand basic interaction with the Input/Output (GPIO) pins of the M5Stamp Timer Power 2. We will configure one pin as an output to control an LED and another as an input to detect a button press. This module, based on the PY32L020 microcontroller, is optimized for low power, but its GPIOs remain accessible for simple logic control. It is essential to understand that power management (via the M5PM1 chip) influences pin states, especially during sleep modes. This course provides the basics to physically interact with the module without relying solely on I2C communication.

Required Hardware

Steps

  1. Pin Identification: The module has 5 programmable IOs. Consult the datasheet to identify the physical pins corresponding to the desired GPIO functions. Note the format is a 28-pin castellated-hole package.
  2. LED Wiring: Connect the LED cathode (short leg) to Ground (GND) via the 220Ω resistor. Connect the anode (long leg) to a GPIO pin configured as output. Ensure the output voltage is compatible (3.3V via PY_3V3 or 3V3_LDO_OUT).
  3. Button Wiring: Connect one leg of the button to a GPIO pin configured as input (with internal pull-up resistor enabled if possible) and the other leg to Ground.
  4. Software Initialization: In your code (C/C++ or MicroPython), initialize the I2C bus to configure M5PM1 registers if needed to activate specific GPIOs. Set the LED pin to OUTPUT mode and the button pin to INPUT mode.
  5. Main Loop: Write a loop that reads the button state. If the button is pressed (low state due to pull-up), set the LED pin to HIGH to turn it on. Otherwise, set it to LOW.

Verification

Open the serial monitor or use a multimeter. Press the button: the LED should light up immediately. Release the button: the LED should turn off. If the LED does not light up, check the LED polarity and ensure the selected pin is powered (check if the 3V3 output is active via M5PM1 configuration).

Going Further

Explore the use of external interrupts (IRQ) to wake the module from deep sleep (6.72uA consumption) when a button is pressed, rather than polling the CPU with a loop.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials