breadboard
Example project · Builds & projects

Uno R4 · SPI SD readback

The pinned MIT SdFat library creates p5.txt on the emulated card, writes breadboard-p5 and reads it back in Serial. D10 selects the card; D11/D12/D13 carry SPI. The card uses the board’s real 3.3 V rail. Recompiling requires SdFat 2.3.0.

The Uno R4 · SPI SD readback circuit as rendered by the simulator

What's on the bench

  • Arduino Uno R4
  • Battery
  • microSD card

How it's wired

  • Battery · pos→Arduino Uno R4 · 5v
  • Battery · neg→Arduino Uno R4 · gnd
  • Arduino Uno R4 · gnd2→microSD card · gnd
  • Arduino Uno R4 · 3v3→microSD card · vcc
  • Arduino Uno R4 · d10→microSD card · cs
  • Arduino Uno R4 · d13→microSD card · sck
  • Arduino Uno R4 · d11→microSD card · mosi
  • Arduino Uno R4 · d12→microSD card · miso

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.

// Breadboard UNO R4 P5 SPI0 SD-card acceptance fixture.

#include <SdFat.h>

static SdFat sd;

void setup() {
  Serial.begin(115200);
  if (!sd.begin(10, SD_SCK_MHZ(8))) {
    Serial.println("sd begin failed");
    return;
  }

  FsFile file = sd.open("p5.txt", O_RDWR | O_CREAT | O_TRUNC);
  if (!file) {
    Serial.println("sd open failed");
    return;
  }
  file.print("breadboard-p5");
  file.sync();
  file.rewind();

  Serial.print("sd");
  while (file.available()) {
    Serial.write(file.read());
  }
  Serial.println();
  file.close();
}

void loop() {}

Firmware licence

Notice: this firmware uses the LGPL-licensed Arduino core library

arduino-unor4wifi-sd-spi.bin is statically linked with ArduinoCore-renesas 1.6.0, in Breadboard's port of its UNO R4 WiFi variant to Renesas FSP 5.3.0. Parts of that core are licensed under the GNU Lesser General Public License, version 2.1 or (at your option) any later version ("the Library"). Breadboard distributes this firmware under terms that permit you to modify the work for your own use and to reverse engineer it for debugging such modifications.

Related projects