Skip to content

Commit 7e039df

Browse files
committed
modified the Datalogger example
1 parent fc880cc commit 7e039df

File tree

1 file changed

+24
-15
lines changed
  • hardware/arduino/avr/libraries/Bridge/examples/Datalogger

1 file changed

+24
-15
lines changed

hardware/arduino/avr/libraries/Bridge/examples/Datalogger/Datalogger.ino

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
SD card datalogger
33
44
This example shows how to log data from three analog sensors
5-
to an SD card mounted on the Arduino Yun using the Bridge library.
5+
to an SD card mounted on the Arduino Yún using the Bridge library.
66
77
The circuit:
8-
* analog sensors on analog ins 0, 1, and 2
9-
* SD card attached to SD card slot of the Arduino Yun
8+
* analog sensors on analog pins 0, 1 and 2
9+
* SD card attached to SD card slot of the Arduino Yún
10+
11+
Prepare your SD card creating an empty folder in the SD root
12+
named "arduino". This will ensure that the Yún will create a link
13+
to the SD to the "/mnt/sd" path.
1014
1115
You can remove the SD card while the Linux and the
1216
sketch are running but be careful not to remove it while
@@ -15,7 +19,7 @@
1519
created 24 Nov 2010
1620
modified 9 Apr 2012
1721
by Tom Igoe
18-
adapted to the Yun Bridge library 20 Jun 2013
22+
adapted to the Yún Bridge library 20 Jun 2013
1923
by Federico Vanzati
2024
modified 21 Jun 2013
2125
by Tom Igoe
@@ -25,7 +29,6 @@
2529
*/
2630

2731
#include <FileIO.h>
28-
#include <Serial.h>
2932

3033
void setup() {
3134
// Initialize the Bridge and the Serial
@@ -34,29 +37,29 @@ void setup() {
3437
FileSystem.begin();
3538

3639
while(!Serial); // wait for Serial port to connect.
37-
Serial.println("Filesystem datalogger");
40+
Serial.println("Filesystem datalogger\n");
3841
}
3942

4043

4144
void loop () {
4245
// make a string that start with a timestamp for assembling the data to log:
43-
String dataString = "";
44-
dataString += addTimeStamp();
46+
String dataString;
47+
dataString += getTimeStamp();
4548
dataString += " = ";
4649

4750
// read three sensors and append to the string:
4851
for (int analogPin = 0; analogPin < 3; analogPin++) {
4952
int sensor = analogRead(analogPin);
5053
dataString += String(sensor);
5154
if (analogPin < 2) {
52-
dataString += ",";
55+
dataString += ","; // separate the values with a comma
5356
}
5457
}
5558

5659
// open the file. note that only one file can be open at a time,
5760
// so you have to close this one before opening another.
5861
// The FileSystem card is mounted at the following "/mnt/FileSystema1"
59-
File dataFile = FileSystem.open("/mnt/sda1/datalog.txt", FILE_APPEND);
62+
File dataFile = FileSystem.open("/mnt/sd/datalog.txt", FILE_APPEND);
6063

6164
// if the file is available, write to it:
6265
if (dataFile) {
@@ -74,17 +77,23 @@ void loop () {
7477

7578
}
7679

77-
// This function append a time stamp to the string passed as argument
78-
String addTimeStamp() {
80+
// This function return a string with the time stamp
81+
String getTimeStamp() {
7982
String result;
8083
Process time;
81-
time.begin("date");
82-
time.addParameter("+%D-%T");
83-
time.run();
84+
// date is a command line utility to get the date and the time
85+
// in different formats depending on the additional parameter
86+
time.begin("date");
87+
time.addParameter("+%D-%T"); // parameters: D for the complete date mm/dd/yy
88+
// T for the time hh:mm:ss
89+
time.run(); // run the command
8490

91+
// read the output of the command
8592
while(time.available()>0) {
8693
char c = time.read();
8794
if(c != '\n')
8895
result += c;
8996
}
97+
98+
return result;
9099
}

0 commit comments

Comments
 (0)