clignotante.py

Raspberry Pi Compute Module 3+ (CM3+ / CM3+ Lite) · Fichier : clignotante.py · Langage : Python · Usage : Faire clignoter une LED depuis un script Python

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+ (BCM2837B0, 1 GB LPDDR4) sur Compute Module IO Board v3, alimentée en 5 V, sous Raspberry Pi OS (Bullseye). 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. Le CM3+ se comporte comme un Pi 3 B+ ; les broches de l'IO Board suivent la numérotation BCM.

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

← Retour à la fiche