The SD library (https://docs.arduino.cc/libraries/sd/) simplifies accessing SD cards. But I think it may have over-simplified it. After you write data to a file and close the file, how do you know when it is safe to remove the card? Does the write() function block until the writes have finished and all data is flushed to the card?
No. Data are buffered in memory and by default a block is not written to the card until it is full.
When done collecting data, you must use SD .flush() or .close() functions to make sure all data are written to the card.
Those operations are blocking, and as soon as they are finished, you could turn on an LED to indicate that it is safe to remove the card.
Thanks for that! Minor point, though - the SD class doesn't have flush() or close(), but the SDLib::File class does.