🛠 Premier script Python sur l'ODROID-C2

Hardkernel ODROID-C2 (Amlogic S905) · debutant · Schéma : IMG-odroid-c2-debutant-3-odroidc2-premier-python.svg — script Python pilotant la LED bleue via /sys/class/leds sur l'ODROID-C2

Objectives

Write the first Python 3 script for the board: query the system (number of Cortex-A53 cores, memory) and control the user blue LED via the kernel LED class — without proprietary libraries, thus compatible with Armbian, Arch Linux ARM, DietPi, and vendor images.

Hardware

Complete code

#!/usr/bin/env python3
"""sante.py — etat systeme + LED bleue via /sys/class/leds."""
import os
from pathlib import Path
from glob import glob

print("--- ODROID-C2 (Amlogic S905, quad Cortex-A53) ---")
print("Coeurs CPU :", os.cpu_count)
chemin = next(iter(glob("/sys/class/leds/*blue*")), None)
assert chemin, "LED bleue introuvable"
led = Path(chemin)
print("LED detectee :", led.name)

trig = led / "trigger"
if trig.exists:
    print("Trigger actuel :", trig.read_text.strip)

for etat in (1, 0) * 3:          # 3 clignotements
    (led / "brightness").write_text(str(etat))
    print("LED", "allumee" if etat else "eteinte")
    import time; time.sleep(0.4)

# retour au rythme cardiaque par defaut
if trig.exists:
    trig.write_text("heartbeat")
print("Trigger remis sur heartbeat.")

Expected verification

The script displays 4 cores, the exact name of the detected LED, makes the blue LED blink 3 times, then returns it to the heartbeat trigger. On Armbian the name is c2:blue:alive, on Arch/vendor blue:heartbeat: the glob handles both.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials