Go Down

Topic: [sdfat] Any way to check if SD has been remove during loop() (Read 260 times) previous topic - next topic

pierrot10

Hello all and happy new year.


My program write log into a sd card.
Mst it important, it need to write GPS position when GSM is not available.

Is there a way to check if the carshas been remove (accidenty or not)?

If it return tue (= card removed), it will loop until the card is re inserted.

Code: [Select]
do
{
   Serial.println(F("Crad removed"));
}while(isInserted() == false);



Should I do with:

sd.begin(CHIPSET)

in the do loop, instead of isInserted?

Cheers
Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!
You can not know everything, perseverance, it is almost everything!

cattledog

Most card readers have a card detect switch. You can read this switch to determine that a card has been removed.

SD cards must be reinitialized when they have lost power, so when the card is reinserted, you will need to call sd.begin(). The calling of sd.begin() after the first initialization is straightforward with SdFat but SD.h requires some additional code.  See http://forum.arduino.cc/index.php?topic=239157.msg1718831#msg1718831

You can use a button to trigger the call to sd.begin() when the card has been reinserted. If you try to use the card detect switch it will require good debounce and an understanding of the timing of when the card trips the switch and when the contacts are actually made.


PaulS

Quote
Most card readers have a card detect switch.
That switch is probably NOT connected to the Arduino, so you'll need to add a jumper wire to get access to the switch.
The art of getting good answers lies in asking good questions.

mudassir9999

I have tried using this code and it's working
Code: [Select]
if (!SD.begin(CS_pin)
    {
      Serial.println("SD Card Failed!");
while(1)
}


I don't know if it's reliable, because everytime when it comes into loop the CS pin gets high for a second.

See what experts says.

fat16lib

Using SD.begin() is not a good way.  It is not reliable.

You can't use it if a file is open since a begin() call will clear all cached data.

Use a socket wit a card detect switch!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy