🛠 Premier script Python 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
- ODROID-C2 with a recent ARMv8 distribution (python3 preinstalled)
- No external components: the blue LED is onboard (c2:blue:alive in mainline, blue:heartbeat on Arch/vendor)
- Terminal access: uart_AO serial console 115200 8N1 or SSH
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
- Writing to /sys/class/leds without sudo: permission denied (or dedicated udev configuration).
- Attempting to write to brightness while a trigger is active: the value is ignored, set the trigger to “none” first.
- Forgetting the shebang and chmod +x, then running ./sante.py directly.
- Looking for a /sys/class/leds named “led0”: the names are those from the DTS, not generic names.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash