clignotante.py
Le script de mise en jambe sur SBC : une LED branchée sur le connecteur GPIO clignote à 1 Hz. gpiozero est la bibliothèque de référence sur cet OS : elle gère les puces GPIO sans manipulation root.
Matériel requis
Un Compute Module 3/3 Lite (BCM2837) sur Compute Module IO Board v3, alimentée en 5 V, avec Raspberry Pi OS (Bullseye) sur la carte SD ou l'eMMC. 1 LED + résistance 330 Ω (les broches sont en 3,3 V sur toutes ces cartes).
Branchement
Anode de la LED sur la broche physique 11 (GPIO17) via 330 Ω, cathode sur une broche GND (ex. 14).
Fonctionnement
Le script configure la broche en sortie, alterne niveau haut/bas avec sleep(1), et rend proprement la broche (finally) même sur Ctrl-C. Sous Bullseye : sudo apt install python3-gpiozero puis python3 votre_script.py. Les broches suivent la numérotation BCM (GPIO17, GPIO18…) reprise par l'IO Board.
Pour aller plus loin
Remplacez sleep par un motif (rampe PWM via gpiozero PWM / gpiod + threads), ou branchez plusieurs LED en anneau.
clignotante.py
#!/usr/bin/env python3
# Clignotement LED avec gpiozero (bibliotheque recommandee sur cet OS).
# Installation : sudo apt install python3-gpiozero
from gpiozero import LED
from time import sleep
led = LED(17) # GPIO17 = broche physique 11 du connecteur
print("Clignotement : Ctrl-C pour arreter")
try:
while True:
led.on() # la broche passe a 3,3 V
print("LED ON")
sleep(1)
led.off() # la broche repart a 0 V
print("LED OFF")
sleep(1)
except KeyboardInterrupt:
print("Arret propre")
finally:
led.close() # rend la broche a l'etat au repos