SPARKFUN ESP32 VROOM PLUS C does not see SD card when using ARDUIN IOT CLOU EDITOR

SPARKFUN ESP32VROOM PLUS C(PART# WRL-20168) does not recognize the SD card when using the ARDUINO IOT cloud editor. The sparkfun example code SD_test.ino works fine.

Here is the Arduino IOT code I am using, I am getting "Card Mount Failed"and “No SD card attached”;

/*
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/6b7debab-1df0-4ab0-b3a8-96d9381a8a44

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  int TargetLaunch;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

#include "FS.h"
#include <SPI.h>
#include <SD.h>

const int sd_cs = 5; //Thing Plus C

int targetPin = 33;  //INCREMENT TARGETS COUNT, SEND TO SD CARD
int target;
int count;
int counter;
int countPin = 12;  //RESET COUNTER TO ZERO

void setup() {
  pinMode(targetPin,INPUT);
  pinMode(countPin,INPUT);
  
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);
  
 Serial.println("SD test");

  if (!SD.begin(sd_cs)) {
    Serial.println("Card Mount Failed");
    //return;
    }
  uint8_t cardType = SD.cardType();

  if (cardType == CARD_NONE) {
    Serial.println("No SD card attached");
    //return;
    }

  Serial.print("SD Card Type: ");
  if (cardType == CARD_MMC) {
    Serial.println("MMC");
    } else if (cardType == CARD_SD) {
    Serial.println("SDSC");
    } else if (cardType == CARD_SDHC) {
    Serial.println("SDHC");
    } else {
    Serial.println("UNKNOWN");
    }

  uint64_t cardSize = SD.cardSize() / (1024 * 1024);
  Serial.printf("SD Card Size: %lluMB\n", cardSize);
    
  Serial.println("FILE NAME = Untitled 4/16/2023");
  
  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
  */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();


}

void loop() {
  ArduinoCloud.update();

  counter = digitalRead(countPin);

  if (counter == HIGH)
  {
    Serial.println("counter == HIGH");
    count = 0;
  }

  target = digitalRead(targetPin);

  if (target == HIGH)
  {
    Serial.println("target == HIGH");
  }

}

/*
  Since TargetLaunch is READ_WRITE variable, onTargetLaunchChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onTargetLaunchChange()  {
  // Add your code here to act upon TargetLaunch change
}

Hi,

Please double-check that you have the latest Espressif ESP32 Board package installed (v2.0.7 is the latest) and that you have the correct board selected: SparkFun ESP32 Thing Plus C (not SparkFun ESP32 Thing Plus).

If it is still not working, perhaps try commenting out the ArduinoCloud code, just in case there is some kind of conflict?

You may get more / better replies of you ask your question here: https://forum.sparkfun.com/viewforum.php?f=97

I hope this helps!

Best wishes,

Paul

Also, it is rare but there are some microSD cards that need an extra pull-up on pin 19 (SPI POCI). Connecting a 10K resistor between pin 19 and 3.3V can sometimes help.

Best wishes,

Paul

I had a similar problem with the SD test example sketch until I corrected the SS pin definition in the C:\Users\micha\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\variants\esp32thing_plus_c\pins_arduino.h file.

The schematic indicates the correct definition should be 5 not 15

static const uint8_t SS = 5;

After this correction I had no problem connecting to the SD card.

Regards,

Mike

Hi Mike,

Each SPI peripheral needs its own Chip Select line. 15 is a good and valid choice for any SPI peripherals you are connecting to the breakout pins on the Thing Plus C. But, yes, agreed, the SD CS is indeed pin 5. The safest thing is to define the chip select explicitly in your code and use it when starting SD - like @williamlynn did in the original post:

const int sd_cs = 5; //Thing Plus C

  if (!SD.begin(sd_cs)) {
    Serial.println("Card Mount Failed");
    }

If you call SD.begin() without providing the pin, then it will default to SS.

When you next update the ESP32 core / board package, pins_arduino.h will be overwritten and your code will stop working again. Best to define the SD CS explicitly in your code.

I hope this helps,

Paul

Hi Paul,

Yes, I agree that does work. My point was more of a question about why the header file for the Thing Plus C does not reflect the true pinout for the product.

Thanks,

Mike