Hi, I am working on a project using the Teensy 4.1's built in SD card reader to read data from text files. I have pretty much everything working, just minor tweaks at this point. One thing I've been trying to figure out is preventing my program from crashing if the SD card gets unplugged mid program. I was thinking there would be a simple function to test whether an SD card was plugged in, but looking at the documentation I haven't been able to find one. Something like SD.exists() or SD.isPluggedIn() type function.
Essentially, I'm finding if the SD card gets unplugged mid runtime, my program crashes when I get to a file.read() statement. I'd like to add a conditional that avoids these statements if the SD card is unplugged so that the other parts of the program can keep running. Something like:
Is there an easy way to do this?
Essentially, I'm finding if the SD card gets unplugged mid runtime, my program crashes when I get to a file.read() statement. I'd like to add a conditional that avoids these statements if the SD card is unplugged so that the other parts of the program can keep running. Something like:
Code:
if(SD.isPluggedIn()){
char data = File.read()
//do something with the data
}else{
//throw unplugged warning, test for replug
}
Is there an easy way to do this?