🛠 Faire clignoter une LED avec libgpiod

Raspberry Pi 3 Model B+ (2018) — Board Sheet · debutant · Schéma : IMG-model-3b-plus-debutant-1-model3bp-led-gpio-libgpiod.svg — Carte à 40 broches, LED via résistance 330 Ω vers GPIO17 (broche 11) et GND (broche 14)

Objectives

Discover the board's GPIO (40-pin connector, 3.3 V logic) by blinking an LED with libgpiod, the modern method that replaces the old wiringPi. You will understand the difference between physical pin numbers and GPIO numbers (BCM), as well as the current limit per pin (16 mA max per pin, 50 mA for the entire connector).

Hardware

Complete Code

Wiring: pin 11 (GPIO17) → 330 Ω resistor → LED anode → LED cathode → pin 14 (GND).

# Installation de libgpiod (présent par défaut sur Raspberry Pi OS récent)
sudo apt update && sudo apt install -y gpiod

# Lister les puces GPIO : gpiochip0 est le connecteur 40 broches
gpiodetect
gpioinfo gpiochip0

# Clignotement : mode sortie, puis basculer l'état 10 fois
sudo gpioset gpiochip0 17=0            # état initial éteint
for i in $(seq 1 10); do
    sudo gpioset --hold-period 500ms gpiochip0 17=1
    sudo gpioset gpiochip0 17=0
    sleep 0.5
done

Expected Verification

The LED blinks approximately once per second for 5 seconds. gpiodetect displays gpiochip0, and gpioinfo gpiochip0 shows line 17 as output while the command is running. No permission errors if you use sudo (or are in the gpio group).

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials