🛠 Getting started with GPIO on Xerxes Pi

Xerxes Pi 2026 Carrier Board for Raspberry Pi CM4/CM5 Modules · debutant · Apprenez à contrôler une LED et lire un bouton via les broches GPIO exposées sur la carte Xerxes Pi.

Objectives

This tutorial guides you through manipulating digital General Purpose Input/Output (GPIO) pins on the Xerxes Pi 2026 board. We will light an LED and read the state of a push button. Understanding GPIO is essential for interacting with the physical world via sensors or actuators. The Xerxes board exposes these signals via its mezzanine connectors, compatible with Raspberry Pi CM4/CM5 modules.

Required Materials

Steps

  1. Pin Identification: Consult the open-source KiCad documentation for the Xerxes Pi to identify physical GPIO pins on the mezzanine connector. Pins follow the Raspberry Pi standard (BCM numbering).
  2. LED Wiring: Connect the long leg (anode) of the LED to a GPIO output pin (e.g., GPIO 17) via the resistor. Connect the short leg (cathode) to a GND pin on the board.
  3. Button Wiring: Connect one leg of the button to a GPIO input pin (e.g., GPIO 27) and the other leg to GND. We will use an internal software pull-up resistor.
  4. Library Installation: Open a terminal and install the RPi.GPIO library if not present: pip install RPi.GPIO.
  5. Python Script: Create a file test_gpio.py. Import RPi.GPIO and time. Set the numbering mode. Define GPIO 17 as output and GPIO 27 as input with pull-up. In an infinite loop, set GPIO 17 to HIGH if the button is pressed (reading LOW), otherwise LOW.
  6. Execution: Run the script with sudo python3 test_gpio.py (sudo is often required for GPIO access).

Verification

Press the button: the LED should light up. Release it: it should turn off. If nothing happens, check solder joints or breadboard connections. Ensure the board is properly powered and the system is booted correctly.

Further Exploration

Explore modern libraries like gpiozero for simpler syntax. Try using Qwiic connectors to add I2C sensors without soldering, leveraging the Xerxes Pi's native expansion.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials