From 44e6976a6ec2add6c1d175ed9969f50c01a9c2bc Mon Sep 17 00:00:00 2001 From: Fede85 Date: Mon, 1 Jul 2013 17:58:03 +0200 Subject: modified the Datalogger example --- .../Bridge/examples/Datalogger/Datalogger.ino | 39 +++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'libraries/Bridge/examples') diff --git a/libraries/Bridge/examples/Datalogger/Datalogger.ino b/libraries/Bridge/examples/Datalogger/Datalogger.ino index 5878e05..2d792a4 100644 --- a/libraries/Bridge/examples/Datalogger/Datalogger.ino +++ b/libraries/Bridge/examples/Datalogger/Datalogger.ino @@ -2,11 +2,15 @@ SD card datalogger This example shows how to log data from three analog sensors - to an SD card mounted on the Arduino Yun using the Bridge library. + to an SD card mounted on the Arduino Yún using the Bridge library. The circuit: - * analog sensors on analog ins 0, 1, and 2 - * SD card attached to SD card slot of the Arduino Yun + * analog sensors on analog pins 0, 1 and 2 + * SD card attached to SD card slot of the Arduino Yún + + Prepare your SD card creating an empty folder in the SD root + named "arduino". This will ensure that the Yún will create a link + to the SD to the "/mnt/sd" path. You can remove the SD card while the Linux and the sketch are running but be careful not to remove it while @@ -15,7 +19,7 @@ created 24 Nov 2010 modified 9 Apr 2012 by Tom Igoe - adapted to the Yun Bridge library 20 Jun 2013 + adapted to the Yún Bridge library 20 Jun 2013 by Federico Vanzati modified 21 Jun 2013 by Tom Igoe @@ -25,7 +29,6 @@ */ #include -#include void setup() { // Initialize the Bridge and the Serial @@ -34,14 +37,14 @@ void setup() { FileSystem.begin(); while(!Serial); // wait for Serial port to connect. - Serial.println("Filesystem datalogger"); + Serial.println("Filesystem datalogger\n"); } void loop () { // make a string that start with a timestamp for assembling the data to log: - String dataString = ""; - dataString += addTimeStamp(); + String dataString; + dataString += getTimeStamp(); dataString += " = "; // read three sensors and append to the string: @@ -49,14 +52,14 @@ void loop () { int sensor = analogRead(analogPin); dataString += String(sensor); if (analogPin < 2) { - dataString += ","; + dataString += ","; // separate the values with a comma } } // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. // The FileSystem card is mounted at the following "/mnt/FileSystema1" - File dataFile = FileSystem.open("/mnt/sda1/datalog.txt", FILE_APPEND); + File dataFile = FileSystem.open("/mnt/sd/datalog.txt", FILE_APPEND); // if the file is available, write to it: if (dataFile) { @@ -74,17 +77,23 @@ void loop () { } -// This function append a time stamp to the string passed as argument -String addTimeStamp() { +// This function return a string with the time stamp +String getTimeStamp() { String result; Process time; - time.begin("date"); - time.addParameter("+%D-%T"); - time.run(); + // date is a command line utility to get the date and the time + // in different formats depending on the additional parameter + time.begin("date"); + time.addParameter("+%D-%T"); // parameters: D for the complete date mm/dd/yy + // T for the time hh:mm:ss + time.run(); // run the command + // read the output of the command while(time.available()>0) { char c = time.read(); if(c != '\n') result += c; } + + return result; } -- cgit v1.2.3-18-g5258