Micro SD Card Wire/Read without Restart

So I’m using a SD Card module this one:

This is the basic code I took from lib and re-wrote to make a simple one:

//Domino60
#include <SD.h>

const int chipSelect = 10;
File dataFile;
void setup(){
  //If sdcard available then go else stop.
 if (!SD.begin(chipSelect)) {
    return;
      }
    pinMode(10, OUTPUT);
  Serial.begin(9600);

}

void loop(){
   
  dataFile = SD.open("test.txt", FILE_WRITE);
  if(dataFile){
    dataFile.println("GO");
   dataFile.close(); 
  }
  
}
//Domino60

Now my main goal was to just simple use it as a data logger but with the device I’m using I’d like to plug and un-plug the Micro sd card to view the data …etc without disconnecting the device/arduino from POWER.

Now if I do that unplug the Micro SD Card without plug off the arduino and plug the Micro SD Card again back to the module the code will not keep going to write I need to press the restart button and it will write again.

So I was thinking to use this :

 //If sdcard available then go else stop.
    if (!SD.begin(chipSelect)) {
    return;
      }

In the loop but I wasn’t sure how it will react, it will make restarting the SD module will it
read if the module is ok to go (with the micro SD card inside or not) what it gonna do?

The main question here is:

  • How to unplug and plug back the micro sd card and my arduino to keep writing without problems or restarting.

D.60