Prepare SD Shield & Card

We chose the Adafruit Assembled Data Logging Shield for this project. It’s the most affordable and trouble-free way to add an SD card reader to an Arduino, and the combined board stack is slim enough to fit inside a popular mint tin.

There are other shields with SD (or microSD) card slots in addition to other features. Most can work just fine as a card reader for this project. Some may have a display or buttons, but our example software doesn’t support these (nor will thicker shields fit inside the mint tin).

With a different enclosure and some custom code, you might be able to add a file selection user interface…or you might not. Memory is exceedingly tight, and we can’t really say whether adding a UI is even practical…it’s something we’ve not explored yet. For now it’s very basic.

Breakout boards for SD/microSD could also work, but we recommend using the shield…the prototyping area provides a solid point of contact for wires and parts we’ll be adding later.
Solder the included male pin headers to the shield following the directions in the Adafruit Data Logger Shield guide. Stacking headers are not recommended for this project; they won’t fit inside the mint tin.

Notice how the solder joints in the photo above are shiny, smooth and concave. The Adafruit Guide to Excellent Soldering illustrates proper soldering technique. “Cold” solder joints (cloudy and balled up on the surface, not flowing smoothly between pin and board) will cause the shield to work unreliably or not at all.

Installing the battery on the shield is optional. This project doesn’t require use of the realtime clock, so it’s okay to leave it out. If you’re planning to dismantle and use the shield in other future projects, or have an idea how you might use the clock in your light painting, go ahead and install the battery. It’ll last for years.
Plug the shield into an Arduino Uno, then connect a USB cable between the board and your computer. The green PWR led on the shield should light up. If it does not (and especially if the computer complains about a USB device drawing too much power), there’s probably a solder bridge between pins. Unplug USB, remove the shield and look it over for any soldering mistakes.

Card Tricks

It’s a good idea to designate a “scratch” card (or several) for this project. Do not use an important card with irreplaceable family photos on it! Our software reads and writes to the card, and perhaps there are bugs we haven’t spotted…there’s a small chance here of data being overwritten.

This task does not require massive storage. It’s a great opportunity to recycle those “tiny” old SD cards cluttering a drawer. You don’t need to buy anything exotic or high-end.

Plug the card into a USB SD card reader (or SD slot if your computer has one) and format it as a FAT filesystem. This has caused some trouble in the past, but more recent releases of both Windows and Mac OS X produce a card that the Arduino can read. If you encounter issues in the next steps, try formatting the card in a digital camera, or download the SD Association’s official SD card formatter application.

Toss a few small files or folders on the card for testing the next step, then eject the card.
Insert the card into the SD socket on the shield, then connect a USB cable between the Arduino and computer.

Launch the Arduino IDE. From the File menu, select: FileExamplesSDCardInfo

This example is part of the standard Arduino SD library; we’ll get into SdFatlib later.

You will need to make a small change to this code. Locate this line:
Download: file
const int chipSelect = 4;
and change it to:
Download: file
const int chipSelect = 10;
From the Tools menu, select Tools→Board→Arduino Uno

Also from the Tools menu, select the Serial Port corresponding to the Arduino USB connection, then click the Upload button (the circle with a right-facing arrow). In a moment, it should report “Done uploading,” and the red LED on the SD shield will light briefly.

Now open the Serial Monitor (the magnifying glass icon at the top-right of the Arduino editor window) and set the baud rate to 9600.

If this succeeds, you’ll see a listing of all the files and folders on the card (if any — but at the very least, it will report the card type and size).

If this reports an error, it’s usually one of three problems:
  • The chipSelect pin number is not set correctly in the software (should be 10).
  • The SD card format is not strictly following the specification. If this was formatted in your computer, try formatting the card in a digital camera instead, or use the aforementioned SD formatter application.
  • A soldering problem with the shield. If you post a clear photo in the Adafruit Customer Support Forums, we’ll look it over for any gremlins.
Do not proceed until you have the CardInfo sketch working, displaying the contents of the SD card. You need to have the SD card fully working before you can store any images on it!
This guide was first published on Dec 10, 2013. It was last updated on Dec 10, 2013. This page (Prepare SD Shield & Card) was last updated on May 22, 2019.