🛠 GPIO en Python avec python3-libgpiod sur Le Potato
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
- Le Potato AML-S905X-CC running Armbian or mainline Debian/Ubuntu
- LED + 330 Ω resistor on physical pin 3 (GPIOAO_5 = chip 0, line 5), ground connected to a GND pin
sudo apt install python3-libgpiod— do NOT usepip install gpiod
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
module 'gpiod' has no attribute 'Chip': The pip packagegpiodconflicts withpython3-libgpiod; uninstall the pip package (pip uninstall gpiod) — this error is documented on the official hub.- API v2: On recent distributions, the signatures of
chip.get_line/line.requesthave changed; check the installed version before copying an example. - Forgetting
line.release: The line remains claimed and blocks other programs. - Permission denied: Add the user to the
gpiogroup or run as root.
Other tutorials for this board
- Faire clignoter une LED en C avec libgpiod sur Le Potato
- Lire un bouton poussoir avec libgpiod (pull-up interne)
- Fondu LED progressif avec PWM sous sysfs (meson)
- Capteur BME280 (I2C) sur Le Potato : overlay et lecture
- Console série (ttyAML0) et SSH sur Le Potato
- Boot SD/eMMC et récupération (pyamlboot) sur Amlogic S905X
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash