🛠 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

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials