Hy,
I'm currently working on a project where i use an SD card with the T4.1. I can succesfully read it out, but now i'd like to make it hotswapable.
i tried just seeing if i can open the file and if not: wait, reopen the sd and try to open the file again. but that doesn't seem to work. Once i take out the SD card, it just grinds to a halt.
greetings,
RayanR
I'm currently working on a project where i use an SD card with the T4.1. I can succesfully read it out, but now i'd like to make it hotswapable.
i tried just seeing if i can open the file and if not: wait, reopen the sd and try to open the file again. but that doesn't seem to work. Once i take out the SD card, it just grinds to a halt.
Code:
// open the file.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
else {
// if the file isn't open, pop up an error:
do{
Serial.println("error opening datalog.txt");
error_blink(2, 2, false);
}
while(!SD.begin(chipSelect));
dataFile = SD.open("datalog.txt", FILE_WRITE);
while(!dataFile)
{
Serial.println("error opening datalog file.txt");
error_blink(2, 2, false);
dataFile = SD.open("datalog.txt", FILE_WRITE);
}
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
greetings,
RayanR