MicroSD shield with leonardo

Hi all.

I’m new to Arduino, so please forgive the stupid questions. I just purchased a Sparkfun MicroSD shield and an Arduino Leonardo. The Leonardo seems to be working fine, I’ve completed most of the basic tutorials without issue.

When I moved to the microSD shield, there are various issues. At first, following the quickstart guide, I included the Sparkfun SDFat library (SdFat.zip) in the library folder but I couldn’t get the example sketch (http://www.sparkfun.com/tutorial/microS … xample.pde) to compile. Further down the quickstart guide, they recommend using a different SDFat library (sdfatlib20120719.zip). Replacing the sparkfun SDFat library with the sdfatlib20120719 library allowed me to compile the example sketch. However, after uploading the sketch, I found no test.txt on the microSD card when I plugged it into my reader.

Trying the quickstart.pde example from the sdfatlib20120719, I was able to upload the sketch and communicate with the Leonardo board. But again, when I open the serial monitor and send “8” or “10” as the chip select pin number, I get:

SD initialization failed.

Do not reformat the card!

Is the card correctly inserted?

Is chipSelect set to the correct value?

Is there a wiring/soldering problem?

errorCode: 0x1, errorData: 0xff

Restarting

Enter the chip select pin number:

Any ideas on my coding errors? Is this a Leonardo-specific thing with the serial1 requirement? Do I have the right SDFat library? Any help or guidance is appreciated. :slight_smile:

Hi there. I’ve been on the Leonardo for a few months now and have gone through the same stuff too! This is a Leonardo specific problem (there are many btw, although it’s improving). I haven’t delt with the micro SD but it’s probably the same issue. My Leo is an R3 and I’m guessing yours is too (check the back to see). On this board, the SPI signals are only available on the 6-pin ISP programming header NOT on the usual pins (as per the UNO). To get it to work you must remove the MISO,MOSI & SCLK signals somehow and re-attach them to the header. It’s going to be a pain to do but it’s the only way to make it work. Newer shields may have this fixed but the current shield (from what I can see, is not). I hope this helps. Once this is done, it should work with the available sketches. I don’t remember having to change them. You can use the same CS.

  • good luck!