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 Alpha (x86 Intel m3-7Y30, Windows 10 or Linux) with its ATmega32U4 co-processor, Arduino Leonardo compatible, on the 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… The ATmega32U4 is a genuine Leonardo: flash it as « Arduino Leonardo » in the IDE through its internal COM port. Host-side, DFRobot's lattepanda Python library talks to it over serial.
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)