clignotante.py

Cartes Libre Computer à base d'Amlogic — libre-amlogic (produit phare : Le Potato AML-S905X-CC) · 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. python3-gpiod pilote directement la puce GPIO via le noyau, sans bibliothèque propriétaire.

Matériel requis

Une Libre Computer « Le Potato » (Amlogic S905X, 2 Go) sous Armbian, alimentée en 5 V/2,5 A micro-USB, avec son connecteur 40 broches compatible Raspberry Pi. 1 LED + résistance 330 Ω (les broches sont en 3,3 V sur toutes ces cartes).

Branchement

Anode de la LED sur la broche GPIO choisie (voir le schéma de la carte et gpioinfo) via 330 Ω, cathode sur GND.

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 Armbian : sudo apt install gpiod libgpiod-utils python3-gpiod ; les broches du connecteur sont nommées « 7J1 Header PinN » dans gpioinfo. 3,3 V uniquement, aucune broche tolérante 5 V.

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 python3-gpiod (API 1.x, Debian/Armbian).
# Installation : sudo apt install python3-gpiod gpiod
# Puce disponible : gpiodetect ; broches : gpioinfo <puce>
import gpiod
from time import sleep

PUCE = "gpiochip1"   # a verifier avec gpiodetect (varie selon la carte)
LIGNE = 17           # numero GPIO du schema de la carte

chip = gpiod.Chip(PUCE)
line = chip.get_line(LIGNE)
line.request(consumer="clignotante", type=gpiod.LINE_REQ_DIR_OUT,
             default_val=0)

print("Clignotement (Ctrl-C pour arreter)")
try:
    while True:
        line.set_value(1)
        print("LED ON")
        sleep(1)
        line.set_value(0)
        print("LED OFF")
        sleep(1)
finally:
    line.release()

← Retour à la fiche