🛠 Allumer une LED via le GPIO avec libgpiod

Raspberry Pi 4 Model B (2019) — Board Sheet · debutant · Schéma : IMG-model-4b-debutant-1-model4b-led-gpio-libgpiod.svg — Raspberry Pi 4B, connecteur 40 broches, GPIO18 (broche 12) vers LED avec résistance 330 ohms puis GND

Objectives

Discover the 40-pin GPIO connector on the Raspberry Pi 4B (3.3 V logic, compatible with all previous Pi models) and light up an LED using libgpiod, the modern Linux kernel character interface that replaces the deprecated wiringPi. By the end, you will be able to control an output pin from a simple terminal.

Hardware

Complete Code

sudo apt install gpiod
sudo adduser "$USER" gpio   # puis reconnexion
# GPIO18 = broche physique 12 ; 330R en serie avec la LED, cathode vers GND
gpiodetect                  # doit afficher: gpiochip0 [brcmstb-gpio] (54 lines)
gpioinfo gpiochip0 | head -n 20
gpioset gpiochip0 18=1      # LED allumee
sleep 2
gpioset --duration=2s gpiochip0 18=0
for i in $(seq 1 10); do gpioset --duration=0.3s gpiochip0 18=1; sleep 0.3; done

Expected Verification

gpiodetect displays gpiochip0 (the BCM2711); the LED lights up for 2 seconds, then the loop makes it blink 10 times at approximately 2 Hz. No gpiochip device = gpio-mockup module or incomplete kernel.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials