gpio-led-blink-python.py

Raspberry Pi Smart Display Module · Fichier : gpio-led-blink-python.py · Langage : Python · Usage : Allumer et éteindre une LED connectée aux GPIO pour tester la sortie numérique.

Script simple utilisant la bibliothèque RPi.GPIO pour contrôler une LED via une sortie numérique.

Requiert un Raspberry Pi Smart Display Module avec Compute Module 5. Connectez une LED avec une résistance de 220Ω entre la broche GPIO 17 et la masse. Assurez-vous que la bibliothèque RPi.GPIO est installée via pip. Lancez le script avec sudo python3 script.py pour les permissions GPIO.

gpio-led-blink-python.py

import RPi.GPIO as GPIO
import time

# Configuration des broches GPIO (BCM est la norme sur CM5)
LED_PIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN, GPIO.OUT)

try:
    while True:
        GPIO.output(LED_PIN, GPIO.HIGH)  # Allumer
        print("LED ON")
        time.sleep(1)
        GPIO.output(LED_PIN, GPIO.LOW)   # Éteindre
        print("LED OFF")
        time.sleep(1)
except KeyboardInterrupt:
    GPIO.cleanup()
    print("GPIO nettoyé")

← Retour à la fiche