🛠 Pont série entre le MCU Arduino et le SoC x86
Objectives
Understand the internal communication channel of the board: the ATmega32U4 is a real Arduino Leonardo that enumerates on a virtual COM port connected to the x86 processor. This is the channel used internally by pinpong/Firmata; here we repurpose it with our own protocol: a C++ sketch on the MCU side that sends timestamped measurements, and a Python script on the Linux side that reads them using pyserial. By the end, you will master both languages of the board (C++ on the MCU, Python on the SoC) and the bridge between them.
Hardware
- LattePanda 3 Delta running Ubuntu 22.04 (or Windows)
- Arduino IDE (board type Arduino Leonardo) to flash the embedded MCU; use the board's Arduino reset button to enter the bootloader
pip install pyserialon the Linux side- LED on D13 (from tutorial 1) for a meaningful message
Complete Code
MCU side — Arduino IDE sketch (board "Arduino Leonardo", MCU port):
// Pont série : envoie une trame horodatée vers le SoC x86.
const uint8_t LED = 13;
unsigned long last = 0;
bool on = false;
void setup {
pinMode(LED, OUTPUT);
Serial.begin(9600); // USB série interne vers le CPU hôte
}
void loop {
if (millis - last >= 1000) {
last = millis;
on = !on;
digitalWrite(LED, on ? HIGH : LOW);
// Trame simple : LED=<etat>;T=<millis>
Serial.print("LED=");
Serial.print(on ? 1 : 0);
Serial.print(";T=");
Serial.println(millis);
}
}
SoC side — pont_serie.py (Linux: /dev/ttyACM0):
import serial
port = serial.Serial("/dev/ttyACM0", 9600, timeout=1)
print("Écoute du MCU... (Ctrl+C pour quitter)")
try:
for ligne in port:
texte = ligne.decode("utf-8", errors="replace").strip
if not texte:
continue
champs = dict(p.split("=") for p in texte.split(";"))
etat = "ALLUMÉE" if champs.get("LED") == "1" else "éteinte"
print(f"MCU: LED {etat} depuis {champs.get('T')} ms")
finally:
port.close
Expected Verification
The SoC terminal displays "MCU: LED ON for … ms" every second, alternating, synchronized with the D13 LED. Both halves of the board communicate without any external cable.
Common Errors
- Conflict with pinpong: If Firmata is uploaded to the MCU, it takes over the port; re-upload your sketch to regain control.
- Wrong Arduino IDE board: Select "Arduino Leonardo", not "Uno" — the embedded ATmega32U4 is the component found in the Leonardo.
- Missed bootloader: Press the board's Arduino reset button just after uploading to re-enter the bootloader.
- Port already open: Close the Arduino IDE serial monitor before launching pyserial, otherwise the port is occupied or you get a
PermissionError. - Linux access rights: Run
sudo usermod -aG dialout $USERthen log out and back in, otherwise access to/dev/ttyACM0is denied. - Truncated frames: Read line by line (port iterator) rather than raw
read, and always end withprintlnon the MCU side.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton.pyPythonservo.pyPythonanalogique.pyPythonrespiration.pyPythonneopixel.pyPython