releve-periodique.ino
The perfect duo of Yun/Tian boards: the MCU measures, the Linux timestamps and logs to CSV. The analog sensor becomes a standalone recorder, exportable with one scp, no external clock needed.
Hardware
An Arduino Tian (Microchip SAM3X8E + TianOS Linux on an Atheros AR9344, dual USB, Ethernet and Wi-Fi). 1 analog sensor (LDR, potentiometer) on A0.
Wiring
Sensor between A0, 5 V and GND per the divider wiring.
How it works
date +%s provides the epoch on the Linux side (the MCU has no clock); echo >> appends the CSV line. test -f creates the header on first run.
Running it
Arduino IDE with the Arduino Tian board: upload over the « Native » USB port. Linux side: ssh root@arduino.local. The Bridge library is identical to the Yun's.
Variants
Add the SoC temperature to the CSV, or replace the shell with FileIO to avoid spawning processes.
releve-periodique.ino
// Horodateur via le Linux, mesure via le MCU : CSV dans /tmp.
#include <Bridge.h>
#include <Process.h>
const int CAPTEUR = A0;
unsigned long t0 = 0;
String horodatage() {
Process p;
p.runShellCommand("date +%s"); // epoch seconde
String s = p.readString();
while (p.running());
s.trim();
return s.length() ? s : String(millis() / 1000);
}
void setup() {
Bridge.begin();
Serial.begin(9600);
Process init;
init.runShellCommand(
"test -f /tmp/mesures.csv || echo 'epoch,capteur' > /tmp/mesures.csv");
while (init.running());
}
void loop() {
if (millis() - t0 < 30000) return; // 30 s
t0 = millis();
int brut = analogRead(CAPTEUR);
String ligne = horodatage() + "," + String(brut);
Process ecriture;
ecriture.runShellCommand("echo '" + ligne + "' >> /tmp/mesures.csv");
while (ecriture.running());
Serial.print("journalise : ");
Serial.println(ligne);
}
// Cote Linux : scp root@<carte>:/tmp/mesures.csv . pour exporter.