Here is where it seems to be the problem:
if (! SD.begin(chipSelect)) { // Check if SD memory card is running
e = 3; // Error #03: Unable to set SD card
error(); // Blink the led and freeze the device
return;
}
if (! SD.exists(filename1)) { // Check and/or create the logdata file on SD Card
datafile = SD.open(filename1, FILE_WRITE); // Create the datafile if it doesn't exist
datafile.close();
if (! SD.exists(filename1)) { // Check if datafile was created
e = 4; // Error #04: Unable to create a file on SD card
error(); // Blink the led and freeze the device
return;
}
delay(50);
datafile = SD.open(filename1, FILE_WRITE); // Open the datafile
if (datafile){
datafile.println("Permarduino_sensors v3a");
delay(30);
datafile.close(); // Close the datafile
}
else {
e = 5; // Error #05: Unable to write on data file
error(); // Blink the led and freeze the device
return;
}
}
So, after the first reset, the led blink 5 times, what means that the file was created, but it was not able to write into the file.
If i push reset button, since the data file already exists, the program continue working and save data into that file...
However, this piece of code is exactly the same for both versions... This is why i suposse that in really it is not a problem in this code section.
Any idea about where could be the problem?