🛠 Bouton poussoir et console série sur le GIGA R1
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
- 1 Arduino GIGA R1 WiFi board
- 1 push button
- 1 USB-C data cable
- No resistor required: we enable the internal pull-up
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
- Logic confusion: with
INPUT_PULLUP, the signal is LOW when pressed, not HIGH. - Button connected between the pin and 3.3 V without a resistor: short circuit or inverted reading.
- Expecting output from a C
printf("...")in the Serial Monitor: on the GIGA's Mbed core,printfdoes not reach the USB serial port (bug #958, fixed since); always useSerial.print. - Serial Monitor closed or wrong baud rate: no visible output.
- Forgetting the
delay(200)debounce: bursts of phantom presses.
Other tutorials for this board
- Faire clignoter la LED de l'Arduino GIGA R1
- Potentiomètre et sortie DAC sur la prise audio du GIGA R1
- Piloter un micro-servo avec la PWM du GIGA R1
- Connecter un capteur I2C sur le GIGA R1
- Publier des données en MQTT/HTTP via le Wi-Fi du GIGA R1
- Programmer les deux cœurs M7 et M4 du GIGA R1 et les faire communiquer
Code examples for this board
clignotante.inoArduinobouton.inoArduinorespiration.inoArduinoanalogique.inoArduinodac-onde.inoArduinooled-i2c.inoArduino