I am trying to store certain text in SC Card memory, but the SD Card save the last line or it does not work at all I'm working with ESP32 microcontroller this is my code
#include <SPI.h>
#include <SD.h>
File myFile;
int i=0;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(5)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
}
void loop() {
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing"+i);
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
i++;
}
it must print
{testing 0
testing 1
testing 2
.....
testing n
}
where n={0-infinity} but it just saves the last line which {testing n } the last line


last line? ... it is unclear what is the problem ... please provide a clear description of what happens – jsotola Aug 15 '20 at 17:57esp32 sd file append– jsotola Aug 16 '20 at 16:20