🛠 Premier script Python : fiche signalétique de la carte et LED
Objectives
Write your first Python script on the Orange Pi 5 Plus: read the board's identification data (device-tree model, number of cores, CPU temperature) from /sys and /proc, then blink the LED from tutorial 1 using Python via libgpiod. The RK3588 exposes 8 cores (4 Cortex-A76 up to 2.4 GHz + 4 Cortex-A55 up to 1.8 GHz): the script counts them automatically.
Hardware
- Orange Pi 5 Plus running Armbian or Orange Pi OS image (ARM64 Debian/Ubuntu)
- LED + 330 Ω resistor on pin 7 (tutorial opi5p-led-gpio)
- Packages:
sudo apt install -y python3 python3-gpiod
Complete code
#!/usr/bin/env python3
"""Fiche signalétique Orange Pi 5 Plus + clignotement LED (broche 7)."""
import pathlib, platform, time
import gpiod # API v1 (libgpiod 1.x, images Debian 11 / Ubuntu 22.04 / Armbian)
def read(path):
try:
return pathlib.Path(path).read_text.strip("\x00").strip
except OSError:
return "n/a"
print("Modèle :", read("/proc/device-tree/model"))
print("Machine :", platform.machine)
print("Cœurs :", len(list(pathlib.Path("/sys/devices/system/cpu").glob("cpu[0-9]*"))))
for z in sorted(pathlib.Path("/sys/class/thermal").glob("thermal_zone*/temp")):
print("Temp :", z.parent.name, int(z.read_text) / 1000.0, "°C")
chip = gpiod.Chip("gpio1")
line = chip.get_line(30) # broche 7 = GPIO1_D6
line.request(consumer="tuto", type=gpiod.LINE_REQ_DIR_OUT)
for _ in range(3):
line.set_value(1); time.sleep(0.3)
line.set_value(0); time.sleep(0.3)
line.release
print("Terminé.")
Expected verification
python3 fiche.py displays "Xunlong Orange Pi 5 Plus", aarch64, 8 cores, one or more temperatures (30 to 50 °C at idle), then the LED blinks 3 times. The mainline device-tree has the compatible string xunlong,orangepi-5-plus.
Common errors
- libgpiod API: the example uses the v1 API (
get_line/request) found in shipped distributions; recent images with libgpiod 2.x have a different API (chip.find_line, line-based requests). - Running without GPIO permissions: run with
sudoif the user is not in thegpio/rendergroup. - Forgetting
line.release: the line remains claimed and gpioset subsequently fails with GPIOBUSY. - >
Other tutorials for this board
- Allumer une LED via le GPIO 40 broches (libgpiod)
- Lire un bouton poussoir et afficher dans la console
- Variation d'intensité d'une LED avec PWM (sysfs pwm)
- Lire un capteur I2C (BMP280) depuis le bus du connecteur
- Exploiter le double Ethernet 2,5 GbE et sécuriser le SSH
- Booter sur NVMe (M.2 PCIe 3.0 x4) et récupérer une carte brique via MaskROM
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash