🛠 Le Bridge : faire exécuter des commandes Linux depuis le croquis

Arduino Tian (id: tian) · intermediaire · Schéma : IMG-tian-intermediaire-1-tian-bridge-shell-linux.svg — Arduino Tian schématique en deux blocs : puce SAMD21 à gauche, puce AR9342 (Linux/OpenWRT) à droite, flèche UART centrale étiquetée « Bridge », terminal affichant « cat /proc/uptime ».

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials