When I remove the SD card and try to open a file, I can detect the error properly.
But how do I detect that the card has been replaced after an error? My first thought was to call SD.begin()
again but it appears that this function returns true exactly once and false thereafter.
Simplified example:
void setup() {
SD.begin(pin); // called exactly once. Works.
}
void loop() {
// stuff
}
But this does not:
void setup() {
SD.begin(pin); // first time calling this function: works.
}
void loop() {
delay(1000);
SD.begin(pin); // always fails
}
I'd rather not reset the microcontroller just for this.
SD.end()
function somewhere. That is what you need, but I can't find anything in the reference.