Micro SD Module wont work on Arduino Uno Rev2 Wifi

Hey guys, I am having trouble with my micro sd card module for the arduino uno rev2 wifi. In the CardInfo example, while my arduino is on. I have to either take out my sd card and plug it back it for it work, or i have to either take out the 5v connector and plug it back in or do the same with the GND connector. It seems like a power issue for sure but I cant put my finger on it. I have narrowed it down to the power pins though.

Schematics please. Pen and paper often works fine. Include the powering stuff.

Taking out GND, is NO, NO, NO! Taking out Vcc is also bad. The logic connections will then power the circuit.

Autoformatted code, presented in code tags is requested.

Some basic advice here: How to get the best out of this forum - Using Arduino / Installation & Troubleshooting - Arduino Forum

While you are posting that annotated schematic include links to technical information on all the hardware devices.

I am using this micro sd card module.

Since the Uno rev2 wifi uses the ICSP pins for the SPI pinout, my connection points for MISO, MOSI, and SCK are on the ICSP pins. The VCC connection is a direct connection into the 5v port, and the GND to GND. I am not using the 5v or GND pins on the ICSP. My CS pin is plugged into digital port 10.

Here is the code im using to test the micro sd card.

/*
  SD card test

  This example shows how use the utility libraries on which the'
  SD library is based in order to get info about your SD card.
  Very useful for testing a card when you're not sure whether its working or not.

  The circuit:
    SD card attached to SPI bus as follows:
 ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
 ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
 ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
 ** CS - depends on your SD card shield or module.
 		Pin 4 used here for consistency with other Arduino examples


  created  28 Mar 2011
  by Limor Fried
  modified 9 Apr 2012
  by Tom Igoe
*/
// include the SD library:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// MKRZero SD: SDCARD_SS_PIN
const int chipSelect = 10;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("\nInitializing SD card...");

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    while (1);
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.println();
  Serial.print("Card type:         ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    while (1);
  }

  Serial.print("Clusters:          ");
  Serial.println(volume.clusterCount());
  Serial.print("Blocks x Cluster:  ");
  Serial.println(volume.blocksPerCluster());

  Serial.print("Total Blocks:      ");
  Serial.println(volume.blocksPerCluster() * volume.clusterCount());
  Serial.println();

  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("Volume type is:    FAT");
  Serial.println(volume.fatType(), DEC);

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize /= 2;                           // SD card blocks are always 512 bytes (2 blocks are 1KB)
  Serial.print("Volume size (Kb):  ");
  Serial.println(volumesize);
  Serial.print("Volume size (Mb):  ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Gb):  ");
  Serial.println((float)volumesize / 1024.0);

  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}

void loop(void) {
}

This is the board im using.

Link to SD card module.

You'll notice that there is no RESET pin on the sd card. Thus, when the cpu resets, the sd card is unaware and gets confused by the unexpected sd.begin()
This is why you need to power cycle for the sd to come back online. Removing and replacing the card is iffy depending on what the sd thought it was doing when the cpu was reset.
Soooo. You can try something like an sd.close() [is that even a command?] or you could put a relay in the sd card's Vcc line so the cpu can power cycle it to ensure sync.

ps: maybe try an io operation BEFORE sd.begin() and if there's no error, skip the sd.begin()?

I know that f ex opening the serial monitor restarts the UNO rev 3 units, so there's something to attack.
Strange that other sd card users don't have the problem You tell about.

That's the same bad as told in reply #software:arduino-ide-2-0-
I suggest braking the power to the entire build for a safe reset if no other helper suggest a better way.

You might be on to something but looking at the picture of the sd card reader doesn't give any help.

I see this issue a lot and have trouble shot it in my own hardware. Its subtle since you may not notice the issue outside dev where you're sw resetting vs fielded systems that get turned on and off -- where it works perfectly.

The relay is a last ditch hack.

Since the power DIDN'T blip, the sd card should be in a steady state. If your app idles with all files closed, there is a good chance it will be fine.
Reset/power cycle with files open will truncate to zero length.

Remember, too, the 32gb size limit and the DOS 8.3 file name limits (which appear to be non-issues since it does write)

ps: Not to brag, by my last job before retiring was an L3 analyst for Dell Server -- perhaps this explains why I notice io channel errors more than others.

Still strange that this question is not common as there are quite a lot of member applications using sd cards.

I've not been playing with them yet and have no hands on experience.
Would a deeper study of the card reader manual/datasheet as well as a dive into the library documentation searching for possibilities be an option? Is the library modern or an "old friend"...? Using another library.......
A file being written usually must get closed to preserve it. One way could be to close and reopen a write-file in case of a system hang up.
Files being read ought to remain on the card.

So I tried what you suggested and having an io operation before my sd.begin didnt work either. Here is what i found though.. I replaced the sd card that I was using with a brand new one and it worked on the first try. I tried all my test scenarios and the reader was picking it up really well. With the old card, i did often times take the card out before cutting power to the board. Im guessing that did something to it. Anyways, seems to be good now so thank you guys for the help and quick responses!

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