🛠 GPIO duos : commander les broches de l'Arduino depuis Linux
Objectives
Leverage the Tian's most advanced concept: I/O pins are physically connected to both processors. The Arduino sketch controls them conventionally, but Linux can also claim them via the kernel's standard sysfs interface (/sys/class/gpio), documented in the official Tian datasheet with a mapping table between Arduino pins and Linux GPIO numbers. You will blink an LED from a shell script, without touching the sketch.
Hardware
- 1 powered Arduino Tian, SSH access (web panel/SSH tutorial)
- 1 LED + 330 Ω resistor on a pin that appears in the GPIO mapping table of the official documentation
- The sketch from the Blink tutorial must be removed or must not use the chosen pin (otherwise both sides will conflict)
Procedure
# Côté SSH Linux — N = numéro GPIO correspondant à votre broche,
# à lire dans la table officielle broche Arduino -> GPIO de la Tian.
# >
# celle de la Yun, utiliser la table du document officiel archivé.
N=21 # exemple de valeur, À REMPLACER par la valeur de la table officielle
echo $N > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio$N/direction
while true; do
echo 1 > /sys/class/gpio/gpio$N/value
sleep 0.5
echo 0 > /sys/class/gpio/gpio$N/value
sleep 0.5
done
Expected Verification
The LED blinks at 1 Hz controlled solely by the shell script — the SAMD21 is not involved. Next diagnostic step: upload a sketch that sets the same pin to a fixed state, then rerun the script: the final visible state is that of the last writer. This proves that the hardware is shared and that it is up to you to arbitrate.
Common Errors
- Two masters on the same pin without a protocol: the sketch writes HIGH, a Linux cron writes LOW, the LED flickers erratically. Define one owner per pin (an engineering rule, not a software bug).
- Using the Yun's GPIO table for the Tian: the chips differ (AR9331 vs AR9342), and so does the numbering — always read the table in the official Tian documentation.
- Forgetting
echo out > direction: without a defined direction, writing to value fails with an obscure I/O error. - Leaving GPIOs exported after experimentation:
echo $N > /sys/class/gpio/unexportreleases them cleanly; otherwise, re-exporting fails in the next script. - Confusing the Linux SoC's GPIOs with the "Arduino" pins: not all physical pins are necessarily wired on both sides; only the cases listed in the official table are guaranteed to be dual-controlled.
- In production, prefer a clean bus (I2C, SPI) with a true single master rather than two-headed shared GPIO.
Other tutorials for this board
- Découvrir l'Arduino Tian : un microcontrôleur et un vrai Linux sur la même carte
- Bouton et LED sur les GPIO de la Tian : les bases côté SAMD21
- 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
Code examples for this board
clignotant-rest.inoArduinoconsole-bridge.inoArduinovaleurs-partagees.inoArduinoprocess-shell.inoArduinoserveur-json.inoArduinolecture-fichier.inoArduino