🛠 Lire le bouton BOOT sur GPIO0 sans se piéger

ESP32-S3 · debutant · Schéma : IMG-esp32-s3-debutant-2-esp32-s3-bouton-boot-gpio0.svg — Bouton BOOT d'une carte ESP32-S3 relié à GPIO0 avec pull-up interne, un second bouton externe sur GPIO1, câble USB vers l'ordinateur.

Objectives

Learn how to read a digital input on the ESP32-S3 using the BOOT button (GPIO0), while understanding why this pin is special: GPIO0 is a strapping pin that determines the boot mode (flash or execution). You will write a program that detects button presses with software debouncing, and you will understand the golden rule: never force GPIO0 to a LOW state during power-up, otherwise the board will think you want to flash it.

Hardware

Complete code

// GPIO0 = bouton BOOT embarque (vers GND), pull-up interne obligatoire
// GPIO1 = bouton externe optionnel, entre GPIO1 et GND
const uint8_t BTN_BOOT = 0;
const uint8_t BTN_EXT  = 1;

unsigned long dernierAppui = 0;
const unsigned long ANTI_REBOND = 60;   // ms

void setup {
  Serial.begin(115200);
  pinMode(BTN_BOOT, INPUT_PULLUP);
  pinMode(BTN_EXT,  INPUT_PULLUP);
}

void loop {
  if (digitalRead(BTN_BOOT) == LOW && millis - dernierAppui > ANTI_REBOND) {
    dernierAppui = millis;
    Serial.println("Bouton BOOT (GPIO0) presse !");
  }
  if (digitalRead(BTN_EXT) == LOW && millis - dernierAppui > ANTI_REBOND) {
    dernierAppui = millis;
    Serial.println("Bouton externe (GPIO1) presse !");
  }
  delay(5);
}

Expected verification

Open the serial monitor at 115200 bauds: each press of the BOOT button prints a single line, without duplicates due to bouncing. The second button (if wired between GPIO1 and GND) behaves identically. The board restarts normally after a reset: GPIO0 was never held LOW during power-up.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials