tableau_bord.py

LattePanda 3 Delta (id: lattepanda-3) · File : tableau_bord.py · Language : Python · Use case : Servir un tableau de bord web mêlant PC et broches

The duo's best in 25 lines: the MCU pin and the PC counters merge into one auto-refresh HTML page. Any phone on the network becomes the machine's interface.

Hardware required

A LattePanda 3 Delta (x86 Intel N5105, Windows 10/11 or Ubuntu) with its Arduino-compatible co-processor (ATmega32U4) wired to the two 50-pin headers. Network access (the board's cable or Wi-Fi).

Wiring

No wiring for the demo; sensor on A0 for the value. Open port 8080 if a firewall is on.

How it works

Each HTTP request re-reads the pin via PinPong and queries psutil; the 2 s refresh keeps the page live without JavaScript. http.server is plenty on a LAN. Host side: pip install pinpong then python3. MCU side: the ATmega32U4 shows up as a COM port — program it with the Arduino IDE (« Arduino Leonardo » board).

Going further

Write control (HTML buttons → POST → servo), or exposure to an MQTT dashboard.

tableau_bord.py

#!/usr/bin/env python3
# Tableau de bord : mesures MCU (PinPong) + etat hote, en HTTP local.
from pinpong.board import Board, Pin
import psutil
from http.server import BaseHTTPRequestHandler, HTTPServer
import time

Board().begin()
capteur = Pin(Pin.A0, Pin.IN)

class Gestionnaire(BaseHTTPRequestHandler):
    def do_GET(self):
        brut = capteur.read_analog()
        html = f"""<meta http-equiv=refresh content=2>
<h1>LattePanda</h1>
<p>A0 : {brut} / 1023 ({brut * 5 / 1023:.2f} V)</p>
<p>CPU : {psutil.cpu_percent():.0f} % — RAM : {psutil.virtual_memory().percent:.0f} %</p>
<p>Uptime : {time.time() - psutil.boot_time():.0f} s</p>"""
        self.send_response(200)
        self.send_header("Content-Type", "text/html; charset=utf-8")
        self.end_headers()
        self.wfile.write(html.encode())

print("http://<ip-de-la-panda>:8080")
HTTPServer(("0.0.0.0", 8080), Gestionnaire).serve_forever()

← Back to the board