🛠 Pont série entre le MCU Arduino et le SoC x86

LattePanda 3 Delta (id: lattepanda-3) · intermediaire · Schéma : IMG-lattepanda-3-intermediaire-1-pont-serie.svg — Diagramme du port série interne : l'ATmega32U4 envoie des trames vers le port COM virtuel lu par un script Python sur le Celeron N5105.

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials