🛠 Pont série SoC ↔ MCU : le tunnel x86 vers ATmega32U4
Objectives
Set up the central pattern of the LattePanda Alpha: the serial bridge between the x86 PC (Core m3-7Y30) and its own ATmega32U4 coprocessor, connected via an internal USB invisible from the outside. The MCU sends measurement frames over Serial, and a Python script on the host reads them line by line. This is exactly the scheme of DFRobot's official "python_arduino_bridge" tutorial, without Firmata.
Hardware
- LattePanda Alpha (Windows or Linux) + compliant 12 V/3 A power supply
- Arduino IDE (on the MCU side) and Python 3 with pyserial on the host side:
pip install pyserial - On Linux: add the user to the
dialoutgroup (sudo usermod -aG dialout $USER, then log out and back in) - Optionally, a potentiometer between 5 V, A0, and GND to see values change (implicit 5 V ADC reference for Leonardo)
Complete Code
On the firmware side (Arduino IDE, board "Arduino Leonardo"):
// stream_analog.ino — envoie A0 au PC hôte à 10 Hz
void setup { Serial.begin(9600); }
void loop {
Serial.println(analogRead(A0)); // valeur ADC 10 bits : 0..1023
delay(100);
}
On the host side (on the Alpha itself, Windows or any Linux distribution):
# host_reader.py — pas besoin de Firmata, tramage série simple
import serial # pip install pyserial
# Windows : 'COM5' | Linux : '/dev/ttyACM0' (utilisateur dans le groupe 'dialout')
with serial.Serial('COM5', 9600, timeout=1) as ser:
for line in ser:
try:
raw = int(line.strip)
print(f'ADC={raw} ({raw * 5.0 / 1023:.2f} V en supposant une référence 5 V)')
except ValueError:
pass # ignorer les lignes partielles au démarrage
Expected Verification
The host terminal displays approximately 10 lines per second: ADC=0 (0.00 V) at rest, and values rising towards 1023 if a potentiometer is wired to A0. Ctrl+C stops the script without touching the firmware, which continues to transmit autonomously.
Common Errors
- Wrong port: on Windows, check the COM number in Device Manager; on Linux,
ls /dev/ttyACM*. - Incomplete lines on the first byte after opening the port: the
try/except ValueErroris essential. - Two programs connected to the same port (IDE serial monitor open in parallel with the script): the script receives nothing.
- Forgetting the
delay(100)on the MCU side: the host is flooded and the display becomes unreadable.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton.pyPythonservo.pyPythonanalogique.pyPythonrespiration.pyPythonneopixel.pyPython