Getting SD.h to work on SparkFun RP2040 Thing Plus

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.
  1. Tried standard SD.h with no modifications.
    Result: "Initialization failed!"

  2. 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.

  1. 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!"

  1. 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!"

  2. Also tried adding this just before SD.begin

	SPI1.setRX(12);
	SPI1.setTX(15);
	SPI1.setSCK(14);

Result: "Initialization failed!"

  1. 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?

  1. Installed the correct core?
    RP2040 Thing Plus Hookup Guide - SparkFun Learn
    image

Note, not the commonly used: GitHub - earlephilhower/arduino-pico: Raspberry Pi Pico Arduino core, for all RP2040 boards

Reference below: RP2040 Thing Plus Hookup Guide - SparkFun Learn

Note: Users trying to access the SD card slot will need to modify the pins_arduino.h file to reconfigure the SPI bus pins. However, this will make the SPI bus inaccessible through the breakout pins (when utilizing the SPI library).

  • On a Windows 10 computer, with the Arduino IDE installed through the App store, the location of the pins_arduino.h file is:C:\Users\<username>\Documents\ArduinoData\packages\arduino\hardware\mbed_rp2040\<package_version>\variants\RASPBERRY_PI_PICOArduino folder for file modification

pins_arduino.h file in the RASPBERRY_PI_PICO folder. (Click to enlarge)

// SPI
#define PIN_SPI_MISO  (12u) //(4u)
#define PIN_SPI_MOSI  (15u) //(3u)
#define PIN_SPI_SCK   (14u) //(2u)
    

line modifications

Beyond the above, if you have additional concerns, you may well wish to ask on the Sparkfun's forum... the support cost is built into your purchase price.

Thanks so much for your reply, but...

However, this will make the SPI bus inaccessible through the breakout pins (when utilizing the SPI library)

I could get my money back, but after all the weeks of effort I put in to getting SPI to work It would be worth $20 to me to smash the @#$%^&* thing with a sledge hammer! :face_with_symbols_over_mouth:

Understand, and maybe an inquiry to Sparkfun's forum will provide a workaround. While everyone here tries to assist with all non-Arduino hardware, sometimes our expertise may fall short of the manufacturer's knowledge. As you will see, this is a documented (common) issue: Using build in SD Card in Sparkfun Thing Plus RP2040 board · Issue #1 · khoih-prog/RP2040_SD · GitHub

https://forum.sparkfun.com/index.php

For all forum members,
3rd party "arduino" product manufacturers may produce products that are good products but targeted to a niche market or use-scenario. As such, such products may be problematic to the end-user compared to generic authentic Arduino boards.

Always do an online search, check the manufacturer's website including their support and GitHub sites to avoid disappointment.

Do not select a non-Arduino board based solely on price.

mrburnette;

Now wish I could take that last post back; an over-reaction at the end of a long frustrating day, sorry (I guess I am human after all.) Thanks for your well thought-out replies, I will press on (and in the future I will think before I post.)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.