MicroSD card presence detection


According to the Seeeduino Stalker v2 documentation, the TF_STATUS jumper have to be solder before being able to detect the presence of a microSD card into the socket. The necessary code for doing that is presented below. For this application I choose also the possibility to provide the power to the miscroSD socket only when it is necessary (the POWER_TF jumper should be set correctly for being able to do this). For the digital input 3 the pullup resistor should be on for not reading  wrong values.

#define TF_STATUS_DIGITAL_PIN 3
#define POWER_TF_DIGITAL_PIN  4
#define STATUS_LED 8

void setup()
{
pinMode(TF_STATUS_DIGITAL_PIN, INPUT);
digitalWrite(TF_STATUS_DIGITAL_PIN, HIGH); // turn on pullup resistor

pinMode(POWER_TF_DIGITAL_PIN, OUTPUT);
digitalWrite(POWER_TF_DIGITAL_PIN, LOW);

//indicate the presence of the microSD card
pinMode(STATUS_LED, OUTPUT);

flashStatusLed(3, 300);
}

void loop()
{
//determine the status of the card
if(digitalRead(TF_STATUS_DIGITAL_PIN) == LOW)
{
// the card is present
digitalWrite(STATUS_LED, HIGH);
digitalWrite(POWER_TF_DIGITAL_PIN, HIGH);
}
else
{
// the card is NOT present
digitalWrite(STATUS_LED, LOW);
digitalWrite(POWER_TF_DIGITAL_PIN, LOW);
}

delay(100);
}

void flashStatusLed(byte noTimes, int delayTime)
{
byte i;

for(i = 0; i < noTimes; i++)
{
digitalWrite(STATUS_LED, HIGH);
delay(delayTime);
digitalWrite(STATUS_LED, LOW);

if(i < (noTimes – 1))
delay(delayTime);
}
}

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: