New user issues with ESP32 and a SD Card Reader
-
- Posts: 15
- Joined: Wed Jan 06, 2021 9:46 am
New user issues with ESP32 and a SD Card Reader
Hi all,
First time poster here and have only had my ESP32 for 2 months now!
I am having issues getting my SD card reader to work. It works perfectly in my Arduino Uno, but I can't get it to work on my ESP. My wiring is as below (it is a 5v SD board):
SD Card - ESP32
CS - 5
SCK - 18
MOSI - 23
MISO - 19
When I load up on the Arduino IDE the Example 'SD-Files' it just says the below in the Serial output:
Initializing SD card...initialization done.
example.txt doesn't exist.
Creating example.txt...
example.txt doesn't exist.
Removing example.txt...
example.txt doesn't exist.
If I take out the SD card from the reader the Initialization fails, so I know that it can see the card, it just can't read or write to it. The SD card is 2GB and formatted as FAT. I have tried 3 different card readers and 4 different SD cards, all card readers and cards are readable by my Arduino Uno.
I tried loading the example 'CardInfo', but it errors on compile stating " 'Sd2Card' does not name a type".
Does anybody have any basic code that allows loading of a file and writing something to it?
I want to write a program that reads a text file for the SSID and password details which are stored on it, so it can then use them to connect to a wireless network.
Many thanks to all who reply to my post.
Alan
First time poster here and have only had my ESP32 for 2 months now!
I am having issues getting my SD card reader to work. It works perfectly in my Arduino Uno, but I can't get it to work on my ESP. My wiring is as below (it is a 5v SD board):
SD Card - ESP32
CS - 5
SCK - 18
MOSI - 23
MISO - 19
When I load up on the Arduino IDE the Example 'SD-Files' it just says the below in the Serial output:
Initializing SD card...initialization done.
example.txt doesn't exist.
Creating example.txt...
example.txt doesn't exist.
Removing example.txt...
example.txt doesn't exist.
If I take out the SD card from the reader the Initialization fails, so I know that it can see the card, it just can't read or write to it. The SD card is 2GB and formatted as FAT. I have tried 3 different card readers and 4 different SD cards, all card readers and cards are readable by my Arduino Uno.
I tried loading the example 'CardInfo', but it errors on compile stating " 'Sd2Card' does not name a type".
Does anybody have any basic code that allows loading of a file and writing something to it?
I want to write a program that reads a text file for the SSID and password details which are stored on it, so it can then use them to connect to a wireless network.
Many thanks to all who reply to my post.
Alan
Re: New user issues with ESP32 and a SD Card Reader
Some code might help!
I have used an SD card on ESP32 (using a hacked Ardunio driver) without issue - and I test hard.
My only 'quick win' thought is that you should wind SPI clock speed back to say 1 MHz and then work up.
ESP32 peripherals are slower than you might expect & GPIO muxing does not help.
Actually, a second thought is that Ardunio is often 5V and so is your card a 5V card??
Would be great for you to post in the bragging forum once done as AFAIK there is not a posted SD card driver (least not 18 months ago when I had this task).
Post if you resolve though, even if it was a solder joint!
I have used an SD card on ESP32 (using a hacked Ardunio driver) without issue - and I test hard.
My only 'quick win' thought is that you should wind SPI clock speed back to say 1 MHz and then work up.
ESP32 peripherals are slower than you might expect & GPIO muxing does not help.
Actually, a second thought is that Ardunio is often 5V and so is your card a 5V card??
Would be great for you to post in the bragging forum once done as AFAIK there is not a posted SD card driver (least not 18 months ago when I had this task).
Post if you resolve though, even if it was a solder joint!
& I also believe that IDF CAN should be fixed.
-
- Posts: 15
- Joined: Wed Jan 06, 2021 9:46 am
Re: New user issues with ESP32 and a SD Card Reader
Thank you @PeterR for your reply. Yes, it might have been helpful for me to post some code.
The ESP32 that I am using is "ESP32-WROOM-32D".
In answer to your question, the SD card reader is 5v, it has a AMS1117 voltage regulator and level shifter on the board. Below is a photo of it:
Then below is it wired up:
The test code that I am trying to use is:
The Serial Output is this:
I would be more than happy to write a post once I have it working so others can see it in the future.
If @PeterR you can offer any advice, it would be greatly taken. If though you think I would be better to use a different SD card reader, I am happy to buy different one if you can suggest one.
Many thanks
Alan
The ESP32 that I am using is "ESP32-WROOM-32D".
In answer to your question, the SD card reader is 5v, it has a AMS1117 voltage regulator and level shifter on the board. Below is a photo of it:
Then below is it wired up:
The test code that I am trying to use is:
Code: Select all
#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(5)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
} else {
Serial.println("example.txt doesn't exist.");
}
// open a new file and immediately close it:
Serial.println("Creating example.txt...");
myFile = SD.open("example.txt", FILE_WRITE);
myFile.close();
// Check to see if the file exists:
if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
} else {
Serial.println("example.txt doesn't exist.");
}
// delete the file:
Serial.println("Removing example.txt...");
SD.remove("example.txt");
if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
} else {
Serial.println("example.txt doesn't exist.");
}
}
void loop() {
// nothing happens after setup finishes.
}
Sadly since I am so new to this, I do not know how to lower the clock speed. I literally am downloading sample code to see if it works, how it works and trying to alter it to suit my needs.Initializing SD card...initialization done.
example.txt doesn't exist.
Creating example.txt...
example.txt doesn't exist.
Removing example.txt...
example.txt doesn't exist.
I would be more than happy to write a post once I have it working so others can see it in the future.
If @PeterR you can offer any advice, it would be greatly taken. If though you think I would be better to use a different SD card reader, I am happy to buy different one if you can suggest one.
Many thanks
Alan
-
- Posts: 364
- Joined: Mon Jan 04, 2021 2:06 pm
Re: New user issues with ESP32 and a SD Card Reader
Hi,
Why don't you try soldering some wires on a SD Card adaptor (SD to micro SD)? Since everything works on 3V3, you don't need the LDO and the level shifter.
This is not a proper solution but can give you a chance to test it.
Why don't you try soldering some wires on a SD Card adaptor (SD to micro SD)? Since everything works on 3V3, you don't need the LDO and the level shifter.
This is not a proper solution but can give you a chance to test it.
-
- Posts: 15
- Joined: Wed Jan 06, 2021 9:46 am
Re: New user issues with ESP32 and a SD Card Reader
Hi @ ESP_Minatel
Thank you for your reply.
I'd be ok to try this, but can you point me to a web page that shows what pin goes where and some sample code.
Many thanks
Alan
Thank you for your reply.
I'd be ok to try this, but can you point me to a web page that shows what pin goes where and some sample code.
Many thanks
Alan
-
- Posts: 364
- Joined: Mon Jan 04, 2021 2:06 pm
-
- Posts: 15
- Joined: Wed Jan 06, 2021 9:46 am
Re: New user issues with ESP32 and a SD Card Reader
Thank you very much @ESP_Minatel
I will give that a try later on today and will let you know how I go. I am going to order some of the below from a well known China distributor, so I can solder them directly to the PCBs I make. I will just need to work out their pin layouts once they arrive.
Again, thank you for your help.
I will give that a try later on today and will let you know how I go. I am going to order some of the below from a well known China distributor, so I can solder them directly to the PCBs I make. I will just need to work out their pin layouts once they arrive.
Again, thank you for your help.
Re: New user issues with ESP32 and a SD Card Reader
This may be problem with sd card, esp32 can be picky about sd cards.
-
- Posts: 15
- Joined: Wed Jan 06, 2021 9:46 am
Re: New user issues with ESP32 and a SD Card Reader
Thank you so much for your help ESP_Minatel. I took an old SD Card reader and soldered the wires directly to it. I was able then to access it and have made myself a basic Datalogger program.
That is a good point @chegewara, thank you.
Onto the next project now!
Cheers all
Re: New user issues with ESP32 and a SD Card Reader
I had the same issue recently and the advice of ESP_Minatel helps me too, so use it
Who is online
Users browsing this forum: No registered users and 89 guests