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

Banana Pi BPI-CM5: Amlogic A311D2 Compute Module with Raspberry Pi CM4 Compatibility · File : bpi-cm5-gpio-led-blink-python.py · Language : Python · Use case : Faire clignoter une LED connectée à une broche GPIO pour tester la sortie numérique.

Python script using gpiozero library to control an LED via GPIO 18.

Ensure the Banana Pi BPI-CM5 module is powered and running a Linux distribution (Ubuntu/Debian). GPIO 18 corresponds to physical pin 12 on the CM4-compatible connector. Install the library with 'sudo apt install python3-gpiozero'. Run the script with sudo if needed. Modify the GPIO number as required.

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()

← Back to the board