🛠 Premier script Python : état de la carte
Objectives
Write your first useful Python script on the ODROID-M1: a status report that displays the RK3568B2 processor (quad Cortex-A55 up to 2 GHz), LPDDR4 RAM (4 or 8 GB), the boot medium, and the M.2 NVMe SSD (PCIe 3.0 x2, approximately 1600 MB/s measured).
Hardware
- ODROID-M1 running Armbian or DietPi (Python 3 preinstalled)
- No electronic components required: everything happens in the console
- Optional: NVMe SSD in the M.2 slot to see the fast disk line
Complete Code
#!/usr/bin/env python3
"""Rapport d'état de l'ODROID-M1 (aucune dépendance)."""
import shutil, os, re
def cpu:
txt = open("/proc/cpuinfo").read
n = len(re.findall(r"^processor", txt, re.M))
return f"{n} coeur(s) détectés (attendu : 4 Cortex-A55)"
def memo:
for l in open("/proc/meminfo"):
if l.startswith("MemTotal"):
return f"RAM : {int(l.split[1]) // 1048576} Go"
def disque:
n = shutil.disk_usage("/")
return f"Racine : {n.used // 2**30} Go utilisés / {n.total // 2**30} Go"
print("== Rapport ODROID-M1 ==")
print(cpu); print(memo); print(disque)
nvme = [p for p in os.listdir("/dev") if p.startswith("nvme")]
print("NVMe M.2 :", nvme if nvme else "aucun SSD installé")
Expected Verification
The script displays 4 cores, the RAM (4 or 8 GB), root disk usage, and the list of nvme0n1 devices if an M.2 SSD is present.
Common Errors
- Running with “python” instead of “python3” on a minimal image.
- Forgetting chmod +x or the shebang, resulting in “Permission denied”.
- Looking for /dev/sda for the NVMe: the M.2 SSD appears as /dev/nvme0n1.
- Confusing storage media: microSD, eMMC module, SATA 3.0, and NVMe can be present simultaneously.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash