🛠 GPIO en Python avec python3-libgpiod sur Le Potato

Libre Computer Amlogic boards — libre-amlogic (flagship: Le Potato AML-S905X-CC) · debutant · Schéma : IMG-libre-amlogic-debutant-3-libre-amlogic-debutant-python-gpiod.svg — Même montage LED que le tuto C (broche 3, GPIOAO_5) piloté cette fois par un script Python via le module gpiod.

Objectives

Control an LED in Python on the Le Potato using the gpiod module provided by the distribution package python3-libgpiod — the officially documented path by Libre Computer to replace RPi.GPIO tutorials.

Hardware

Complete Code

#!/usr/bin/env python3
"""Clignotement broche 3 du Le Potato (chip 0, ligne 5). python3-libgpiod 1.x."""
import gpiod
import time

with gpiod.Chip("0") as chip:            # /dev/gpiochip0
    line = chip.get_lines([5])
    line.request(consumer="blink", type=gpiod.LINE_REQ_DIR_OUT)
    try:
        for _ in range(10):
            line.set_values([1])
            time.sleep(0.2)
            line.set_values([0])
            time.sleep(0.2)
    finally:
        line.release
print("Terminé")

Expected Verification

python3 blink.py turns the LED on and off 10 times. Running gpioinfo gpiochip0 during execution shows line 5 claimed by the consumer “blink”.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials