🛠 Lire le bouton BOOT sur GPIO9

ESP32-C3 · debutant · Schéma : IMG-esp32-c3-debutant-2-bouton-boot-gpio9.svg — Bouton BOOT du ESP32-C3 câblé entre GPIO9 et GND avec résistance de pull-up interne, compteur d'appuis en console

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials