🛠 Allumer une LED via le GPIO 40 broches

Raspberry Pi 2 Model B (2015) — Board Sheet · debutant · Schéma : IMG-model-2b-debutant-1-model2b-led-gpio.svg — Raspberry Pi 2 Model B, connecteur J8 à 40 broches, LED et résistance 330 Ω câblées entre GPIO17 et masse

Objectives

Discover the 40-pin GPIO connector (J8) on the Raspberry Pi 2 Model B and turn on an LED from the command line: first with the legacy sysfs interface, then with libgpiod, the recommended interface on recent systems. By the end, you will know how to export a pin, configure it as an output, and control it without writing a program.

Hardware

Full code

# Méthode 1 : sysfs (ancienne interface, dépréciée mais pédagogique)
echo 17 | sudo tee /sys/class/gpio/export
echo out | sudo tee /sys/class/gpio/gpio17/direction
echo 1 | sudo tee /sys/class/gpio/gpio17/value   # LED allumée
sleep 2
echo 0 | sudo tee /sys/class/gpio/gpio17/value   # LED éteinte
echo 17 | sudo tee /sys/class/gpio/unexport

# Méthode 2 : libgpiod (recommandée)
sudo apt install gpiod
sudo gpioset --time 2000 gpiochip0 17=1          # impulsion de 2 s

Expected verification

The LED turns on when the value is 1 and turns off at 0. With gpioset, the --time 2000 option produces a two-second pulse. The controller name may be gpiochip0 or gpiochip1 depending on the kernel: check with gpioinfo before copying the commands.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials