gpio-led-blink-python.py

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

Simple script using RPi.GPIO library to control an LED via a digital output.

Requires a Raspberry Pi Smart Display Module with Compute Module 5. Connect an LED with a 220Ω resistor between GPIO pin 17 and ground. Ensure the RPi.GPIO library is installed via pip. Run the script with sudo python3 script.py for GPIO permissions.

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é")

← Back to the board