#include <SD.h>
#include<SPI.h>
const int chipSelect = 8;
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
}
Serial.print("Initializing SD card...");
pinMode(chipSelect, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}
void loop()
{
}
This is my code to check the sd card in the sd card shield
I am using the following shield but I always get the same result that card initialization failed.Please help me this is the shield
The seller of that shield says "Also for the libraries to work pin D10 will have to be set as an output in the 'setup()' section of your sketch. " I would try that.
hi sir...
I got error which means hardware problems or card..
I used new microSd card..How I could solve this problem..
I used Sparkfun MicroSD shield and Arduino UNO board. For the Software, I use Arduino 1.6.5..
jamaliah:
hi sir...
I got error which means hardware problems or card..
I used new microSd card..How I could solve this problem..
I used Sparkfun MicroSD shield and Arduino UNO board. For the Software, I use Arduino 1.6.5..
I really hope that you may help me...
You need to provide more information:
create a simple Arduino sketch that reproduces your problem.
post that sketch, with a copy of the error messages.
so we can review you sketch for errors
post a drawing of your circuit.
so we can understand how the sketch is expecting the hardware be configured.
I am having the same problem. I tried the "DataLogger" example and modified it in a way that it outputs the errors' code and date. The interesting thing is, that it works once after every second reset!
<<< RESET button pressed >>>
Initializing SD card...Initialization failed.
Error code: 2
Error data: FF
<<< RESET button pressed >>>
Initializing SD card...Wiring is correct and a card is present.
<<< RESET button pressed >>>
Initializing SD card...Initialization failed.
Error code: 2
Error data: FF
<<< RESET button pressed >>>
Initializing SD card...Wiring is correct and a card is present.
And if the initialization has been successful I can write exactly one time to a file. After the first file.open() / file.close() it cannot be opened again.
// Chip select pin for SD card.
const int sdCsPin = 8;
// Replace the -1 with the CS pin number of any shared SPI device.
const int sharedCsPin = -1;
void setup() {
Serial.begin(9600);
// Disable any other SPI devices
if (sharedCsPin >= 0) {
pinMode(sharedCsPin, OUTPUT);
digitalWrite(sharedCsPin, HIGH);
}
// Try to initialize the SD card
if (card.init(SPI_HALF_SPEED, sdCsPin)) {
Serial.println("card init OK");
} else {
Serial.print("errorCode: ");
Serial.println(card.errorCode(), HEX);
Serial.print("errorData: ");
Serial.println(card.errorData(), HEX);
return;
}
// Try to initialize the FAT volume.
if (vol.init(&card)) {
Serial.println("vol init OK");
} else {
Serial.println("vol init failed");
return;
}
// Try to open root
if (root.openRoot(&vol)) {
Serial.println("open root OK");
} else {
Serial.println("open root failed");
}
}
void loop() {}
If all is well you should see this:
If there is a hardware problem with the shield or card you will see something like this:
If the card format is bad you will see something like this:
Or this:
Please post the results.
hi sir.. i tried your code.. got error message as below, what does it mean??? pls help to solve it..