🛠 Bouton poussoir et console série avec le coprocesseur
Objectives
Add a digital input to the LattePanda Alpha's ATmega32U4 coprocessor: a push button read with an internal pull-up resistor, an LED that lights up in response, and most importantly the internal USB serial link connecting the ATmega32U4 to the x86 PC (Core m3-7Y30). This is the fundamental building block for all SoC ↔ MCU communication on this board.
Hardware
- LattePanda Alpha powered by 12 V/3 A or USB-C PD 45 W
- 1 push button, 1 LED + 330 Ω resistor
- Wiring: button between D2 and GND (internal pull-up enabled, no external resistor needed); LED + resistor on D13 to GND
- Arduino IDE on Windows or Linux; the IDE's serial monitor is sufficient for this tutorial
Complete Code
// BlinkAndButton.ino — téléverser sur le coprocesseur, carte "Arduino Leonardo"
const int LED_PIN = 13; // broche numérique compatible Arduino
const int BTN_PIN = 2; // bouton de D2 vers GND (pull-up interne utilisé)
void setup {
pinMode(LED_PIN, OUTPUT);
pinMode(BTN_PIN, INPUT_PULLUP);
Serial.begin(9600); // série USB vers le côté x86 (COM sous Windows, /dev/ttyACM* sous Linux)
}
void loop {
digitalWrite(LED_PIN, digitalRead(BTN_PIN) == LOW ? HIGH : LOW);
if (Serial.available) { // laisse le côté PC nous envoyer des caractères
char c = Serial.read;
Serial.print('got:'); Serial.println(c);
}
delay(20);
}
Then open the IDE's serial monitor (9600 baud) on the coprocessor's port to see got:x displayed when you type.
Expected Verification
Pressing the button → LED on; releasing → LED off. The x86 PC's serial monitor displays got:a for each character typed on the PC keyboard: the internal USB serial link works in both directions.
Common Errors
- Forgetting
INPUT_PULLUPand wiring the button to 3.3 V/5 V without an external resistor: the read state remains undefined (floating pin). - Inverted logic: with a pull-up, a pressed button gives
LOW, notHIGH. - Two programs open on the same serial port (IDE monitor + another script): the second one receives nothing.
- Wrong baud rate: the monitor must be set to 9600, matching
Serial.begin(9600).
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton.pyPythonservo.pyPythonanalogique.pyPythonrespiration.pyPythonneopixel.pyPython