Arduino.cc says SD.h works on ALL architectures, but it's not working for me.
- Computer: Raspberry Pi 4 with 8G Memory
- OS: Linux raspberrypi 5.10.103-v8+ #1529 SMP PREEMPT Tue Mar 8 12:26:46 GMT 2022 aarch64 GNU/Linux - fully updated.
- Software: Arduino IDE version 1.8.19 - Boards and Libraries fully updated.
- Board: SparkFun Thing Plus RP2040 Board Info: BN: SparkFun ProMicro RP2040, VID: 1b4f, PID: 0026
- Note: The board is a "SparkFun Thing Plus RP2040", but Tools/Get Board Info returns "SparkFun ProMicro RP2040". (which is a different SparkFun RP2040 board that does NOT have a Built-In SD Card Slot.)
- SD Card: SanDisk 32GB Formated as FAT32. And still has data on it from a 5 year old Arduino project that used SD, so I know it's formatted correctly.
-
Tried standard SD.h with no modifications.
Result: "Initialization failed!" -
From the "RP2040 Thing Plus Hookup Guide"
under the Hardware Section it says:
The µSD card slot is connected to the following dedicated GPIO:
GPIO 09: DATA 3/CS
GPIO 10: DATA 2
GPIO 11: DATA 1
GPIO 12: DATA 0/CIPO (or Peripheral's SDO)
GPIO 14: CLK/SCK
GPIO 15: CMD/COPI (or Peripheral's SDI)
but doesn't make it clear how to use that information.
- Tried modifying /home/pi/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/variants/sparkfun_thingplusrp2040/pins_arduino.h
as per Using build in SD Card in Sparkfun Thing Plus RP2040 board · Issue #1 · khoih-prog/RP2040_SD · GitHub
Added:
#define PIN_SPI_MISO (12u)
#define PIN_SPI_MOSI (15u)
#define PIN_SPI_SCK (14u)
#define PIN_SPI_SS (9u)
Result: "Initialization failed!"
-
Tried using RP2040_SD Library Using build in SD Card in Sparkfun Thing Plus RP2040 board · Issue #1 · khoih-prog/RP2040_SD · GitHub
Result: "Initialization failed!" -
Also tried adding this just before SD.begin
SPI1.setRX(12);
SPI1.setTX(15);
SPI1.setSCK(14);
Result: "Initialization failed!"
- And tried this (didn't document where I got it):
#if defined(ARDUINO_ARCH_MBED)
#define PIN_SD_MOSI PIN_SPI_MOSI
#define PIN_SD_MISO PIN_SPI_MISO
#define PIN_SD_SCK PIN_SPI_SCK
//#define PIN_SD_SS PIN_SPI_SS
//#define PIN_SD_SS 5
#define PIN_SD_SS 9
#endif
if (!SD.begin(4)) {
...
Result: "Initialization failed!"
// SparkFun_Thing_Plus_RP2040_Test_SD.ino
/*************************************************************************************************/
// Includes
#include <SPI.h>
#include <SD.h>
/*************************************************************************************************/
// Global Constants
const static int iBAUD_RATE = 9600;
/*************************************************************************************************/
// Global Variables
File myFile;
/*************************************************************************************************/
void setup() {
Serial.begin(iBAUD_RATE);
while (!Serial) {
;
}
delay(1000);
Serial.print("Initializing SD card...");
// Tried adding the following: didn't work.
//SPI1.setRX(12);
//SPI1.setTX(15);
//SPI1.setSCK(14);
//// Also tried the following: didn't work.
//#if defined(ARDUINO_ARCH_MBED)
//
// #define PIN_SD_MOSI PIN_SPI_MOSI
// #define PIN_SD_MISO PIN_SPI_MISO
// #define PIN_SD_SCK PIN_SPI_SCK
// //#define PIN_SD_SS PIN_SPI_SS
// //#define PIN_SD_SS 5
// #define PIN_SD_SS 9
//#endif
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
myFile.close();
Serial.println("done.");
} else {
Serial.println("error opening test.txt");
}
myFile = SD.open("test.txt", FILE_READ);
if (myFile) {
Serial.println("test.txt:");
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close();
} else {
Serial.println("error opening test.txt");
}
}
/*************************************************************************************************/
void loop() {
// nothing happens after setup
}
/*************************************************************************************************/
Can someone please post an SD example that works on a SparkFun Thing Plus RP2040?


