Adjusted datalogger to remove indirection reference and changed from Console to Serial
This commit is contained in:
parent
53779e4bcd
commit
cbfc82e0aa
|
@ -2,45 +2,46 @@
|
||||||
SD card datalogger
|
SD card datalogger
|
||||||
|
|
||||||
This example shows how to log data from three analog sensors
|
This example shows how to log data from three analog sensors
|
||||||
to an SD card mounted on the Linux using the Bridge library.
|
to an SD card mounted on the Arduino Yun using the Bridge library.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
* analog sensors on analog ins 0, 1, and 2
|
* analog sensors on analog ins 0, 1, and 2
|
||||||
* SD card attached to SD card slot of the Arduino Yun
|
* SD card attached to SD card slot of the Arduino Yun
|
||||||
|
|
||||||
You can remove the SD card while the Linux and the
|
You can remove the SD card while the Linux and the
|
||||||
sketch are running but becareful to don't remove it while
|
sketch are running but be careful not to remove it while
|
||||||
the system is writing on it.
|
the system is writing to it.
|
||||||
|
|
||||||
created 24 Nov 2010
|
created 24 Nov 2010
|
||||||
modified 9 Apr 2012
|
modified 9 Apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
adapted to the Yun Bridge library 20 Jun 2013
|
adapted to the Yun Bridge library 20 Jun 2013
|
||||||
by Federico Vanzati
|
by Federico Vanzati
|
||||||
|
modified 21 Jun 2013
|
||||||
|
by Tom Igoe
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <FileIO.h>
|
#include <FileIO.h>
|
||||||
#include <Console.h>
|
#include <Serial.h>
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Initialize the Bridge and the Console
|
// Initialize the Bridge and the Serial
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
Console.begin();
|
Serial.begin(9600);
|
||||||
FileSystem.begin();
|
FileSystem.begin();
|
||||||
|
|
||||||
while(!Console){
|
while(!Serial); // wait for Serial port to connect.
|
||||||
; // wait for Console port to connect.
|
Serial.println("Filesystem datalogger");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop () {
|
void loop () {
|
||||||
// make a string that start with a timestamp for assembling the data to log:
|
// make a string that start with a timestamp for assembling the data to log:
|
||||||
String dataString = "";
|
String dataString = "";
|
||||||
addTimeStamp(dataString);
|
dataString += addTimeStamp();
|
||||||
dataString += " = ";
|
dataString += " = ";
|
||||||
|
|
||||||
// read three sensors and append to the string:
|
// read three sensors and append to the string:
|
||||||
|
@ -62,11 +63,11 @@ void loop () {
|
||||||
dataFile.println(dataString);
|
dataFile.println(dataString);
|
||||||
dataFile.close();
|
dataFile.close();
|
||||||
// print to the serial port too:
|
// print to the serial port too:
|
||||||
Console.println(dataString);
|
Serial.println(dataString);
|
||||||
}
|
}
|
||||||
// if the file isn't open, pop up an error:
|
// if the file isn't open, pop up an error:
|
||||||
else {
|
else {
|
||||||
Console.println("error opening datalog.txt");
|
Serial.println("error opening datalog.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(15000);
|
delay(15000);
|
||||||
|
@ -74,7 +75,8 @@ void loop () {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function append a time stamp to the string passed as argument
|
// This function append a time stamp to the string passed as argument
|
||||||
void addTimeStamp(String &string) {
|
String addTimeStamp() {
|
||||||
|
String result;
|
||||||
Process time;
|
Process time;
|
||||||
time.begin("date");
|
time.begin("date");
|
||||||
time.addParameter("+%D-%T");
|
time.addParameter("+%D-%T");
|
||||||
|
@ -83,6 +85,6 @@ void addTimeStamp(String &string) {
|
||||||
while(time.available()>0) {
|
while(time.available()>0) {
|
||||||
char c = time.read();
|
char c = time.read();
|
||||||
if(c != '\n')
|
if(c != '\n')
|
||||||
string += c;
|
result += c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue