SDcard detection

I am using one of these SDcard holders and an Arduino Mega 2560:

https://www.ebay.com/itm/174563463881

I needed a way to detect if the card was inserted. Turns out there is a switch in the card holder that provides that feedback but it is not broken out on any of the pins. So I had to tack a wire on it and using a 4.7k pull up resistor, I am now able to detect the card using that switch.

My problem is it seems like this pull up is causing a .200ma constant extra drain all of the sudden. Putting the card into the slot causes the drain and if it's out I am only using about .08ma total for everything else. Disconnecting the pull up from the AtMega means while I can't detect the card there is no extra drain.

So, it shouldn't be doing that. Has anyone had this problem? I have other pull ups that do not cause this, so maybe I am wrong about this switch in the card reader and how it works?

Drew

Have you tried the internal pull-up (30-50K) instead of the external 4.7K? Enable the internal pull-up with:
pinMode(pin, INPUT_PULLUP);

Blockquote
Have you tried the internal pull-up (30-50K) instead of the external 4.7K?
Blockquote

I thought I tried an external 47k resistor but I'll give the on chip ones a try tomorrow. I have a 24 hour run test going right now, otherwise I'd try it now. Stay tuned! =)

Drew

Why not just try a small write & read, if successful the card is inserted.

I was originally writing it that way but my concern was that someone (not myself of course :wink:) could pull out the card right as the test is taking place and possibly corrupt the file system. I mean the odds of that are slim but why risk the data that has been logged. I figured the less time files are open for writes/reads the better.

I may go back to that idea if I can't resolve it, because this current draw is just too high.

Drew

Not related to your original question, but are you using this module with a 3.3V Arduino? Despite what the listing says, this module isn't appropriate for a 5V MCU. It has no level shifter for the MOSI, SCLK and CS lines.

Edit: Forgot to say - the lowest current solution will be to replace your 4.7K pullup with something like a 1Meg pullup. It will use very little current, but will still work.

Bah, this is completely ridiculous now. I added the internal pull up, removed my resistor and now the code don't want to work and by the way I was missing any kind of pinMode() setting for the pin I am using. I hadn't realized I was missing that. So that may explain some of the current problems but now I don't understand why adding pinMode() would kill the source because literately NOTHING of value changed the outcome of any variable. I just assigned the pin which I hadn't done before. Ridiculous.

Sigh....

Drew

The pin you are using probably defaulted to INPUT on powerup, and that worked because you had the external resistor. But to use the internal resistor you have to use pinMode(yourpin,INPUT_PULLUP);

But having done that, then it should work. When you insert an SD card, that pin should go to ground. Does it?

Simple sketch testing shows that yes it goes to ground, I get a 1 when the card is out a 0 when the card is in. No but now in my full sketch it's hanging it up. All I added was pinmode() to setup.

Drew

It does resolve the power drain though... so I guess there is that. I guess I will just rewrite this section, I dunno what else to do. makes no sense.

Drew

Ok, so my original post said atmega I meant to say Arduino Mega 2560. I was using pin 53 on the Arduino Mega 2560, don't work. So I moved it to pin 7 because why not, now it works. The code is just fine with using pin 7... Now, the question is, what is it that I have forgotten here? I can't recall why that would be different. They are both digital pins, why would pin 7 make a difference?

Not sure what I am missing here.

Drew

DOH! 53 is part of the SPI pins. I knew that, because I had stuff on SPI there and it just escaped me. It's funny now :clown_face: right? No. LOL :rofl:

Ok, so... pin 43 it is. Now I am down to about .09ma standard and .12ma max which I suspect that jump is when the high power rf24 module is send and receiving. That is much better!

Thanks for the help and space to work thru it!

Drew

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.