ESP 32 and Adafruit SDcard module

I am trying to get an ESP 32 to play a MP3 file.
I would like to use a Flutesan ESP 32 board with a Adafruit microSD breakout board.
When the sketch runs, I get an error message:
[ 15428][E][sd_diskio.cpp:199] sdCommand(): Card Failed! cmd: 0x37
[ 15428][E][sd_diskio.cpp:199] sdCommand(): Card Failed! cmd: 0x29
[ 15429][E][sd_diskio.cpp:802] sdcard_mount(): f_mount failed: (3) The physical drive cannot work
Error accessing microSD card!
I have checked my pin connections, have tried two different ESP boards, two different brands of ESP 32 boards, two different SDcard boards, three different sd cards, reinstalled the schreibfaul1/ESP32-audioI2S library and checked the connections countless times. Still, the same error!
I’m hoping someone here can show me what I’m doing wrong.

I’m including the source code here:

/*
  ESP32 SD I2S Music Player
  esp32-i2s-sd-player.ino
  Plays MP3 file from microSD card
  Uses MAX98357 I2S Amplifier Module
  Uses ESP32-audioI2S Library - https://github.com/schreibfaul1/ESP32-audioI2S
  * 
  DroneBot Workshop 2022
  https://dronebotworkshop.com
*/
 
// Include required libraries
#include "Arduino.h"
#include "Audio.h"
#include "SD.h"
#include "FS.h"
 
// microSD Card Reader connections
#define SD_CS          5
#define SPI_MOSI      23    // On SDcard reader is shown as DI
#define SPI_MISO      19    // On SDcard reader is shown as DO
#define SPI_SCK       18
 
// I2S Connections
#define I2S_DOUT      22
#define I2S_BCLK      26
#define I2S_LRC       25
 
 // Create Audio object
Audio audio;
 
void setup() {
    
    // Start Serial Port
    Serial.begin(115200);
    
    // Set microSD Card CS as OUTPUT and set HIGH

    Serial.println("My Message! About to set pinmode for CS");
    delay(5000);
    pinMode(SD_CS, OUTPUT);      
    digitalWrite(SD_CS, HIGH); 

   Serial.println("My Message! About to initialize SPI bus")    ;
   delay(5000);
    // Initialize SPI bus for microSD Card
    SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
    
   Serial.println("My Message! About to start microSD Card")    ;
   delay(5000);
    // Start microSD Card
    if(!SD.begin(SD_CS))
    {
      Serial.println("Error accessing microSD card!");
      while(true); 
    }
    
    // Setup I2S 
    audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
    
    // Set Volume
    audio.setVolume(5);
    
    // Open music file
    audio.connecttoFS(SD,"/MYMUSIC.mp3");
    
}
 
void loop()
{
    audio.loop();    
}

Hello Bart, are you able to provide exactly which ESP32 board you are using?

It could help provide an answer.

Can you please share your wiring diagram?

Double check the your SD Pull-up’s: SD Pull-up Requirements - ESP32 - — ESP-IDF Programming Guide latest documentation

esp-idf example here: https://github.com/espressif/esp-idf/tree/53ff7d43dbff642d831a937b066ea0735a6aca24/examples/storage/sd_card/sdspi

Regards,

One of them is a Flutesan board I ordered from Amazon. That’s about all the info I have. I have several of these and have tried three different ones to eliminate the possibility of a defective board. These boards work perfectly running another sketch.
The other board(s) I tried are Doit boards. They just say ESP32 DEVKIT V1.
All these boards have the Vroom esp chip.

Not to be smartalecie, but the wiring is pretty much shown in the source. Of course I used the pin labels, and not the actual pin numbers. I’ve changed the defines to try different pins with no success. The only gotcha is the sdcard shows DI and DO instead of MOSI and MISO.

The funny part of this there are three different videos on youtube showing how to do exactly what I’m trying and, on screen, it works just like it should! They all provide the code they used. And I even ordered the exact parts they used. I think these things just don’t like me!

I’m at a complete loss. It’s not like I haven’t spent the time looking over the wiring, watching the videos, looking my source over line by line, it’s been hours!

The only possibility I can think of is that I’m using a linux box running vscode while they were all using windows. But, I got the libraries from the same place as they did and they should be the same!

Hmmmmm! I’m going to see if I can borrow a windows box and try this there! (If I can find someone I know who still uses windows). I wonder if there’s a problem in the compiler?

I’ve never programmed for the ESP32 platform or SD Cards via SPI so take this with a grain of salt. :slight_smile:

I remember on the PICList many years ago others using SD cards via SPI found that not all brands and models of SD cards properly supported the SPI interface method (usually the much faster SD mode is used in PC’s Phones, etc.).

So maybe try a different SD card.

1 Like

Looks around my home office/lab… Just let me know if you want to share exactly how you wired it, as I’ve got a bunch of esp32/etc in my lab and could help validate it…

I’m assuming you used this model: MicroSD card breakout board+ : ID 254 : $7.50 : Adafruit Industries, Unique & fun DIY electronics and kits

Regards,

Hi bart,

Looks like you purchased the DFRobot DFR0229. That card module is intended to be used with 5V systems. It has a 5V to 3.3V regulator and level shifters. I’d bet your ESP32 board is a 3.3V board, so these two are incompatible.

You would need to either use a card module which is designed for 3.3V systems (no on-board regulator) and no level-shifters, or one which is designed for both 3.3V and 5V which is adaptable to either, such as the one RobertCNelson mentioned.

I would also verify that your card(s) is formatted to either FAT16 or FAT32, as I believe it must be one of those to be compatible.

