🛠 Allumer une LED via le GPIO avec libgpiod

Raspberry Pi 3 Model B (model-3b) · debutant · Schéma : IMG-model-3b-debutant-1-model3b-led-gpio-libgpiod.svg — Raspberry Pi 3 Model B, broche 11 (GPIO17) vers résistance 330 Ω puis LED et 220 Ω vers GND broche 14

Objectives

Turn a LED on and off from the GPIO of a Raspberry Pi 3 Model B using the libgpiod library (modern character device API, which replaces the deprecated wiringPi). Understand the difference between BCM numbering (SoC pin number) and the physical pin number on the 40-pin connector, and remember that the Pi 3B's GPIO logic is 3.3 V only — the GPIO pins are NOT 5 V tolerant.

Hardware

Full code

The SoC's GPIO controller exposes /dev/gpiochip0 on the Pi 3B. We configure GPIO17 as an output and then make it blink:

# Installation des outils
sudo apt update && sudo apt install -y libgpiod-utils

# Vérifier le nom du chip (gpiochip0 sur Pi 3B)
gpiodetect

# Éteindre proprement le GPIO17 (broche physique 11)
gpioset gpiochip0 17=0

# Clignoter 10 fois : 200 ms allumé, 300 ms éteint
for i in $(seq 1 10); do
  gpioset -t 200ms gpiochip0 17=1
  sleep 0.3
done

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

Expected verification

gpiodetect displays gpiochip0 [brcm-gpios] (54 lines). During the loop, the LED blinks approximately twice per second. gpioinfo gpiochip0 | grep line\ 17 shows the line as output while gpioset is running. Upon Ctrl-C, releasing the line sets the pin back to input (LED off).

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials