🛠 Allumer une LED via le GPIO avec libgpiod
Objectives
Discover the 26-pin GPIO connector (P1, 2×13) on the Raspberry Pi Model B Rev 1 and turn on an LED from the command line using libgpiod, the modern method that replaces the older wiringPi. You will understand BCM numbering (Broadcom pin numbers) and the difference between data pins and power pins.
Hardware
- Raspberry Pi Model B Rev 1 (BCM2835, 256 MB) with Raspberry Pi OS legacy 32-bit (Buster)
- 1 red LED + 330 Ω resistor
- Breadboard and female-to-male Dupont wires
- The P1 connector provides only 3.3 V logic: no 5 V components on the GPIO pins, as they are not 5 V tolerant.
Complete code
# Installation de libgpiod (Buster)
sudo apt update && sudo apt install -y gpiod
# Lister les broches du contrôleur BCM2835
gpioinfo gpiochip0
# Configurer GPIO17 en sortie puis l'allumer (GPIO17 = broche physique 11)
gpioset gpiochip0 17=1
sleep 3
gpioset gpiochip0 17=0
Expected verification
The LED turns on for 3 seconds and then turns off. gpioinfo gpiochip0 shows pin 17 changed from input to output. The wiring diagram: GPIO17 (pin 11) → 330 Ω resistor → LED anode → cathode → GND (pin 6).
Common errors
- Confusing physical and BCM numbering: physical pin 11 is GPIO17, not pin 1.
- Forgetting the resistor: the LED burns out without current limiting.
- Reversing anode/cathode: the LED only lights up in the correct direction.
- Using a power pin (3.3 V pin 1, 5 V pin 2) as a control pin: they are not controllable.
- On Raspbian older than Buster,
gpioddoes not exist: use RPi.GPIO or switch to a recent legacy image.
Other tutorials for this board
- Lire un bouton poussoir et afficher l'état dans la console
- Premier script Python : faire clignoter la LED
- Variation d'intensité LED avec le PWM matériel (et son piège)
- Lire un capteur I2C (température/humidité) sur le bus 1
- Configurer l'Ethernet 10/100 et piloter le Pi en SSH
- Boot sur SD, partitions et procédure de recouvrement
Code examples for this board
led_blink.pyPythonbutton_led.pyPythonservo_sweep.pyPythondht_temp.pyPythonoled_i2c.pyPythonmcp3008_read.pyPython