wokwi-microsd-card Reference
microSD card with SPI interface
Pin names
Name | Description |
---|---|
CD | Card detect * |
DO | SPI data output (MISO) |
GND | Ground |
SCK | SPI clock |
VCC | Voltage supply |
DI | SPI data input (MOSI) |
CS | Chip select |
* 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.
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 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
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 |
#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() {
}