microSD card module
A real FAT16 card behind SD.h. Watch the files a sketch writes appear, and download them.
- 6 pins
- 2 settings
- In 2 projects
- In 1 lesson
The microSD card module in brief
What it is, and every setting the properties panel gives it.
A microSD card module is the small SPI breakout with a card socket, a 3.3 volt regulator and a level shifter, which is why it takes 5 volts on VCC from an Uno: CS to pin 4 or 10, SCK to 13, MOSI to 11 and MISO to 12, or on a Mega 52, 51, 50 and 53. Mokxi puts a 4 MB card in it, formatted as a real FAT16 volume with a partition table, and the card speaks the SPI mode of the SD specification: CMD0, CMD8, ACMD41, CMD58, single and multiple block reads and writes, with R1 status, data tokens, CRCs and busy after a write. The files property sets what the card holds when the run starts, as 8.3 names mapped to text; while it runs, whatever a sketch writes appears beside the board and can be downloaded singly or as a disk image. Clicking the board ejects the card, and a sketch then has to call SD.begin() again. Real cards are slower to initialize and stall now and then while erasing, and SDHC cards, FAT32 and long file names are not modeled.
- Family
- Clocks and links
- Pins
- 6
- files
- {"HELLO.TXT": "Hello from the SD card.\r\n"}
- inserted
- true
6 pins
Named as the editor names them, so a wire lands where you expect it.
How to use a microSD card module with an Arduino
The module goes on the Uno’s SPI pins: MOSI to 11, MISO to 12, SCK to 13, and CS to pin 10, with VCC on 5 V. Call SD.begin() with the CS pin and check what it returns, then SD.open() a file with FILE_WRITE, print to it and close() it.
Bytes wait in a 512-byte buffer until a sector fills or the sketch calls flush() or close(), so a logger that keeps its file open should flush every second or so, as the rocket flight computer does. Pull the card out mid-run and SD.begin() has to be called again.
#include <SPI.h>
#include <SD.h>
void setup() {
Serial.begin(9600);
if (!SD.begin(10)) {
Serial.println("No card");
while (true) {}
}
File file = SD.open("LOG.TXT", FILE_WRITE);
file.println("Hello from the Uno");
file.close();
}
void loop() {}What is true about the microSD card module, here
In its help article’s own words: what the simulation gets right, and where it stops.
Not modeled
Real cards are slower in ways this one is not: long initialization, and a write that now and then takes a hundred milliseconds while the card erases. High capacity (SDHC) cards, FAT32 and long file names are not here.
Everything goes over SPI a bit at a time, driven by the sketch, so reading a
512-byte sector takes tens of milliseconds on an Uno, where a real SPI port takes
well under one. On a faster board each bit waits a little before it is read, so the
answer the card has just put on MISO has arrived; that makes a card read on an
ESP32-C3 or a Pico slower still. It is the one thing about this card that is
slower here than on the bench, and it matters when a sketch also has to keep up
with something else, like a GPS: the GPS logger in the gallery writes its lines
five at a time for that reason.
From microSD card module, in full.
See the microSD card module in a project
2 built-in projects use it. Each opens in the editor, already wired.
Where it turns up in a lesson
One lesson places it in its own circuit.
The boards it is shown on
Each of these 2 boards has a built-in project with the microSD card module in it.
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the microSD card module
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.