Breadboard
docs
Example project · Builds & projects

microSD write & read-back

A real 64 MB SD card in SPI mode: the Uno runs the honest init handshake (CMD0, CMD8, ACMD41), writes a message into a raw block through the hardware SPI port, reads it back with CMD17 and prints it on the serial monitor — watch the activity LED blink on the breakout. The card ships FAT16-formatted, so the Code tab’s SD.h sketch (compile & upload) can write real files to it too.

The microSD write & read-back circuit as rendered by the simulator

What's on the bench

  • Arduino Uno
  • Battery
  • microSD card

How it's wired

  • Battery · posArduino Uno · 5v
  • Battery · negArduino Uno · gnd
  • Arduino Uno · 3v3microSD card · vcc
  • Arduino Uno · gnd2microSD card · gnd
  • Arduino Uno · d13microSD card · sck
  • Arduino Uno · d11microSD card · mosi
  • Arduino Uno · d12microSD card · miso
  • Arduino Uno · d10microSD card · cs

The code

This Arduino C++ sketch lives in the Code tab; sign in and press Compile & upload to build real firmware for the emulated board.

// The same card through the Arduino SD library (the card comes
// FAT16-formatted, so SD.begin just works). CS on pin 10; the SD
// library drives the hardware SPI port (11/12/13) itself.
#include <SPI.h>
#include <SD.h>

void setup() {
  Serial.begin(9600);
  if (!SD.begin(10)) {
    Serial.println("card init failed");
    return;
  }
  Serial.println("SD init OK");
  File f = SD.open("log.txt", FILE_WRITE);
  f.println("HELLO FROM SD :)");
  f.close();
  f = SD.open("log.txt");
  Serial.print("log.txt: ");
  while (f.available()) Serial.write(f.read());
  f.close();
}

void loop() {}

Related projects