bpi-cm5-gpio-led-blink-python.py

Banana Pi BPI-CM5 : Module Compute SoC Amlogic A311D2 compatible Raspberry Pi CM4 · Fichier : bpi-cm5-gpio-led-blink-python.py · Langage : Python · Usage : Faire clignoter une LED connectée à une broche GPIO pour tester la sortie numérique.

Script Python utilisant la bibliothèque gpiozero pour contrôler une LED via le GPIO 18.

Assurez-vous que le module Banana Pi BPI-CM5 est alimenté et que le système Linux (Ubuntu/Debian) est installé. Le GPIO 18 correspond au broche physique 12 du connecteur CM4 compatible. Installez la bibliothèque avec 'sudo apt install python3-gpiozero'. Exécutez le script avec les droits sudo si nécessaire. Modifiez le numéro de GPIO selon vos besoins.

bpi-cm5-gpio-led-blink-python.py

#!/usr/bin/env python3
# BPI-CM5 GPIO LED Blink Example
# Nécessite : sudo apt install python3-gpiozero
# Wiring : LED (+) -> GPIO 18 (Physical Pin 12), LED (-) -> GND (Physical Pin 14)

from gpiozero import LED
from time import sleep

# Initialisation de la LED sur le GPIO 18
led = LED(18)

try:
    while True:
        led.on()
        print("LED ON")
        sleep(1)
        led.off()
        print("LED OFF")
        sleep(1)
except KeyboardInterrupt:
    print("Programme interrompu")
    led.off()

← Retour à la fiche