Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!




ESP32 use microSD m...
 
Share:
Notifications
Clear all

[Solved] ESP32 use microSD module

23 Posts
2 Users
0 Likes
5,952 Views
 tvr4
(@tvr4)
Estimable Member
Joined: 4 years ago
Posts: 122
Topic starter  

I can not get the microSD to work on the ESP32.  I can connect the module to my Arduino Nano and it works fine.

I used the CardInfo example from the Arduino IDE under Examples/SD/CardInfo. 
No matter how I wire the SD module the sketch returns "initialization failed"

I also tried a few sketches for the Uno, Nano and some that were supposed to work on the ESP32 and all give an error initializing the SD module.

Most of these sketches use SD.h but some use SdFat.h

 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

Hi again 😋 

Just being curious: did you use the correct power pin?
If I recall correctly, most SD card readers need 5V (versus 3.3V). 


   
ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 4 years ago
Posts: 122
Topic starter  

@hansYes I did check the power.

I have the same SD module connected to my Nano. When I had problems getting it to work on the ESP32 I swapped the boards.
Both boards work properly when connected to the Nano.  Neither will work properly with the ESP32


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

What is the exact error you're getting?

In an attempt to try to find a solution, I did read somewhere that removing the SD card while uploading the sketch could do the trick.
Maybe this is a helpful post. 🤞🏻


   
ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 4 years ago
Posts: 122
Topic starter  

The problem is in the part of the code that initializes the SD card.  I have tried the SD module connected to my nano and there are no issues.   I have not been able to get the module to work connected to the ESP32

Serial.print("\nInitializing SD card...");

Here is the initiilization from the cardinfo example in the SD.h

if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
while (1);
} else {
Serial.println("Wiring is correct and a card is present.");
}

The code may be slightly different but the result is the same, it will not find or initialize the SD module on the ESP32


   
ReplyQuote


 tvr4
(@tvr4)
Estimable Member
Joined: 4 years ago
Posts: 122
Topic starter  

I sent days of research and weeding through code that the authors say will work, but actually doesn't.

I was able to get the microsd module working on the ESP32.  I don't quite understand why the other libraries and wiring didn't work.
But as long as it works.

The key was using mySD.h and not SD.h or SDfat.h.  Not sure why they don't work but I think it has something to do with the non-standard SPI pins on the ESP32.

Wiring is on the Heltec ESP32 WiFi Lora Development board.

SD Module
CS     to ESP32 Pin 26
SCK   to ESP32 Pin 27
MOSI to ESP32 Pin14
MISO to ESP32 Pin 13
VCC   to ESP32 5V
GND  to ESP32 GND

Code needs to be changed from
#include SD.h

to this
#include mySD.h


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

Interesting find 👍 

As far as I can see, the mySD.h is a wrapper for the sdfatlib library, and uses these libraries:

#include <SPI.h>
#include <utility/SdFat.h>
#include <utility/SdFatUtil.h>
#include <utility/Sd2Card.h>

I see it being used in this library: ESP32 micro SD card where the writer states: "this library is for Arduino, I modified it to adapt with ESP32".
Rather poorly linked on his Github page, but I did manage to find this demo - which may or may not be helpful.

He used this for wiring (the same as you did as far as I can see):

CS microSD   -> ESP32 IO26 (for SPI: ESP32 IO5)
MOSI microSD -> ESP32 IO14 (for SPI: ESP32 IO23)
MISO microSD -> ESP32 IO13 (for SPI: ESP32 IO19)
SCK microSD -> ESP32 IO27 (for SPI: ESP32 IO18) 
GND microSD -> ESP32 GND
VCC microSD -> ESP32 3.3V (some SD card readers may require 5V)


   
ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 4 years ago
Posts: 122
Topic starter  

That would make sense since, as far as I could tell, does not change from SD.h to mySD.h

When I ported the sketch from the nano to the ESP32 the only change I made to the SD portion is to change the library.  The code itself did not change.

Did you see anything about using long filenames or is mySD still limited to 8.3 filenames?

On a side note, how can you create wiring diagrams like the one you sent?

Thanks.  I will look over the library for more info just in case


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

Long vs short filenames:

I'd try to stick to short file names - it's just the most foolproof approach.
I can see that you'd probably want to store a date/time in the filename, which would make 8.3 too short for this purpose.

Diagrams:

This one I actually copied from another website, but when I do want to draw something like this I typically grab, and highly recommend, Fritzing (free and they offer a nice service for PCB's - which I have not used yet).


   
ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 4 years ago
Posts: 122
Topic starter  

I came to the same conclusion about filenames.,  I just changed the name of the GPS data file from data.txt to GPS-data.txt

I looked at fritzing and it is no longer free:
"We are asking you to pay 8€ (less than US$9) for downloading the application.
This way we can ensure future releases, bugfixes and features.

I did find a download on another site but the app just locks up after running. Maybe it doesn't like windows 10


   
ReplyQuote


 tvr4
(@tvr4)
Estimable Member
Joined: 4 years ago
Posts: 122
Topic starter  

@hans
I have been experimenting with frizing and it is HORRIBLE

It crashes constantly, many parts I design do not save or appear to save only to disappear again

Any other options are greatly appreciated


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

Interesting, Fritzing has never given me any problems (under macOS). 🤔 
Not sure when you tried it the last time? I recall that specifically under Windows, early version could be "problematic" haha.

Maybe Circuit.io is a good alternative you may want to look into. Personally I do not like web-based apps.

Back in the day, mostly for PCB design but they have added more options, Eagle was the way to go.
Unfortunately, it feels like they forgot to innovate and they have been purchased by AutoDesk. (link - there appears to be a free version).


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

I totally overlooked the message from you where you mention that Fritzing is no longer free ... yikes.

I did find a few links where you can still download a recent version:

  • nPack.org (link - Windows version, it says 0.9.4 but it actually is 0.9.3b)
  • ComputerBild (German) seems to have 0.9.4 available for Windows (link
  • Domoticx (Dutch) has quite a few versions for Windows (link)

Having said that: I have no idea what is going on with those guys ... seems they had a ton of legal issues, and now (yikes!!) switched to JavaScript ... not sure when or as of what version this happened though.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

Just tested the Fritzing version (for Mac) from ComputerBild and it works pretty OK (it is a little slow), so I'd assume it may work under Windows as well.

After spending some time on Circuit.io, I can say that it looks really nice but with some setups you're forced to use it a certain way (try adding an ESP8266 + a LED strip -> it will add MosFETs even though I didn't ask for it). In the meanwhile, I think Eagle may not be the tool for you, as it still heavily focuses on PCB design.

I was not able to find a "great" alternative 😔 


   
ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 4 years ago
Posts: 122
Topic starter  

@hansI looked at eagle and it is very complicated and I agree, I don' t think it will do what I need.

I did download the latest fritzing from the page you suggested.  I should have asked you to translate where the download was since I can not read the German.  But google translate did a good enough job that I was able to find and download it.

The version fritzing.0.9.4.64.pc_and_dll seems to be a huge improvement and stable.  At least it runs without constantly crashing.

I just created a simple breadboard view, no connections yet.  I could not find the GPS module or the display in the parts.  But I found an Adafruit fritzing parts master which did include the SSD7735 display with microsd.

I was not able to find a fritzing part file for the GPS module.  But I found a simple breadboard file where I was able to copy and past a basic GPS module for now.

I will try making connections and see how it goes.

Thanks for the help!


   
ReplyQuote


Page 1 / 2

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: