As for how best to use this, I don't know. I can't see a problem with mounting and unmounting all the time.
No, there shouldn't be a problem with unmounting/re-mounting (there may be a little more SD card wear over just leaving the file open and appending to it though).
However it does seem to take a while to re-initialise the SD card (also to open the file), during which time Espruino won't be doing anything else (unless you're able to record using
Waveform, which uses interrupts), so potentially you could lose data during that time.
Personally I wouldn't unmount each time because of the above.
One potential fix might be to use the 'card detect' switch. It's not wired up on the Espruino board, but you could solder it to a GPIO pin. You could use
setWatchon it to detect when the card was being ejected and to then close the file, unmount, and stop writing.
Whether you can do that quick enough not to cause damage to the SD card, I really don't know I'm afraid.
Hi, what's the best practice for making sure the SD card gets properly unmounted? Of course this could be done with a button, but that's cumbersome.
I'm developing a logger for my brainwave recorder which basically is supposed to write data to the SD card for hours at a low data rate. The way I'm currently doing it is I append the new data to a variable and every 5 seconds I append the contents of that variable to a file and immediately unmount the SD. I also turn on an LED while this takes place. That way, the user can easily turn off the device or remove the SD in the 5 second intervals while the LED is off.
Is there anything bad about unmounting and re-mounting the SD all the time? Any other reason why this is bad practice?