I had the problem with the card fresh from the dealer. Later I re-formatted it within Ubuntu (18.04). Later I created a 4GB partition on it and formatted it via a console:
$ sudo mkdosfs -F 16 /dev/sdc1
This is my sketch:
/*
Listfiles
This example shows how print out the files in a
directory on a SD card
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 2 Feb 2014
by Scott Fitzgerald
This example code is in the public domain.
*/ #include <SPI.h> #include <SD.h>
#define serialConnection Serial
File root;
void setup() {
// Open serial communications and wait for port to open:
serialConnection.begin(57600);
while (!serialConnection.available()) {
; // wait for serial port to connect. Needed for native USB port only
}
serialConnection.print("Initializing SD card...");
pinMode(4, OUTPUT); // SD Card CS
if (!SD.begin(4)) {
serialConnection.println("initialization failed!");
while (1);
}
serialConnection.println("initialization done.");
root = SD.open("/");
printDirectory(root, 0);
serialConnection.println("done!");
}
void loop() {
// nothing happens after setup finishes.
}
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
serialConnection.print('\t');
}
serialConnection.print(entry.name());
if (entry.isDirectory()) {
serialConnection.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
serialConnection.print("\t\t");
serialConnection.println(entry.size(), DEC);
}
entry.close();
}
}
And cardinfo shows this:
Initializing SD card...initialization failed. Things to check:
is a card inserted?
is your wiring correct?
did you change the chipSelect pin to match your shield or module?
The main problem is that it only works with 5V, not with 3.3V (as described).
The second problem was that the SD-card used in my first tests had some problems (I will look into this later).
So here is what I did step by step:
I changed the SD-card
I changed the card-reader
I switched to 5V.
Then it works (as described yesterday).
Today I checked it again: still works. Then I formatted the SD-card again using the full 16GB of the card: still works. Then I switched to 3.3V: init failed. Switching back to 5V: everything works.
I tested it with 3 sketches from the example and they all work.
Today I checked it again: still works. Then I formatted the SD-card again using the full 16GB of the card: still works. Then I switched to 3.3V: init failed. Switching back to 5V: everything works.
The best to would be to provide a link to the card readers (yes, plural) that you used. One or both of them must have a built in level shifter and is expecting 5V. Yes the cards are 3.3V only, but if it requires 5V to work, then there must be a level shifter or the SD card IS going to smoke.
Makes sense. The module only has one "Vcc" (power input) pin, and it's wired to a 3.3v regulator.
Powering a 3.3v regulator with that voltage, results in a even lower output; so low that renders the SD card inoperable (but not destroyed fortunately).
And yes, it has a logic level shifter for that previous reason.