releve-periodique.ino

Arduino Yún · File : releve-periodique.ino · Language : Arduino · Use case : Horodateur Linux + capteur : journal CSV complet sans PC

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 Yun (ATmega32U4 + Linino Linux on an Atheros AR9331, Wi-Fi and Ethernet, microSD slot). 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: select the serial port to upload, then the Arduino Yun board for the monitor. Linux side: ssh root@arduino.local (distribution password). The Yunwizard app configures the network.

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.

← Back to the board