I have a micro SD card module on hand and I want to use it with NodeMCU ESP8266. However, since NodeMCU provides a 3.3V output, the SD card module cannot be initialized. When I run the SD card module with Arduino Uno, which operates at 5V, it works fine. Even when I connect it to the 3.3V pin of Arduino Uno, it still doesn't work.
I am supplying 5V externally to the SD card module through an adapter, but it still doesn't work. Where could I be making the mistake?
SD card uses 3.3 V. so additional circuit on the module converts the 5 V. some SD modules can work with both 5 V and 3.3 V but then there are two Vcc pins. 3.3 and 5 V one.
I moved your topic to an appropriate forum category @faruk_7586.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
Thank you all for your interest. I'm sharing the circuit below and the error I encountered. Additionally, I will also share the 5V circuit at the end, as I couldn't get positive results from any of them.
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
SD card attached to SPI bus as follows:
** MOSI - pin D7
** MISO - pin D6
** SCK - pin D5
** CS - pin D2
*/
#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) { Serial.write(myFile.read()); }
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}
The result I obtained is this.
initialization failed!
I fed the SD card with 5V in the second case, but the code did not work at all
That module was designed to be used with 5V microcontrollers. The module's Vcc pin is connected to the input of a 3.3V regulator, which in turn supplies everything else on the module. Here's the schematic:
So you have to supply 5V power to the module's Vcc pin to provide 3.3V to the SD card. The module's extra chip normally level shifts the incoming MOSI, SCK and CS lines from the MCU, which would normally be 5V signals, down to 3.3V, which is what the card expects. However, if the incoming lines are already 3.3V, then the translator chip will simply translate 3.3V to 3.3V, and everything should still work.
So if it works with an Arduino, but not with the ESP8266 when the module is powered with 5V, then the most likely explanation is that you're using the wrong pins on the ESP8266 for SPI.
The issue is that if I power the SD card module from Arduino with 5V, it works without any problems. However, when I connect the SD card module to an external 5V power source, it still doesn't work.
It turns out the only problem was the orange cable. I hadn't connected it to the ground of the Nodemcu. Thank you very much, my friend. I hope everything goes well for you.