🛠 Allumer une LED via le GPIO avec libgpiod

Raspberry Pi Model B Revision 2 (2012) — Board Sheet · debutant · Schéma : IMG-model-b-rev2-debutant-1-modelb2-led-gpio.svg — Connecteur P1 26 broches du Raspberry Pi Model B Rev 2, LED et résistance 330 Ω sur GPIO17 (P1-11) vers GND

Objectives

Turn on and blink an LED from a GPIO pin on the Raspberry Pi Model B Rev 2 (Broadcom BCM2835 SoC, 26-pin P1 connector) using libgpiod, and understand the mapping between physical pin and GPIO number.

Hardware

Complete code

# Raspbian legacy 32 bits (ère BCM2835)
sudo apt update && sudo apt install -y gpiod libgpiod2
# > 
gpiodetect                      # doit afficher: gpiochip0 (BCM2835 GPIOs)
gpioinfo gpiochip0 | head -25
# Clignotement: ligne 17 a l'etat 1 pendant 500 ms, 10 fois de suite
sudo gpioset -c gpiochip0 --time=500ms --repeat=10 17=1

Expected verification

gpiodetect displays gpiochip0. The LED blinks ten times at approximately one blink per second, then turns off. In gpioinfo, line 17 switches to output during the pulse.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials