🛠 Premier script Python sur la bête de 256 Mo

Raspberry Pi Model A (2013) — Board Sheet · debutant · Schéma : IMG-model-a-debutant-3-modela-premier-python.svg — Raspberry Pi Model A relié à un écran HDMI affichant un terminal avec un script Python, carte SD grand format insérée dans le logement, blocs mémoire 256 Mo et ARM11 700 MHz annotés

Objectives

Hardware

Complete code

#!/usr/bin/env python3
"""Inventaire express du Model A."""
import subprocess, shutil, platform

def cmd(c):
    return subprocess.run(c, shell=True, capture_output=True,
                          text=True).stdout.strip

print("machine :", platform.machine)
print("cpu     :", cmd("awk -F: 'NR==1{print $2}' /proc/cpuinfo"))
print("temp    :", cmd("vcgencmd measure_temp"))
print("freq    :", cmd("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"), "kHz")
m = shutil.disk_usage("/")
print("sd libre:", m.free // (1024 * 1024), "Mo")
chmod +x inventaire.py && ./inventaire.py

Expected verification

The script displays armv6l, a temperature in degrees Celsius, the current frequency in kHz (700000 at maximum unthrottled), and the free space on the SD card. >

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials