🛠 Bouton poussoir et console série sur le GIGA R1

Arduino GIGA R1 · debutant · Schéma : IMG-giga-r1-d2-1-bouton-console-serie.svg — Bouton poussoir câblé entre une broche GPIO du GIGA R1 et la masse, avec le câble USB-C reliant la carte au PC pour la console série.

Objectives

Learn how to read a digital input using an internal pull-up resistor and communicate with the PC via the GIGA R1's USB-C serial port. You will also discover a documented pitfall of the Mbed core: native printf does not output to the USB serial port (issue #958); you must use Arduino's Serial object.

Hardware

Complete code

// GIGA R1 WiFi — bouton poussoir + console série
#include <Arduino.h>

const int BOUTON = D2;      // bouton entre D2 et GND (pull-up interne activé)

void setup {
  Serial.begin(115200);     // console série sur USB-C
  pinMode(BOUTON, INPUT_PULLUP);
  Serial.println("Appuyez sur le bouton !");
}

void loop {
  if (digitalRead(BOUTON) == LOW) {   // contact fermé -> LOW (pull-up)
    Serial.println("Bouton appuyé !");
    delay(200);                       // anti-rebond logiciel simple
  }
}

Connect one leg of the button to pin D2 and the other leg to GND. The potential is held high by the internal pull-up as long as the button is open.

Expected verification

At startup, the Serial Monitor (115200 baud) displays "Press the button!". Each press displays "Button pressed!" with a rate limited by the 200 ms debounce. Releasing the button produces no line.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials