[RISOLTO] Rimozione SD e ripristino automatico al reinserimento

Sul connettore della SD hai due segnali aggiuntivi, uno ti dice se è protetta da scrittura, l'altro ti avvisa se è inserita oppure no, questo lo devi usare per verificare se viene estratta e poi reinserita in modo da poter reinizializzare la sua lettura.

il mio problema non è sapere se è presente o meno, è farla vedere di nuovo
Questo sketch funziona perfettamente fino a quando non la estraggo

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

const int SD_CS = 4;          // pin 4 is the SPI select pin for the SDcard
const int ETHER_CS = 10;   // pin 10 is the SPI select pin for the Ethernet


byte ip[] = { 192, 168, 2, 177 };                     
byte subnet[] = { 255, 255, 255, 0 };                
byte gateway[] = { 192, 168, 2, 1 };                 
byte mac[] = { 0x00, 0x11, 0x22, 0x33, 0xFB, 0x11 }; 

const int Pin2 = 2; //uscita led errore generico
boolean has_filesystem = true;

void setup() 
{
  Serial.begin(9600);
  
   pinMode(Pin2, OUTPUT);  //led errore
  pinMode(SS_PIN, OUTPUT);	// set the SS pin as an output(necessary to keep the board as master and not SPI slave)
  digitalWrite(SS_PIN, HIGH);	// and ensure SS is high
  // Ensure we are in a consistent state after power-up or a reset
  // button These pins are standard for the Arduino w5100 Rev 3
  // ethernet board They may need to be re-jigged for different boards
  pinMode(ETHER_CS, OUTPUT); 	// Set the CS pin as an output
  digitalWrite(ETHER_CS, HIGH); // Turn off the W5100 chip! (wait for configuration)
  pinMode(SD_CS, OUTPUT);       // Set the SDcard CS pin as an output
  digitalWrite(SD_CS, HIGH); 	// Turn off the SD card! (wait for configuration)

  sd_init() ;

  Ethernet.begin(mac, ip);
}

void sd_init() 
{   
  if (!card.init(SPI_FULL_SPEED, SD_CS)) { has_filesystem = false; }
  if (!volume.init(&card)) { has_filesystem = false; }
  if (!root.openRoot(&volume)) { has_filesystem = false;}
}  

void loop() 
{

  if (!volume.init(&card)) { has_filesystem = false; }  //Se estraggo la scheda SD ottengo un errore immediato
  
  if (!has_filesystem) 
  { 
    digitalWrite(Pin2, HIGH); // led ERRORE .... che si accende se estraggo la scheda
    sd_init(); // tento un ripristino 
  } 

..............
..............
..............

}