> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/wokwi/wokwi-docs/llms.txt
> Use this file to discover all available pages before exploring further.

# microSD Card

> microSD card with SPI interface and FAT16 filesystem support

microSD card with SPI interface.

## Pins

<ParamField path="CD" type="detect">
  Card detect - The CD pin is connected to ground when there's no card in the socket. In the simulator, there's always a card in the socket, so this pin is always disconnected.
</ParamField>

<ParamField path="DO" type="spi">
  SPI data output (MISO)
</ParamField>

<ParamField path="GND" type="ground">
  Ground
</ParamField>

<ParamField path="SCK" type="spi">
  SPI clock
</ParamField>

<ParamField path="VCC" type="power">
  Voltage supply
</ParamField>

<ParamField path="DI" type="spi">
  SPI data input (MOSI)
</ParamField>

<ParamField path="CS" type="spi">
  Chip select
</ParamField>

## Filesystem

When you start the simulation, Wokwi creates a FAT16 file system and attaches it to the microSD card. By default, Wokwi copies all your project files into the microSD card.

### Uploading binary files

[Paying users](https://wokwi.com/pricing?ref=docs_sdcard) can upload custom binary files (e.g. bitmaps, sounds, etc.) to the microSD card's filesystem. After adding a microSD card to your project, you'll see a new "SD Card" tab next to the other tabs in the code editor. Click on the "Upload Files" buttons and select any files you wish to upload.

You can also upload a complete folder tree (useful if you have a physical SD card attached to your computer and you want to upload all the data from it, as-as). Click on the small arrow next to the "Upload Files" button and select "Upload complete folder". Then select the folder with the files you want to upload.

Wokwi stores the uploaded files for you, alongside with your project. Anyone who opens your project and starts the simulation will have to wait for all the micro SD card files to download before the simulation starts.

Example: [microSD Card project with a custom bitmap file](https://wokwi.com/projects/319810932695892564)

## Arduino code example

The example below uses the popular *SdFat* Arduino library. It prints a list of all the files in the card. The code assumes the following connections:

| SD card pin | Arduino Uno pin |
| ----------- | --------------- |
| SCK         | 13              |
| DO          | 12              |
| DI          | 11              |
| CS          | 10              |

```cpp theme={null}
#include "SdFat.h"

#define SPI_SPEED SD_SCK_MHZ(4)
#define CS_PIN 10

SdFat sd;

void setup() {
  Serial.begin(115200);
  if (!sd.begin(CS_PIN, SPI_SPEED)) {
    if (sd.card()->errorCode()) {
      Serial.println("SD initialization failed.");
    } else if (sd.vol()->fatType() == 0) {
      Serial.println("Can't find a valid FAT16/FAT32 partition.");
    } else {
      Serial.println("Can't determine error type");
    }
    return;
  }

  Serial.println("Files on card:");
  Serial.println("   Size    Name");

  sd.ls(LS_R | LS_SIZE);
}

void loop() {
}
```

[Run this example on Wokwi](https://wokwi.com/projects/310692660849410626)

## Simulator examples

* [SD library example](https://wokwi.com/projects/310542489623724609)
* [SdFat library example](https://wokwi.com/projects/310692660849410626)
* [Display a custom bitmap from microSD card on an ILI9341 LCD](https://wokwi.com/projects/319810932695892564)
