RESOLVED - How can I debug an issue with SD Card reading?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
sethcstenzel
Posts: 5
Joined: Thu Mar 29, 2018 2:05 pm

RESOLVED - How can I debug an issue with SD Card reading?

Post by sethcstenzel » Mon Apr 22, 2019 11:10 pm

As far as I can tell, I have read all the SD card related posts, and can't seem to figure out why I can't simply connect an SD card reader to my ESP32's. I have tried both hardware SPI and software and can't seem to mount and SD card.

I am able to mount the same SD card using micro python on an esp8266 however. It seems strange to me that the process would not be identical. Any assistance in how I should go about tracking down why it is failing would be greatly appreciate.

Everything seems to go fine until I try to mound the sd card object.

If possible try to imagine you are talking to a gorilla because I am pretty new to all this so dumb it down for me if you can.

Here is the basic code that I have that is failing.
Failed with 2 separate SD cards, pny and sandisk
Failed with 3 separate SD card readers
Failed on 3 separate ESP32 board types.

Here is the basic code I'm trying to use.

>>> import sdcard
>>> from machine import SPI, Pin
>>> import os
>>> spi_sd = SPI(-1, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
>>> sd = sdcard.SDCard(spi_sd, Pin(5))
>>> os.mount(sd, '/sd')
Traceback (most recent call last):
File "<stdin", line1, in <module>
OSError: [Errorno 19] ENODEV
>>>

Here are the 3 boards I've tried on.
https://www.ezsbc.com/index.php/feature ... L5ImOhKiUk

https://www.ebay.com/itm/MINI-D1-ESP32- ... SwyutchAgp

https://www.ebay.com/itm/TTGO-MINI-32-V ... 2749.l2649
Last edited by sethcstenzel on Tue Apr 23, 2019 3:20 pm, edited 3 times in total.

User avatar
Mike Teachman
Posts: 71
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: How can I debug an issue with SD Card reading?

Post by Mike Teachman » Tue Apr 23, 2019 3:54 am

Here is what works for me, using the Lolin D32 Pro hardware.

Code: Select all

import uos
import sdcard
from machine import Pin
from machine import SPI
spi = SPI(1, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
sd = sdcard.SDCard(spi, Pin(4))
uos.mount(sd, "/sd")
Two thoughts:
- I have problems getting small capacity SD cards (e.g. 2GB) to work with the sdcard.py module. 10GB cards work.
- GPIO5 is a strapping pin on the ESP32 which has an internal pull-up resistor. This should only matter at boot time, but who knows ... Could that be causing issues with CS? Perhaps try GPIO4 as the chip select.

sethcstenzel
Posts: 5
Joined: Thu Mar 29, 2018 2:05 pm

Re: How can I debug an issue with SD Card reading?

Post by sethcstenzel » Tue Apr 23, 2019 5:04 am

Thanks for the assistance.
Still the same error however. The Cards and 16gb and 32gb. Both work in cellphones and computer. I've reformatted both as well.

>>> import uos
>>> import sdcard
>>> from machine import Pin
>>> from machine import SPI
>>> spi = SPI(1, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
>>> sd = sdcard.SDCard(spi, Pin(4))
[0;32mI (7542) gpio: GPIO[23]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m
[0;32mI (7542) gpio: GPIO[19]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m
[0;32mI (7552) gpio: GPIO[18]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m
[0;32mI (7682) gpio: GPIO[23]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m
[0;32mI (7692) gpio: GPIO[19]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m
[0;32mI (7692) gpio: GPIO[18]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m
>>> uos.mount(sd, "/sd")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 19] ENODEV
>>>
>>>

This is the right library correct?
https://github.com/micropython/micropyt ... /sdcard.py

sethcstenzel
Posts: 5
Joined: Thu Mar 29, 2018 2:05 pm

Re: How can I debug an issue with SD Card reading?

Post by sethcstenzel » Tue Apr 23, 2019 5:16 am

Thanks again for your help. If anything it let me know that I was not completely off my rocker. I had tried similar things to what you had as well in my 5 hours of trials today trying to get this to work.

Apparently it is the microsd card readers themselves that are bad. After thinking how unlikely it was that all my esp32 boards were bad, and since the sd cards worked on pc and had been used in esp8266 projects in the past, I went ahead and dug out an esp8266 wemos to try and load from the microsds with it since I knew I had done so around christmas 2018.

I also could not get it to work correctly with either of the 2 microsd card readers that I had. I'm not sure if they are both bad, I'm assuming so, or there is something I'm missing with them. Maybe somehow I fried them and didn't know it or something, IDK. They are both this model:
https://www.ebay.com/itm/For-Arduino-Mi ... Swn7JYCc9i

However after it failed I realised I had an older standard sd card reader and after I hooked that up I was able to get it to work on the esp8266 and the esp32 after. The micro sdcards were still good, I just used them and an adapter for a standard sd card size.
https://www.ebay.com/itm/SD-Card-Module ... xy-W9SNHsJ

Thanks again for the help! :D I tried both using pin 4 and pin 5 and both seem to work fine. :lol:

>>> import uos
>>> import sdcard
>>> from machine import Pin
>>> from machine import SPI
>>> spi = SPI(1, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
>>> sd = sdcard.SDCard(spi, Pin(5))
[0;32mI (9202) gpio: GPIO[23]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m
[0;32mI (9202) gpio: GPIO[19]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m
[0;32mI (9212) gpio: GPIO[18]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m
[0;32mI (9512) gpio: GPIO[23]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m
[0;32mI (9512) gpio: GPIO[19]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m
[0;32mI (9522) gpio: GPIO[18]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m
>>> uos.mount(sd, "/sd")
>>> import os
>>> os.listdir()
['sd', 'boot.py', 'sdcard.py']
>>> os.listdir('sd')
['System Volume Information', 'categories']
>>>

User avatar
Mike Teachman
Posts: 71
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: How can I debug an issue with SD Card reading?

Post by Mike Teachman » Tue Apr 23, 2019 1:37 pm

Glad you got it working. Yay!.

After reading your description of the problem I have another idea. What voltage goes to the Catalex SD card reader? 3.3V or 5V? it looks like it needs a 5V input.

The 2nd SD Card you listed is the exact model that I use.

sethcstenzel
Posts: 5
Joined: Thu Mar 29, 2018 2:05 pm

Re: How can I debug an issue with SD Card reading?

Post by sethcstenzel » Tue Apr 23, 2019 3:13 pm

Hey Mike,

You are totally right. I made two mistakes, well maybe one and a half. First I misread the data sheet, it is a 5v sd card reader, however it is both 5v and 3.3v logic level compatible. I thought when I read it, that it was both 5v and 3.3 compatible as far as power supply needed.

However I actually did try both 3.3v and 5v with those since I thought the reader could handle both and it failed. I think the 5v pin on the board I was using when I tried 5v was not working. I lent out my multi-meter so I can not test the 5v pin on the ttgo board that I am using, however I used my built in multi-meter and simply tested quickly on my tongue ( I know gross ) the difference between 3.3v and 5v on that board and I can feel no difference. I have a duplicate of that board, and "re-tested" for 5v on that pin with the duplicate board and could feel a drastic difference. I'm assuming that maybe even though the board has a 5v pin that the board must be damaged somehow.

Basically my mistake of misreading the documentation combined with a physically damaged board let me to the pits of dispair and complete desperation last night. I worked my way through all 4 of the first steps of the 7 steps of grief :D Thanks to you I made it to step 5! :lol:
https://www.recover-from-grief.com/7-st ... grief.html

Here is the board if interested https://pasteboard.co/IbtKUPC.png

So I provided a separate 5v power source tied grounds and tried again, and the sdcard reader worked strait away and I was able to mount it. So either that pin is not giving me 5v, or it can't handle the sd card readers draw maybe or something.

It really was a "Yay!" as it was the last piece of hardware being tested working for a project, and as I mentioned I had the sd card reading working a few months back on the esp8266 and another esp32 so I figured I'd have zero issue with the sd reading and could start putting my project together on a few pcbs instead of my rats nest of wires and start coding the project as a whole, as right now it is all just separate files testing all the components individually and making sure they were working.

Thanks again for all your help!

Post Reply