🛠 Premier script Python : fiche signalétique de la carte et LED

Orange Pi 5 Plus (Rockchip RK3588) · debutant · Schéma : IMG-orangepi-5-plus-debutant-3-opi5p-premier-script-python.svg — Orange Pi 5 Plus avec un terminal affichant modèle, cœurs CPU, température et une LED clignotante pilotée par un script Python

Objetivos

Escribir su primer script Python en la Orange Pi 5 Plus: leer la ficha técnica de la placa (modelo del device-tree, número de núcleos, temperatura de la CPU) desde /sys y /proc, y luego hacer parpadear el LED del tutorial 1 desde Python mediante libgpiod. El RK3588 expone 8 núcleos (4 Cortex-A76 hasta 2,4 GHz + 4 Cortex-A55 hasta 1,8 GHz): el script los cuenta automáticamente.

Material

Código completo

#!/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é.")

Verificación esperada

python3 fiche.py muestra «Xunlong Orange Pi 5 Plus», aarch64, 8 núcleos, una o varias temperaturas (30 a 50 °C en reposo), y luego el LED parpadea 3 veces. El device-tree mainline tiene como compatible xunlong,orangepi-5-plus.

Errores frecuentes

Otros tutoriales para esta placa

Ejemplos de código para esta placa

← Volver a la ficha 🛠 Todos los tutoriales