🛠 Le Bridge : faire exécuter des commandes Linux depuis le croquis
Objectives
Cross the threshold that makes the Tian interesting: the Bridge, a communication layer between the sketch (SAMD21) and Linux (AR9342), running over an internal serial link between the two chips. You will call Linux shell commands from the sketch and retrieve their output — here, the system uptime, readable in /proc/uptime.
Hardware
- 1 Arduino Tian powered via USB (allow time for Linux to boot, ~30 s to 1 min on first boot)
- Micro-USB cable + Arduino IDE with the Tian package
- No external wiring: everything happens between the two brains of the board
Full code
// Exécuter une commande shell côté Linux et lire le résultat.
#include <Bridge.h>
void setup {
Serial.begin(9600);
while (!Serial) { } // attend l'ouverture du port USB
Bridge.begin; // ouvre le canal vers Linux
}
void loop {
// runShellCommand renvoie un Process dont on lit la sortie comme un flux.
BridgeProcess p = Bridge.runShellCommand("cat /proc/uptime");
String uptime = p.readString;
Serial.print(F("Linux uptime: ")); Serial.println(uptime);
delay(5000);
}
Expected verification
After uploading, the Serial Monitor displays a line like “Linux uptime: 83.42 0.00” every 5 s, with the first value continuously increasing: it is indeed the Linux kernel on the AR9342 responding, not the sketch. Cut the power completely and reconnect: the uptime restarts from zero, proving that it is the Linux system doing the counting.
Common errors
- Talking to the Bridge before Linux has finished booting: on the first start after a power cut, the command fails silently; add a retry or wait until the Linux status LED indicates boot completion.
- Confusing the Tian Bridge with the Yun’s: the library and exact API differ (runShellCommand, value map, etc.). >
- Believing that runShellCommand is asynchronous: each read of the output waits for the result; do not call it at 1 kHz in loop.
- Forgetting that Linux can be crashed while the sketch is running: the SAMD21 survives a kernel panic; if the Bridge stops responding, it is the Linux side that needs diagnosis (SSH).
- Injecting user variables into a shell command without escaping: on the Linux side, uncontrolled input becomes a command injection.
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
- 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