🛠 Bouton et LED sur les GPIO de la Tian : les bases côté SAMD21
Objectives
Control an output and read an input on the Tian's I/O pins driven by the SAMD21: internal pull-up, active-low logic, and discovering the pinout peculiarity — analog inputs A6 to A11 share pins with digital pins 4, 6, 8, 9, 10, and 12, which can cause function conflicts if you don't check the schematic.
Hardware
- 1 Arduino Tian + micro-USB cable
- 1 breadboard, jumper wires
- 1 push button, 1 LED, 1 330 Ω resistor
- Wiring: button between a digital pin (e.g., D2) and GND — the internal pull-up avoids any external resistor; LED + 330 Ω to GND from another pin (e.g., D13).
- >
Complete Code
// Bouton sur D2 (vers GND), LED sur D13.
const uint8_t BTN = 2;
const uint8_t LED = 13;
void setup {
pinMode(BTN, INPUT_PULLUP); // repos = HIGH, appuyé = LOW
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop {
bool appuye = (digitalRead(BTN) == LOW); // logique inversée
digitalWrite(LED, appuye ? HIGH : LOW);
if (appuye) Serial.println(F("bouton appuyé"));
delay(20);
}
Expected Verification
LED off at rest, on when pressed; the Serial Monitor displays a message while pressed. Touch the D2 wire without the button: the input floats and the state becomes random — the internal pull-up is indeed what stabilizes the circuit.
Common Errors
- Using D4, D6, D8, D9, D10, or D12 as both analog and digital inputs simultaneously: A6–A11 are physically on these pins (documented in the Tian's official datasheet); one function overrides the other.
- Inverting active-low logic: here, pressed == LOW; testing == HIGH makes the button seem dead.
- Forgetting the LED resistor: you exceed the maximum current per pin, damaging the LED or the regulator.
- Wiring to the USB host or Ethernet port pins thinking everything is GPIO: only the edge I/O pins are usable, refer to the official schematic.
- Mechanical button bounce: invisible when lighting an LED, critical when counting presses — add a 30 ms window using millis.
Other tutorials for this board
- Découvrir l'Arduino Tian : un microcontrôleur et un vrai Linux sur la même carte
- Lire un capteur avec l'ADC 12 bits du SAMD21
- Le Bridge : faire exécuter des commandes Linux depuis le croquis
- Configurer le WiFi et piloter Linino en SSH
- Télémétrie : pousser une mesure du capteur vers le réseau
- GPIO duos : commander les broches de l'Arduino depuis Linux
Code examples for this board
clignotant-rest.inoArduinoconsole-bridge.inoArduinovaleurs-partagees.inoArduinoprocess-shell.inoArduinoserveur-json.inoArduinolecture-fichier.inoArduino