MicroSD TinyShield Tutorial

This TinyShield allows you to add a lot more memory to your TinyDuino projects. The Adapter TinyShield works directly with the Arduino SD Card libraries that are already installed in the Arduino IDE.
Learn more about the TinyDuino Platform
Description
Sometimes you need to add a little storage to your projects, and sometimes you need a lot. This TinyShield microSD Adapter lets you add a huge amount of storage by connecting a microSD card to your TinyDuino. And with SD card support libraries included with the Arduino Software environment, you can have your project using microSD cards in a matter of minutes!
This TinyShield incorporates level shifters and a local power supply to ensure proper and safe operation over the entire TinyDuino operating voltage range up to and including 5V.
Note: This does not include the microSD card (sold separately). You can get a compatible microSD card here.
Technical Details
MicroSD Specs- Uses standard Arduino SD Card Library
- Supports standard microSD cards and SDHC cards
- Voltage: 3.0V - 5.5V
- Current: 100mA or more during SD card writes, depends on the microSD card being used. Because of this high current, the TinyDuino processor cannot be used with a coin cell.
SPI Interface used
- 10 - CS: This signal SPI chip select for the microSD card
- 11 - SCLK: This signal is the serial SPI clock out of the TinyDuino and into the microSD card.
- 12 - MISO: This signal is the serial SPI data out of the microSD card and into the TinyDuino.
- 13 - MOSI: This signal is the serial SPI data out of the TinyDuino and into the microSD card.
- 20mm x 20mm (.787 inches x .787 inches) Note: microSD card overhangs the edge by approx 3mm for easy removal
- Max Height (from lower bottom TinyShield Connector to upper top TinyShield Connector): 5.11mm (0.201 inches)
- Weight: 1.36 gram (.05 ounces)
To see what other TinyShields this will work with or conflict with, check out the TinyShield Compatibility Matrix
Notes
- This does not include the microSD card (sold separately). You can get a compatible microSD card here.
- A microSD card consumes a large amount of power when it is being accessed(100-200mA), so your system needs to have a power supply or battery that is large enough to power this. The coin cell option on the TinyDuino is not sufficient to power this. We recommend a battery if you will be using the project wirelessly.
Materials

Hardware
- Micro USB Cable
- TinyDuino and USB TinyShield OR
- MicroSD Card TinyShield
- MicroSD Card and Adapter
- Optional: Battery (You will need a power source if you intend to take your boards somewhere without a microUSB attachment)
Software
- Arduino IDE
- TinyCircuits adapted SD Library CardInfo example
- (optional) TinyCircuits adapted SD Library Data Logger example
- SD Card Formatting Utility
Hardware Assembly
Connect your processor board of choice to the SD Card TinyShield using the tan 32-pin connector. Connect your TinyDuino stack to your computer using the microUSB cable.

Make sure the power switch on your processor board is flipped to ON.
Software Setup
Fortunately, the SD card TinyShield is compatible with the Arduino SD card library. So instead of having to download an external library, all you need to do in order to use the SD library utilities in your future programs is to include the library at the top of your program:
#include <SD.h>
You will also need to make sure that the chipSelect variable at the beginning of every program is set to 10 instead of 4 in order to be compatible with the wiring on the SD Card TinyShield:
const int chipSelect = 10;
Formatting the microSD Card
The Arduino SD Card Library supports cards formatted with FAT16 and FAT32 filesystems. For best results, we recommend formatting your microSD card before use by using the official SD card formatting utility as supplied by the SD Card Association:
Testing it out
Plug in the formatted microSD card into the connector. Open the Arduino IDE, and go to the SD CardInfo sketch.
Select File -> Examples -> SD -> CardInfo.

If you're using the TinyDuino as your processor board, all you will have to do is change the chipSelect = 10
to make this example program work. If you are using a TinyZero or TinyScreen+, you will have to change every instance of SerialUSB
, or you can download this zip file we edited to work for both the TinyDuino and SAMD processor boards (TinyZero and TinyScreen+):

Now click the Upload button on the Arduino IDE to build the sketch and upload it to the TinyDuino stack. Open up the Serial Monitor by navigating to it under the Tools tab, or selecting the magnifying glass icon in the top right of the IDE.
Type something in and press "Send". You should receive some data back on the card and a list of files:

If this example program is having a problem recognizing the card, make sure chipSelect = 10
. Try to reformat your SD card using the official SD Card Utility mentioned above.
Using the microSD Card
There are a number of examples included in the Arduino IDE that will help you get started using the microSD card. One of the best basic examples to get you started is the Datalogger example (in the Arduino ID under File...Examples...SD...Datalogger). This example will read several ADC values and store them to a file on your microSD card. Just be sure to remember to set the ChipSelect variable at the top of the file to a "10".
Before uploading the sketch, the chipSelect variable must be assigned a value of 10.

Upload the sketch to the TinyDuino and open the Serial Monitor. Type something into the monitor and press Enter or Send.

Code
/*
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
modified 24 May 2019
by Laveréna Wienclaw for TinyCircuits
*/
// 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, and TinyCircuits SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// MKRZero SD: SDCARD_SS_PIN
const int chipSelect = 10;
// Make program compatibile for all TinyCircuits processor boards
#if defined(ARDUINO_ARCH_SAMD)
#define SerialMonitor SerialUSB
#else
#define SerialMonitor Serial
#endif
void setup() {
// Open serial communications and wait for port to open:
SerialMonitor.begin(9600);
while (!SerialMonitor) {
; // wait for serial port to connect. Needed for native USB port only
}
SerialMonitor.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)) {
SerialMonitor.println("initialization failed. Things to check:");
SerialMonitor.println("* is a card inserted?");
SerialMonitor.println("* is your wiring correct?");
SerialMonitor.println("* did you change the chipSelect pin to match your shield or module?");
while (1);
} else {
SerialMonitor.println("Wiring is correct and a card is present.");
}
// print the type of card
SerialMonitor.println();
SerialMonitor.print("Card type: ");
switch (card.type()) {
case SD_CARD_TYPE_SD1:
SerialMonitor.println("SD1");
break;
case SD_CARD_TYPE_SD2:
SerialMonitor.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
SerialMonitor.println("SDHC");
break;
default:
SerialMonitor.println("Unknown");
}
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
SerialMonitor.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
while (1);
}
SerialMonitor.print("Clusters: ");
SerialMonitor.println(volume.clusterCount());
SerialMonitor.print("Blocks x Cluster: ");
SerialMonitor.println(volume.blocksPerCluster());
SerialMonitor.print("Total Blocks: ");
SerialMonitor.println(volume.blocksPerCluster() * volume.clusterCount());
SerialMonitor.println();
// print the type and size of the first FAT-type volume
uint32_t volumesize;
SerialMonitor.print("Volume type is: FAT");
SerialMonitor.println(volume.fatType(), DEC);
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1KB)
SerialMonitor.print("Volume size (Kb): ");
SerialMonitor.println(volumesize);
SerialMonitor.print("Volume size (Mb): ");
volumesize /= 1024;
SerialMonitor.println(volumesize);
SerialMonitor.print("Volume size (Gb): ");
SerialMonitor.println((float)volumesize / 1024.0);
SerialMonitor.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) {
}
This TinyShield adds a significant amount of memory to the TinyDuino (when accompanied by a MicroSD card) and can be used in projects that need to store or interpret much more data.
If you'd like to look further into the features of the SD Arduino Library, check out the SD Library Reference Page.
Downloads
Contact Us
If you have any questions or feedback, feel free to email us or make a post on our forum. Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it.
Thanks for making with us!