I'm using the DFRobot Interface sd card shield(CS pin 10) and trying to print out data from 3 sensor(A0-A2) to 3 different .txt documents.
And the problem is this, after exactly 10 times running the main loop, it can't open the files anymore and starts giving me the error code:
I've been using most of the code from the example for the SD Datalogger with a few tweaks here and there for my purposes:
#include <SD.h>
const int chipSelect = 10;
void setup()
{
Serial.begin(9600);
while (!Serial) {;
}
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
}
void loop()
{
delay(1000);
float sensor = analogRead(A0)*(5.0/1023.0);
File dataFile = SD.open("datalogv.txt", FILE_WRITE);
if (dataFile) {
dataFile.println(sensor);
dataFile.close();
Serial.println(sensor);
}
else {
Serial.println("error opening datalogv.txt");
}
float sensor1 = analogRead(A1)*(5.0/1023.0);
File dataFile1 = SD.open("dataloga.txt", FILE_WRITE);
if (dataFile1) {
dataFile.println(sensor1);
dataFile.close();
Serial.println(sensor1);
}
else {
Serial.println("error opening dataloga.txt");
}
float sensor2 = analogRead(A2)*(5.0/1023.0);
File dataFile2 = SD.open("datalogt.txt", FILE_WRITE);
if (dataFile2) {
dataFile.println(sensor2);
dataFile.close();
Serial.println(sensor2);
}
else {
Serial.println("error opening datalogt.txt");
}
}
To summarise my question, why does it start giving me the: "error opening datalogx.txt" (x for a,t,v) after 10 times?