Le programme ci-dessous, permet d'écrire les données de A0 et A1 sur la carte SD de l'arduino yun.

Etape 1 :

Créer un fichier data.txt dans le répertoire arduino\www\data.txt

Etape 2 :

Téléverser le code ci-dessous dans l'arduino yun.

#include <FileIO.h>

#define led 13


void setup() {
// Initialize the Bridge and the Serial
Bridge.begin();
delay(2000);

Serial.begin(9600);

FileSystem.begin();
delay(2000);

while (!SerialUSB); // wait for Serial port to connect.
SerialUSB.println("Filesystem datalogger\n");

pinMode(led,OUTPUT);
}


void loop() {
// make a string that start with a timestamp for assembling the data to log:
digitalWrite(led,LOW);

String dataString;
dataString += getTimeStamp();
dataString += " = ";

// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 2; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
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/sd/data.txt", FILE_APPEND);

// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();

// print to the serial port too:
SerialUSB.println(dataString);

digitalWrite(led,HIGH);
delay(1000);

}
// if the file isn't open, pop up an error:
else {
SerialUSB.println("error opening datalog.txt");
}

delay(15000);

}

// This function return a string with the time stamp
String getTimeStamp() {
String result;
Process time;
// 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;
}

 

En poursuivant votre navigation sur mon site, vous acceptez l’utilisation des Cookies et autres traceurs  pour réaliser des statistiques de visites et enregistrer sur votre machine vos activités pédagogiques. En savoir plus.