Pages: [1]   Go Down
Author Topic: Using SD card only for the initial configuration: how eject it?  (Read 1401 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I have the Arduino Ethernet Shield with an SD card reader.
I would like read the SD card only while the setup() process. As soon as the program runs the main loop I wish remove my SD card (for using it with another Arduino project or with my camera). Well, after reading my configuration my SD card is useless.
Which code I have to write for a clean eject? Just closing my ini file, some pins to power off?

During the setup my 13-led is HIGH. So while this led switch off, I know I can remove the card… if it is the right way.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46227
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Well, after reading my configuration my SD card is useless.
What does this mean? You need to throw it away and buy a new one?

Quote
Which code I have to write for a clean eject?
All that really needs to be done is close all open files, and make sure you never try to access the device in loop(). Setting the slave select pin HIGH again wouldn't hurt.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't panic, all is right smiley-wink

Just that I'm rewriting my configuration in a text file instead as #define in an header file. And my code about the SD is only in my setup.

Thanks!
Logged

Monterey, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another alternative:
Set a DoOnce variable at the start of the loop, have it open/read/close the file on the SD card, then set DoOnce again so it doesn't repeat it until next bootup.
Like:
Code:
int DoOnce;

void setup()
{
//Your code here
digitalWrite(13,HIGH);  //Optional status led
}

void loop()
{
if (DoOnce==0)
  {
    //Your code to open, read, and close here
  digitalWrite(13,LOW);  //Goes along with the Setup status led
  DoOnce=1;
  }
//Rest of your code
}

Logged

Food for thought.
Nom.

Pages: [1]   Go Up
Jump to: