🛠 Bouton MODE et console série sur la Boron
Objectives
Interact with the local user and debug: read the state of the onboard MODE button, count presses, and display messages on the USB serial console via Serial.begin / Serial.println. You will also discover system modes controlled by buttons (Reset + MODE), which are useful in all subsequent tutorials.
Hardware
- 1× Particle Boron + micro-USB data cable
- PC with a serial monitor (VS Code,
particle serial monitor, or your tool of choice)
Complete code
// Boron — bouton MODE + console série
const uint16_t BUTTON_PIN = MODE; // broche du bouton MODE — voir remarque
uint32_t appuis = 0;
uint32_t dernierAppui = 0;
void setup {
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT_PULLUP); // bouton câblé vers la masse
delay(1000); // laisse le moniteur se connecter
Serial.println("Boron prete : appuyez sur MODE");
}
void loop {
uint32_t maintenant = millis;
if (digitalRead(BUTTON_PIN) == LOW && maintenant - dernierAppui > 200) {
dernierAppui = maintenant; // anti-rebond logiciel 200 ms
appuis++;
Serial.printf("Appui n°%lu uptime=%lus\n", appuis, maintenant / 1000);
}
if (maintenant % 10000 < 10) {
Serial.println("tick"); // battement toutes les ~10 s
}
delay(10);
}
Flash the firmware, then open the console: particle serial monitor --follow or the VS Code serial extension (9600 baud).
Expected verification
At startup, the message “Boron prete” is displayed. Each press of the MODE button prints a line with the press number and uptime; a long or repeated press should not produce more than a few lines thanks to debouncing. The “tick” beat confirms that the loop is running. By holding Reset and then pressing MODE, you enter system modes (DFU, listening) — the RGB LED changes color.
Common errors
- Opening the serial monitor while flashing is in progress: the port is occupied, close it before running
particle flash. - Forgetting
INPUT_PULLUP: the pin floats and the counter increments in a loop. - Debounce time too short (< 50 ms): a single press is counted multiple times.
- Wrong baud rate in the monitor (it must be 9600 here): you will see gibberish.
- The USB serial port may disappear under Windows 11 after an OTA update (known community issue): reconnect or reinstall the CDC driver.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-evenement.inoArduinofonction-distance.inoArduinocapteur-dht.inoArduinoruban-neopixel.inoArduinopwm-respiration.inoArduino