🛠 Getting started with GPIO on 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
- Xerxes Pi 2026 board with CM4 or CM5 module.
- USB-C or PoE power supply.
- One red LED (or other color) and a 220 to 330 ohm resistor.
- One momentary push button.
- Connecting wires (jumpers) and a breadboard if needed for prototyping.
- Software: Raspberry Pi OS installed.
Steps
- 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).
- 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.
- 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.
- Library Installation: Open a terminal and install the RPi.GPIO library if not present:
pip install RPi.GPIO. - 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. - 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
poe-status-monitor.pypythonnvme-benchmark.shbashqwiic-bme280-reader.pypythonpwm-fan-control.pypythonethernet-poe-config.shbashnvme_storage_benchmark-6.inobash