🛠 Premier script Python : LED et informations système
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
- ODROID-C4 running Armbian current
- Keyboard + HDMI screen or SSH session
- Python 3 is preinstalled on Armbian (
python3 --version)
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
PermissionErroron/sys/class/leds/...: rerun withsudo ./hello_c4.pyorsudo python3 hello_c4.py.- Forgetting the shebang
#!/usr/bin/env python3and then executing./hello_c4.py: the shell refuses or misinterprets the file. - The LED path is written as
blue:statuswith a colon: beware of shell auto-completion which escapes it asblue\:status. - Confusing
brightness(0 or 1 here, the LED has no PWM variation on this node) with a 0-255 value as on other boards. - Running the script under Python 2:
pathliband f-strings require Python 3.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash