rfresh737:
I purchased an SD Card board on eBay and I'm running the Ardunio CardInfo example sketch.
I'm getting an Initialization Failed message in the serial window.
I'm wired up this way on the SD Card board:
GND going to my Leonardo GND pin.
VCC going to the 3.3 pin on the Leonardo.
MISO going to Leo pin 12.
MOSI going to Leo pin 11.
SCK going to Leo pin 13.
CS going to Leo pin 10.
Does my wiring sound right?
Thanks for any help...
No, I would change your VCC connection. From your JPG's The SOT223 device marked U is a 3.3v regulator, It expects 5V for it's input. If you connect VCC to 3.3v the SDCard will not receive 3.3v.
Also, The U1 part looks to be a voltage buffer, SDCards expect 3.3v logic levels. It looks like this SD Adapter is designed to interface to a 5V CPU.
I don't know if it will work correctly when connected to a 3.3v Leo.
TEST STEPS:
If you have a multimeter, only wire up GND and connect VCC to 3.3v.
Measure between GND and the big tab on "U" (Vout).
See how close to 3.3V it is.
It needs to be above 3.2V. If it is less you may have to modify this board. You can run a jumper from input to output on the regulator, bypassing it. The regulator is the "U" IC, It should have top markings of LM1117-3.3 on it.
Here is a outline drawing of a SOT223 regulator.
If you run this jumper, ONLY connect VCC 3.3V. If you connect VCC to 5V you will let the smoke out!
/*
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) {
}
I understood from you earlier post that you were using a Catalex module.
According to the link I posted, if you want it to run on pins 11,12,13 and 4 on a Leonardo you need to change the constructor and make sure that the library version of SD.h byou are using supports "SD card on any pin".
Well, I think I made the correct changes "SD card on any pin" as I copied the Lib from the Adafruit URL reference and edited the sketch per their instructions.
I'm still getting SD Card initialization failure however.
/*
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 Leonardo only
}
// see if the card is present and can be initialized:
if (!SD.begin(10, 11, 12, 13))
{
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!
while (!card.init(SPI_HALF_SPEED, 10, 11, 12, 13))
{
//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) {
}
There are two things wrong that I see in your sketch.
First your sketch is a mixture of the Card Info sketch which uses card.init and other examples which use sd.begin. The way you have the two different calls nested looks wrong.
Second, the constructor needs to be changed to reflect the use of pin 4 instead of pin 10.
If you are using sketches which use sd.begin() then I think the constructor should be sd.begin(4,11,12,13).
Try this modificaton of the standard card info sketch which uses init.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
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)){ need to change constructor to Leonardo version
if (!card.init(SPI_HALF_SPEED, 4,11,12,13)) {
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) {
}
Initializing SD card...Wiring is correct and a card is present.
Card type: SDHC
Volume type is FAT32
Volume size (bytes): 3956801536
Volume size (Kbytes): 3864064
Volume size (Mbytes): 3773
Files found on the card (name, date and size in bytes):
TEST.TXT 2015-12-11 19:47:00 4
Apparently there are two different ways to access an SD Card...I'm not clear on what those differences are...why did I have to use the inti.Card vs SD.begin method?
SD.begin();
init.card();
Your init.Card() code worked, but I don't know why.
I tried to look up SD Card examples that read and write to the card and I copied several different examples but they all fail to read and to write. I'm wondering if it is because those examples are using SD.begin()?
Seems to me it shouldn't make any difference but apparently it does. Do I need to use different read/write code when I'm using init.Card()?
Thank you...
/*
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;
File myFile;
// 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.println("Initializing SD card.");
Serial.println();
// 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)){ need to change constructor to Leonardo version
if (!card.init(SPI_HALF_SPEED, 4,11,12,13))
{
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("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");
return;
}
// 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);
//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);
Serial.println();
//--------------------------------------------------------
// To create a text file, we can open a new file and immediately close it
myFile = SD.open("example.txt", FILE_WRITE); // doesn't work
myFile.close();
// doesn't work
if (SD.exists("test.txt"))
{
Serial.println("file exists");
}
else
{
Serial.println("file not found");
}
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile)
{
Serial.print("Writing to the text file...");
myFile.println("Congratulations! You have successfully wrote on the test file.");
myFile.close(); // close the file:
Serial.println("done closing.");
}
else
{
// if the file didn't open, report an error:
Serial.println("error opening the text file!");
}
// re-open the text file for reading:
myFile = SD.open("test.txt");
if (myFile)
{
Serial.println("test.txt:");
// read all the text written on the file
while (myFile.available())
{
Serial.write(myFile.read());
}
// close the file:
myFile.close();
}
else
{
// if the file didn't open, report an error:
Serial.println("error opening the text file!");
}
}
void loop(void)
{
}
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
Sd2Card, SdVolume, and SdFile are poorly documented classes and they are contained within the utility folder included in the SD library. The SD library is a beginner friendly wrapper for another library called SdFat and these are classes from that library.
I'm not sure what operations require using those classes, and I think it is unfortunate that CardInfo is one of the SD.h example sketches and it needs to use classes which are not in SD.h