🛠 Bouton et console série sur la GIGA R1 WiFi

Arduino GIGA R1 WiFi · debutant · Schéma : IMG-giga-r1-wifi-debutant-2-bouton-console-serie.svg — Bouton poussoir câblé entre une broche GPIO et GND avec résistance de pull-up interne, et liaison USB-C vers le moniteur série de l'ordinateur

Objectives

Read a numeric input, debounce it properly, and communicate with the native serial port of the GIGA R1 WiFi (available as soon as it is connected to the USB-C USB0 port, without a USB-to-serial converter). You will also learn the golden rule of pins: 3.3 V logic, never a 5 V signal, and INPUT_PULLUP to avoid wiring to VCC.

Hardware

Complete code

// GIGA R1 WiFi — bouton + console série avec anti-rebond
const int BTN_PIN  = 6;    // bouton vers GND, pull-up interne
const int LED_PIN  = 5;    // LED + 330 ohms vers GND

volatile unsigned long appuis = 0;
int etatPrecedent = HIGH;
unsigned long dernierChangement = 0;
const unsigned long ANTI_REBOND = 30;   // ms

void setup {
  Serial.begin(115200);          // port série natif sur USB-C (USB0)
  while (!Serial) {}             // attend l'ouverture du moniteur (USB natif)
  pinMode(BTN_PIN, INPUT_PULLUP);  // 3.3 V logic — jamais de signal 5 V
  pinMode(LED_PIN, OUTPUT);
  Serial.println("GIGA R1 WiFi prete : appuyez sur le bouton broche 6");
}

void loop {
  int etat = digitalRead(BTN_PIN);
  unsigned long maintenant = millis;
  if (etat != etatPrecedent && maintenant - dernierChangement > ANTI_REBOND) {
    dernierChangement = maintenant;
    etatPrecedent = etat;
    if (etat == LOW) {                       // bouton actif a l'etat LOW (pull-up)
      appuis++;
      digitalWrite(LED_PIN, HIGH);
      Serial.print("Appui n#"); Serial.print(appuis);
      Serial.print(" — uptime "); Serial.print(maintenant / 1000); Serial.println(" s");
    } else {
      digitalWrite(LED_PIN, LOW);
    }
  }
}

Expected verification

Open the serial monitor at 115200 baud: the welcome message is displayed. Each press prints a line like “Press n#1 — uptime 12 s” etc., without spurious duplicates (the 30 ms debounce does its job). The indicator LED lights up during the press.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials