Arduino Forum

Using Arduino => Storage => Topic started by: Sirius93 on Dec 31, 2015, 01:35 am

Title: SD Card wont work, no matter what i try
Post by: Sirius93 on Dec 31, 2015, 01:35 am
Hello,

I am trying to use a SD Card with my Arduino and by now im having huge trouble getting it to work. I actually have 2 different modules and 4 SD cards and nothing worked by now. I checked my wiring thousands of times, but i still cant get it to work. I've check the internet for any solution, but for me nothing works.

The first problem i had was, that the first module was on 3,3V logic leven which did not work. The one i use now, should work on 5V, but with the testsketch it does not work. I have tried both pin4 and pin10 for the CS, still no luck, im always getting the message, that the SD Card could not be initialized. I as well tried the SDFat library, still no luck.

Is there anything that could be wrong besides that? Im really clueless, since this is such a joke of a problem and any solution the web gives me just does not help.

Title: Re: SD Card wont work, no matter what i try
Post by: OldSteve on Dec 31, 2015, 02:33 pm
Hello,

I am trying to use a SD Card with my Arduino and by now im having huge trouble getting it to work. I actually have 2 different modules and 4 SD cards and nothing worked by now. I checked my wiring thousands of times, but i still cant get it to work. I've check the internet for any solution, but for me nothing works.

The first problem i had was, that the first module was on 3,3V logic leven which did not work. The one i use now, should work on 5V, but with the testsketch it does not work. I have tried both pin4 and pin10 for the CS, still no luck, im always getting the message, that the SD Card could not be initialized. I as well tried the SDFat library, still no luck.

Is there anything that could be wrong besides that? Im really clueless, since this is such a joke of a problem and any solution the web gives me just does not help.
We can't really help unless you show us your code and schematic diagram. It would also be a good idea to post a link to the SD card module that you're using. It might need external level-shifting, even if it does have a 5V supply pin. (Mine does.)
Title: Re: SD Card wont work, no matter what i try
Post by: Sirius93 on Dec 31, 2015, 04:21 pm
I'm using a CATALEX MicroSD Card Adapter with Arduino Uno.
Im using this code, which is an example of the SD Library.
My Pins are connected as told in the example, CS is connected to Pin10



Code: [Select]
/*
  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
const int chipSelect = 4;

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?");
    return;
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.print("\nCard 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");
    return;
  }


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

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);


  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) {

}
Title: Re: SD Card wont work, no matter what i try
Post by: cattledog on Dec 31, 2015, 07:28 pm
Quote
My Pins are connected as told in the example, CS is connected to Pin10
Code: [Select]
const int chipSelect = 4;

 Either change the wiring to match the sketch or change the sketch to match the wiring.
Title: Re: SD Card wont work, no matter what i try
Post by: Sirius93 on Jan 01, 2016, 04:51 pm
Oh sorry, i just pasted the example code, of course i changed this to Pin10. I also tried Pin4, which did not work either.
Title: Re: SD Card wont work, no matter what i try
Post by: cattledog on Jan 02, 2016, 04:18 am
I have the same catalex module, and the example code you posted works fine, so that sketch is not the problem.

If you are indeed wired correctly, then you must have either defective wires, a defective breadboard, a defective Arduino Uno or a defective module, or wrongly formatted or defective card.

What error do you get? How are you providing power to the card? How did you format the card? Can you provide a photo of your wiring and module?

Sometimes the jumper wires or breadboard can be defective, so move the card around to different pin holes, and change your wires.
Title: Re: SD Card wont work, no matter what i try
Post by: Sirius93 on Jan 02, 2016, 05:54 pm
You are right, it should work fine, since i never heard, that it did not work for anyone.
I checked the wiring about 10 times, i rewired it several times, it never worked, so im about 100% sure, there is nothing wrong with the wiring. As exchanged the wires as well, still no work. The Breadboard also works fine since i tried with and without breadboard at different spots, as well as i checked if the VCC and GND of the module works with a LED.

I also thought, that the UNO is the problem, but if i use the pins to send and recieve data for other applications it works fine as well.

I get this error:

Code: [Select]
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?");
    return;


I also tried a other Code, with SD.begin which also did not work for me.

Power is provided from the Arduino 5V directly to the module. Formatted with SDFormatter in FAT.


I apparently am not able to upload a picture, but as said i just connected the module. VCC and GND directly to Arduino 5V and GND, rest as in the code i posted, with CS to pin10. I decided to get another module, since they are not that expensive, just to make sure that it isnt the module, that is not working. Or is there any other way to find out whether the module itself works or not?
Title: Re: SD Card wont work, no matter what i try
Post by: jack_tinsley on Apr 09, 2019, 09:46 pm
I have the same problem. I have tried two different MicroSD Catalex modules. Some time it works and sometimes it doesn't. After fiddling around with it a bit and running several sketches it comes back to life. I also use XOD. Some times it works and sometimes it doesn't.  When it works all txt files are there and readable. Then for no reason it stopes. There must be a procedure to shut down the Arduino and remove card and re-install card and power on. That seems to be the weak point.

Thanks
JT