Micro SD card in a datalogger with nacro sleep.
Moderators: adafruit_support_bill, adafruit

Micro SD card in a datalogger with nacro sleep.

by tomthepot on Mon Oct 15, 2012 3:51 pm

I have bought several Adafruit MicroSD Breakout Boards to log data on some environmental loggers controlled with an ATmega328 mpu. The loggers need to run for several months on simple batteries so the mpu is in 'sleep' mode most of the time.

To isolate the SD card the ground from the microSD breakout board is switched on and off using a digital line from the 328 and a switching transistor. With-out the breakout board I can get current drain down to 0.4 mA but when this is in and the ground (GND)line is switched off the break out board still draws about 18 mA.

On the advice of UK distributors Oomlout I have reset the SD pins (10,11,12,13) to input just before sleeping. This isolates the SD card and gets the battery drain down to 0.4 mA but I cannot re-awaken the SD card board sucessfully.

Re-awaken with SD.open seems to work [in that if (myFile) returns TRUE but nothing is written to the file after re-awakening. Using SD.begin() fails.
tomthepot
 
Posts: 4
Joined: Mon Oct 15, 2012 3:32 pm

Re: Micro SD card in a datalogger with nacro sleep.

by adafruit_support_rick on Tue Oct 16, 2012 1:10 pm

Are you closing any files before you go to sleep? I would think that you would just continue where you left off when you wake up - I don't think I see a need to call open or begin.

Did you try actually powering the MicroSD with a digital pin? I don't know what your overall GPIO drain is, but that might be a possibility.

adafruit_support_rick
 
Posts: 12904
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Micro SD card in a datalogger with nacro sleep.

by tomthepot on Tue Oct 16, 2012 3:18 pm

Many thanks for your help.

The steps (in the test program) are:

Write data to file (at present just three integers)
Close file
Switch ground line from SD card off
Set pins 10,11,13 to INPUT to stop power drain

call narcoleptic.delay

// re-awaken
Set pins 10,11 13 to output and pin 12 to input
delay(1000) to get everything awake and settled
SD.open to re-open file
loop back to beginning

I was avoiding powering the SDcard from a Pin as I had read that they could be power hungry and draw up to 150 mA when writing data which would be well over what the pin could safely supply.
tomthepot
 
Posts: 4
Joined: Mon Oct 15, 2012 3:32 pm

Re: Micro SD card in a datalogger with nacro sleep.

by adafruit_support_rick on Tue Oct 16, 2012 4:34 pm

They can pull 150mA? Didn't know that. Okay, that would be wayyy too much. Just curious - why did you choose to switch ground rather than Vcc?

So the the file system state on the 328 should still be correct, and the open should work. Seems like all that's left is that the power-up sequence is putting the microSD into some sort of wacky state. When do you re-enable the ground to power the card - before or after you re-configure the SPI pins?

One thing to try is to enable the internal pull-ups on 10,11,13 when you switch them to input, to keep them from floating as the SD powers up. You don't have a common ground until you flip the transistor, so who knows what could be happening. I guess I would have opted to switch Vcc instead of GND for that reason.

adafruit_support_rick
 
Posts: 12904
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Micro SD card in a datalogger with nacro sleep.

by tomthepot on Tue Oct 16, 2012 5:12 pm

This is on the adafruit website:

There are a few things to watch for when interacting with SD cards:

One is that they are strictly 3.3V devices and the power draw when writing to the card can be fairly high, up to 100mA (or more!)


Guess you need to adjust for the different voltages but the answer will still be over 40 mA. I just took the short-hand = 'bad idea'

Switched the ground rather than Vcc because that is what others seemed to do! [I am really a cattle veterinarian wanting to monitor the environment in cow sheds]; also the way my boards have evolved that was a bit easier than Vcc.

I am on the road for the next day or so but you have given me some more ideas for tinkering to try when I get back.

Many thanks for your help - I will let you know how it goes.
tomthepot
 
Posts: 4
Joined: Mon Oct 15, 2012 3:32 pm

Re: Micro SD card in a datalogger with narco sleep.

by tomthepot on Sun Oct 21, 2012 2:15 pm

Have now moved away from SD cards to USB sticks. I am using the Hobbytronics USB host - their 1st version. This has a full PIC mpu on the break out board so only supply power, Rx and Tx so frees up pins. With all the software on the break out board there is less library code in the compiled program. Also because it does all its own boot up it is easier to turn on and off - but is v slow (several seconds - not an issue for me but might be for others) and does require that you re-initialise the serial connection (works with softwareserial) and .begin the serial comms each time. Still not quite working but getting there.

Also note that you cannot turn the breakout on and off with a simple transistor. I used a P2N222A and had problems. On checking with a meter there is quite a resistance on the closed-switch and with a 65 mA current drain to the USB board there was a 2V drop across the transistor. Have cobbled something togeather with a relay for now but am told a cheap MOSFET transistor should do the job as they have almost zero resistance when closed.
tomthepot
 
Posts: 4
Joined: Mon Oct 15, 2012 3:32 pm