Hi everyone.
Are there any code or function be able to check if the file save to wrote to a SD card finished or not?
Thanks
Adam
I think that you will find that the write() function does not return until the writing is complete and you can always follow the write() with a close() to make sure that the action is complete.
If you want to make sure that the write completed successfully then you could read the file back and count the number of characters or lines in it
From the tone of your question it sounds like you have had problems. If so, what are they and how do they manifest themselves ?
thank you UKHeliBob.
yes, I got a problem of SD card was corrupted every time removed from ESP32CAM, and the reason was found by tjaekel in my last asking.
and tjaekel also advised some good suggestions, I checked them later on, and tested some and realized I can't accomplish it.
its why asked here for more specific solution.
I'll check follow the write() with a close() and see. just are there any code examples please?
Do you really need an example just to follow a print() with a close() ?
Look at the SD ReadWrite example in the IDE
if (myFile)
{
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
}
thank you.
its nice.
what I am doing is save pictures to SD card, I can see that the ESP32CAM take and saved picture on it from serial monitor.
there do have a file.close(); in that code.
still SD card corrupted .
is there a good example which works well with ESP32CAM + SD without card corrupted?
Is Google broken where you live ?
no, google is OK here.
and my last asking used the sketch from this same link (I guess all of this kink same source ).
any others?
What class of SD card are you using ?
the RED card be recognized of 4G, 32G.
the BLACK never be recognized, don't why.
I just think maybe can set one of SD pins LOW in code after write, and set HIGH when write? may any bad for hardware?
well depends what you call "complete"
in the SD library, write() or print() just add the data to the 512 byte buffer and only when the buffer is full, it gets committed on the SD card and really saved. So a power loss or extracting the card at this point will result in missing data and possibly corrupted file system.
Calling file.flush() ensures that any bytes written to the file are physically saved to the SD card. This is done automatically when the file is closed, so closing is an option too (but you have to possibly open again later)
Thank you J-M-L.
Rui Santos' sketch used: SD_MMC.begin() and file.close(); as a pair.
is it right to use file.close(); will totally shunt SD? no need MMC.end(); kind of code? or I even think of to set GPIO 12 = LOW; after write.
if you use the The SD/SDIO/MMC driver then stick to those API. it's not Arduino's SD card library
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
