🛠 Premier script Python : LED et informations système

ODROID-C4 (Hardkernel) · debutant · Schéma : IMG-odroid-c4-debutant-3-odroidc4-premier-python.svg — ODROID-C4 relié à un écran HDMI affichant un terminal Python, LED status clignotant au rythme du script.

Objectives

Write your first Python 3 script on the ODROID-C4: display information about the Amlogic S905X3 SoC (4 Cortex-A55 cores) and blink the status LED via sysfs, without external GPIO dependencies. You will learn how to create, make executable, and run a script, and how to manipulate files in /sys from Python.

Hardware

Complete code

#!/usr/bin/env python3
"""hello_c4.py - infos système + clignotement LED status."""
import pathlib
import platform
import time

led = pathlib.Path("/sys/class/leds/blue:status")
led.joinpath("trigger").write_text("none")   # libérer la LED du heartbeat

cpu = pathlib.Path("/proc/cpuinfo").read_text
coeurs = cpu.count("processor")
print(f"Architecture : {platform.machine}")
print(f"Cœurs détectés : {coeurs} (Amlogic S905X3, Cortex-A55)")

for i in range(10):
    led.joinpath("brightness").write_text("1" if i % 2 == 0 else "0")
    time.sleep(0.4)
led.joinpath("brightness").write_text("0")
print("Terminé : 5 clignotements effectués.")

Run: chmod +x hello_c4.py && ./hello_c4.py

Expected verification

The terminal displays Architecture : aarch64, Cœurs détectés : 4, then the blue LED blinks 5 times (0.4 s per state) before turning off. The script terminates on its own and returns control. If you rerun it without touching the trigger, the blinking still works: trigger=none persists as long as the system is running.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials