bouton.py
The physical button becomes a PC event: 50 Hz polling on the Python side, pull-up handled by the MCU. The ideal trigger for the heavy processing only the x86 can do.
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. 1 push button (D2 to GND).
Wiring
Button between the 50-pin header's D2 pin and a GND pin. Internal pull-up enabled by the script.
How it works
read_digital crosses the PinPong serial bridge (~1 ms); the 20 ms loop debounces. The press can fire subprocess, a camera capture, an email… 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
A full menu with three buttons, or a safety interlock before motor activation.
bouton.py
#!/usr/bin/env python3
# Bouton sur D2 (vers GND, pull-up MCU) -> reaction Python immediate.
from pinpong.board import Board, Pin
import time
Board().begin()
bouton = Pin(Pin.D2, Pin.IN, Pin.PULL_UP)
print("Appuyez sur D2 (Ctrl-C pour sortir)")
dernier = 1
while True:
etat = bouton.read_digital()
if etat != dernier:
dernier = etat
if etat == 0:
print("APPUI ! — horodatage", time.time())
# Ici : lancer un script, piloter un actionneur, logger...
time.sleep(0.02)