@RobertCNelson,

As far as the wiring goes, it changes based on which ESP module I’m using. However, I wire it using the labels on the pins (D5, D23,D118, D19) rather than the pin number (1, 2, 3, etc). I have:
ESP ---- SDcard ---- Defined as
D5 ------ CS ----------- SD_CS
D18 ---- CLK --------- SPI_SCK
D19 ---- DO ---------- SPI_MISO
D23 ---- DI ------------ SPI_MOSI
3.3v ---- 3v
GND — GND

That is the sdcard I have. The Adafruit 254.

As far as the ESP cards go, I bought several of them from Amazon. They are shown as Flutesan brand and some say Wroom and some don’t. I have a couple of DoIt boards? And a couple others, one of which came DOA, the the other is suspect.

I have verified that the micro sd cards are formatted fat32, are =< 32G and have a valid .mp3 file. I can play the file on the sd card on both windows and linux. I have three different sd cards. All work.

I have been using VSCode and Platformio on my linux box for development. I tried to load Arduino SDE on a windows box but couldn’t get it use the library from Schreibfaul! so I installed VSCode and Platformio on that machine to see if a different compiler would be the cause. It wasn’t.

That is the card holder not the card, it is definitely SPI usage compatible.

But is the actual SD card you insert in the holder properly implementing SPI?

Many years ago I heard from other engineers and hobbyists that some cards would not work with SPI.

On Windows and Linux SD cards are NOT read/written with SPI mode, they use SD mode for reading/writing (SD mode is a lot faster but harder to use).

However. I would think that as long as the cards are three different reputable brands (e.g. SanDisk, Samsung, Kingston, PNY, TDK) at least one of them should work properly with SPI instead of SD mode access. But then again as I said up front, I’ve never worked with cards in SPI mode, maybe all SD cards work now.

Funny aside, the normal nomenclature is to call them ESP boards or ESP PCBs, ESP Cards are traditionally a different thing entirely. :laughing:

1 Like

The sd cards are PNY and Sandisk. However, one of the sandisk cards is marked HC. The other two are marked HCI. ??? There’s a difference? :slight_smile:

As for your aside, ya gotta give me a little room! Actually, thanks for the correction. I’m absolutely brand new to this stuff. I saw a video about an ESP32 “board” and thought “Hey! I wonder if I could…” So, here I am! Sure glad I found this forum!

Found another fun gocha, which revsion of the ESP32 chipset does esptool.py report when you flash your board?

esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting.....
Chip is ESP32-D0WD (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None

I found some fun conflicting issues between Espressif’s spi-sd library with some devices not allowing you map to other ports…

Otherwise a similar issue:

I (340) example: Mounting filesystem
E (370) sdmmc_common: sdmmc_init_ocr: send_op_cond (1) returned 0x107
E (370) vfs_fat_sdmmc: sdmmc_card_init failed (0x107).
E (370) example: Failed to initialize the card (ESP_ERR_TIMEOUT). Make sure SD card lines have pull-up resistors in place.

But the esp32thing_plus i’m using doesn’t map out the pins for the default state https://github.com/espressif/esp-idf/blob/master/examples/storage/sd_card/sdspi/README.md

and i’m fighting an un-defined CONFIG_SOC_SDMMC_USE_GPIO_MATRIX in the classic esp32…

Regards,

I’m not getting errors about reading the sd card, rather it says the ESP can’t recognize the card reader itself. I have two different brand modules coming. If neither of these work I’ll look at a different way to do what I want.

Thanks for your reply! Perhaps I’ll try all the different examples of pins recommended in the link you sent.

Well, I have it working! The problem was in my breadboard! I couldn’t get my head around the fack I might not have good connections. But when I direct wired the card module to the ESP32, it worked!

I bought a breadboard kit from Amazon, which is a hobbyest package with wires and all sorts of things. It’s obvious that, once again, you get what you pay for!

So, someone please tell me where I can get a good, reliable solid breadboard.

Here is a link to breadboards on the website:
Prototype Boards Perforated | Electronic Components Distributor DigiKey
This is the link to the solderless breadboards:
Solderless Breadboards | Electronic Components Distributor DigiKey
We also sell some jumper wire kits on this link:
Jumper Wire | Electronic Components Distributor DigiKey

They are most likely okay for the wires. I just added that in case they were not.

Glad to hear you got it sorted out.

While the more expensive breadboards and jumper kits are better, they are very far from perfect. So even if like me you buy excellent gear you will still have occasional puzzling intermittent connections.

My rules for least frustration with solderless breadboard prototyping:

  • Always insert, half-remove, then re-insert the wires and components to clean the oxidation from both the wire/pins and the breadboard contacts
  • Never make the circuit too large, prototype a small portion at a time. Once the circuit is designed and debugged I transfer it to a soldered breadboard before intermittent connections waste my time. (I have a hard limit 4" x 6" (100mm x 150mm) maximum for solderless breadboards at home and work)
  • When you see intermittent operation, wiggle the wires and if that doesn’t help, insert, half-remove, then re-insert the wires again.
  • When there’s a problem, confirm the electrical signals are correct at all connections with a multimeter.
    Common pins in the alligator clips make great probes for this, they fit in the breadboard holes and easily probe component leads. If you have brass pins, either raw or nickel plated, you can solder up dedicated test leads
  • Most importantly always remember the connections will not be very reliable and will require troubleshooting of their own. It’s the price we pay for rapid prototype circuit construction.

FYI - the largest model I currently use is this one:

However, I don’t think it’s significantly better than this newer model at half the price:

1 Like