I have SD card init failure with the arduino wifi shield R3 and a 4 GB SD card. The symptom is as such: After program upload (sample code ReadWrite from SD library Arduino 1.0), Arduino would repeatedly fail to init, tried other cards, same thing. I tried power down and resets and no luck. Then if I remove card, run program, it shows fail to init (as expected). Then I reinsert the SD card and reset, the card is detected. What could be causing this?
I tried a second Arduino wifi shield and the same exact problem.
If I use external power supply and unplug the USB, using the LED9 on the wifi shield as indicator, then if I initially power up the system, it fails to init SD card. If I push reset it then succeeds. I then tried to add delay but that didn't work. I sometimes get the card fail with just external power and reset won't help. I have to pull the card out, reset, wait for it to fail init, insert SD card, reset, then it works.
Code:
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created Nov 2010
by David A. Mellis
updated 2 Dec 2010
by Tom Igoe
This example code is in the public domain.
*/
#include <SD.h>
File myFile;
void setup()
{
Serial.begin(9600);
Serial.println("Press a key to continue...");
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
delay(2000);
// while (!Serial.available())
// {
// ; // wait for serial port user input
// }
// Serial.read();
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
if (!SD.begin(4)) {
Serial.println("initialization failed!");
digitalWrite(9,HIGH);
return;
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
digitalWrite(9,HIGH);
delay(500);
digitalWrite(9,LOW);
delay(500);
digitalWrite(9,HIGH);
delay(500);
digitalWrite(9,LOW);
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop()
{
// nothing happens after setup
}
Using Arduino UNO and IDE 1.0
I switched to Adafruit sd logger and didn't get this problem anymore. I am using a different card though.
Tried MEGA, same result. Tried a Kingston micro sd card, new. Same result. Used microSD card adapter and on the Adafruit SD logger. Works no problem. I am lost.
Out of frustration I took out my MEGA 2560 clone and tried it. Worked with the arduino wifi shield and micro sd card, both USB and external power.
Bump Having the same problem... really lost. Happens very inconsistently. sometimes a reset will fix it, sometimes not?! It seems to be the begin() method thats failing.
Hey,
I think I should post back. I have not had any problem since I started using MEGA2560 R3, which is the only board I use with SD card now. I don't know why earlier boards such as UNO R2 and MEGA1280 had this problem. I'm in the planning stage to include SD card in a board design with an ATMEGA328P-AU. Hope it works or I don't know what to do.
What is the board and revision of your arduino?
What is the Arduino IDE version you use?
I am going to try newer Arduino IDE versions with these older boards, when I have time.
(I hate this problem!)
I have the same problem with Seeed SD shield on Arduino Uno R3. I read on a different forum that using a different SD library can solve the problem. Will post the details here if that works out.
UnoTotoro:
I have the same problem with Seeed SD shield on Arduino Uno R3. I read on a different forum that using a different SD library can solve the problem. Will post the details here if that works out.
Which library are you using? SD or SdFat?
I am using SdFat library now with MEGA2560 R3. I have not seen any problems since. I guess it may be due to the weak 3.3V supply on older boards (MEGA1280, UNO R2, Duemillanove) not able to supply enough power to the card for initialization. MEGA2560 R3 has a separate 3.3V supply. I designed a board also with a separate 3.3V supply. I have not seen any problem so far.
Thanks for the tip, I am using SD library. Will switch to SdFat and check it.
Seeed SD shield is powered from the 5V supply and converts it to 3.3V. The problem persists even if I power the boards with the USB port, without running the serial monitor.
Provide a link to the SD shield. I'll take a look at its design.
Which Arduino board and which version are you using?
Thanks a lot, that will be a great help!
This is the SD Shield:
http://www.seeedstudio.com/depot/sd-card-shield-v40-p-1381.html?cPath=132_134
For coding, I am using Arduino IDE 1.0
THe SD shield design looks decent. There is a 3.3V supply on board and a voltage level shifter as well. Have you tried different SD cards, say some 4GB cards? I am mainly using 4GB and 8GB cards.
Spot on! It works with a 4GB micro SD card (in a SD card housing).
I was using a 2GB Eye-Fi card. The Eye-Fi circuitry might also have caused a problem.
Thanks again for the help!
UnoTotoro,
I took another look at the seeed sd shield. It uses XC6206 regulator for 3.3V. It is rated at 200mA. That is not very high. Some more recent SD cards can draw 800mA when operating. Look here under power consumption:
I use AMS1117-3.3 that is rated at 1A. Never had a problem. When I was using the Eye-Fi cards, they got so hot that I was concerned about them. I was using Adafruit data logging shield. It has a regulator rated at 250mA. Maybe that's why it worked.
Are you trying to upload images with Eye-Fi and Arduino? I know a few tricks there.
Are you trying to upload images with Eye-Fi and Arduino? I know a few tricks there.
Yup, thought it could be a cheaper option than using a WiFi shield. But if they overheat, I guess that is going to be trouble.
Any other caveats, tips etc?
I spent some time last year using the Eye-Fi SD card to transfer images. The power consumption was not an issue with adafruit data logging shield. There might be new firmware so my experience is not up to date. The card requires CRC, which is not turned on by SD library. Use the SdFat library and turn on CRC. Also files less than a certain size (around 10KB?) are not transferred. That is to make sure smaller files like thumb tags or from particular camera makers are not unnecessarily transferred. So you will have to make the file large enough to be transferred. Only image files are transferred. You will have to rename your files to jpg. I also learned some trick to add date and time to the files I got from a serial port vga camera. Have to dig it out if you really need that feature.