Can't add data to existing SD file
-
Hi,
I have ported my datalogging program from Arduino Mega to the M5Stack Core 2 for AWS.
It all is now working as I expected except for one behavior.
On the Arduino, I could open an existing file on SD card and append data to the end of the file.
On the M5Stack, I can create, open, write to, and close a file on the SD card.
But when I re-open this file and write more data, it overwrites the existing data in the file.
It appears the FILE_WRITE specifier is allowing write access but is not moving the file pointer to its end...not sure why not?
Can anyone suggest what I am doing wrong or provide a workaround?
Thanks!The relevant portion of my test code is below; apologies if it comes through with weird formatting:
if (!SD.begin(4,SPI,40000000)) { // ******M5 CS line is GPIO4
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.NewFile = SD.open("/TRIAL.TXT",FILE_WRITE); char message1[64]="This is just a test"; // 64 byte array char message2[64]="It seems to be working so far!";
// delay(5000);
// if the file opened okay, write to it:
if (NewFile) {
NewFile.println(message1);
NewFile.println(message2);// close the file: NewFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error initially opening test.txt");
}// Now try reopening file and writing more data into it
delay(100); NewFile = SD.open("/TRIAL.TXT",FILE_WRITE); //*******Reopen for more writing NewFile.println("Trying to add this additional line"); NewFile.close(); delay(100);