Why does my SD card corrupt on arduino rescue?
I have a 4GB Kingston micro SD card and a datalogger code that deletes the exiting file and creates a new one with the new values of the variables. Below is the Code:
void back_var() {
SD.remove("/backup/BACKUP.txt");
char var_up[] = "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;";
sprintf(
variaveis, //Nome da String a ser criada
var_up, //Char utilizado para armazenar a String
valor1, //Informações
valor2,
valor3,
valor4,
valor5,
valor6,
valor7,
valor8,
valor9,
valor10,
valor11,
valor11,
valor12,
valor13,
valor14,
valor15
);
Serial.println("Print das variáveis:");
Serial.println(variaveis);
Serial.println(botoeira_entrada_S15);
SD.begin (4);
backup = SD.open("/backup/BACKUP.txt", FILE_WRITE);
if (backup) {
Serial.println("Inserindo variáveis no SD...");
backup.print(variaveis);
backup.print('|');
Serial.println("Variáveis inseridas no SD!");
backup.close();
}
else {
Serial.println("Erro ao abrir arquivo de Update");
}
}
The problem is that after a certain time the txt file is corrupted and other unreadable files are created.
Why does this occur? And how to solve?
Below are the unreadable files created:
0
Author: Sarah Tavares, 2019-07-17