🛠 Allumer une LED via le GPIO avec libgpiod
Objectives
Discover the 40-pin GPIO header of the Raspberry Pi 5 and turn on an LED from the command line using libgpiod, the modern Linux kernel GPIO API. On the Pi 5, the 3.3 V pins are controlled by the RP1 chip, and the logic is 3.3 V only.
Hardware
- Raspberry Pi 5 running 64-bit Raspberry Pi OS (Bookworm or later)
- 1 red LED + 1 470 Ω resistor
- Female-to-male Dupont cables
- Pinout: physical pin 11 = GPIO17 (output), physical pin 6 = GND
Full code
# Installer les outils libgpiod
sudo apt update && sudo apt install -y gpiod
# Vérifier la puce GPIO (gpiochip0 sur Pi 5)
gpiodetect
gpioinfo gpiochip0 | grep -A1 line\ 17
# Mettre GPIO17 en sortie et l'allumer (broche physique 11)
gpioset gpiochip0 17=1
sleep 2
gpioset gpiochip0 17=0
# Clignoter 5 fois
for i in 1 2 3 4 5; do gpioset --hold-period 1s gpiochip0 17=1; done
Expected verification
gpiodetect displays gpiochip0 [pinctrl-rp1]. The LED lights up during gpioset with 17=1 and then turns off. With --hold-period 1s, it blinks for one second per cycle.
Common errors
- Forgetting the resistor: the LED burns out or draws too much current (recommended limit is 16 mA per pin, 50 mA total on the GPIO).
- Confusing the GPIO number with the physical pin number: GPIO17 = pin 11, not pin 17.
- Using old RPi.GPIO tutorials with direct BCM2835 writes: on the Pi 5, GPIO goes through RP1, use libgpiod, lgpio, or gpiozero.
gpiodetectis empty: check that the kernel is up to date (uname -r) and reboot.- Powering a circuit with 5 V from a GPIO pin: the data pins are 3.3 V.
Other tutorials for this board
Code examples for this board
led_blink.pyPythonbutton_led.pyPythonservo_sweep.pyPythondht_temp.pyPythonoled_i2c.pyPythonmcp3008_read.pyPython