🛠 Lire le bouton BOOT sur GPIO9
Objectives
Use the BOOT button on the ESP32-C3 as a real application input. On these boards, BOOT is connected to GPIO9, active low: we read it with an internal pull-up resistor. You will discover the strapping role of GPIO9 (held pressed during a reset, it forces flash mode) and how to prevent issues.
Hardware
- 1 ESP32-C3 board (the embedded BOOT button is sufficient)
- 1 USB-C data cable
- Optional: external button on GPIO9 to GND
Complete code
const uint8_t BOUTON = 9; // bouton BOOT, actif a l'etat BAS
uint8_t etatPrecedent = HIGH;
uint32_t dernierAppui = 0;
uint32_t compteur = 0;
void setup {
Serial.begin(115200);
pinMode(BOUTON, INPUT_PULLUP);
}
void loop {
uint8_t etat = digitalRead(BOUTON);
if (etat == LOW && etatPrecedent == HIGH &&
millis - dernierAppui > 50) { // anti-rebond 50 ms
dernierAppui = millis;
compteur++;
Serial.printf("Appui n%u sur BOOT\n", compteur);
}
etatPrecedent = etat;
delay(5);
}
Expected verification
Each press of BOOT displays "Press n1 on BOOT", "Press n2...", etc., without duplicates thanks to debouncing. If BOOT is held while resetting, the board enters download mode (log "Download mode"): this is the expected strapping behavior, not a bug.
Common errors
- INPUT_PULLDOWN instead of INPUT_PULLUP: the button connects to ground, so the pull-up is required; with pull-down, the input stays at 0 and no edge is detected.
- Confusing application press and reset press: GPIO9 is sampled at startup (strapping); a press held during flashing blocks program execution.
- Debounce time too short (5 ms): mechanical bouncing visible as double presses.
- Waiting for an edge on GPIO9 via interrupt during deep sleep: plan for a dedicated RTC wake-up pin instead.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinorespiration.inoArduinodht22.inoArduinooled-i2c.inoArduinoserveur-web.inoArduino