Connecting SD Card Module to NodeMCU ESP8266

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.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

These, or similar (or solder wires to the microSD contacts) --
https://www.amazon.com/dp/B0989SM146

1 Like

Can you post a picture of your microSD module?

If it worked with an Arduino when powered with 5V, then it seems it should work with your ESP8266 if powered from an external 5V.

Because I don't currently have an SD card module for 3.3 volts, I improvised and used a micro SD adapter for a different purpose:

The 32 GB Micro-SD shown here is connected to an ESP8266 (WEMOS D1 mini):

Pin assignment:

    Card Module             ESP8266        Cable
    ---------------------------------------------------
     3V3 --------------------------- 3V3    (red)
     SCK --------------- GPIO 14 --- D5     (green)
     MISO -------------- GPIO 12 --- D6     (yellow)
     MOSI -------------- GPIO 13 --- D7     (blue)
     CS ---------------- GPIO 15 --- D8     (brown)
     GND --------------------------- GND    (black)

Test sketch:

/*
  SD-Card write and read test with ESP8266

  Connections:
    MicroSD Card
    Card Module       ESP8266
    --------------------------------
     3V3 -------------------- 3V3 
     SCK -------- GPIO 14 --- D5
     MISO ------- GPIO 12 --- D6
     MOSI ------- GPIO 13 --- D7
     CS --------- GPIO 15 --- D8
     GND -------------------- GND
*/

#include <SPI.h>
#include <SD.h> 

File Textfile;   

void setup() {
  Serial.begin(74880);
  Serial.println("Initializing SD card");

  if (!SD.begin(15)) {  
    Serial.println("Initialization failed!");  
    return;
  }

  Serial.println("Initialization completed"); 
  Textfile = SD.open("test.txt", FILE_WRITE);  

  if (Textfile) {
    Serial.println("Writing to Textfile...");  
    Textfile.println("First line");    
    Textfile.println("1, 2, 3, 4, 5");
    Textfile.println("a, b, c, d, e");
    Textfile.println();
    Textfile.close();     
    Serial.println("Completed");       
    Serial.println();
  }
  else {
    Serial.println("Text file could not be read");  
  }

  // READ TEXTFILE
  Textfile = SD.open("test.txt");      
  if (Textfile) {
    Serial.println("test.txt:");    
    while (Textfile.available()) {
      Serial.write(Textfile.read());     
    }
    Textfile.close();    
  }
  else  {
    Serial.println("Text file could not be opened"); 
  }
}

void loop()  {
}

Output in serial monitor:

Initializing SD card
Initialization completed
Writing to Textdatei...
Completed

test.txt:
First line
1, 2, 3, 4, 5
a, b, c, d, e

Board: Generic ESP8266 Module

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

Bu the code is working in arduino

1 Like

Thank you for your interesting. I posted picture below.

Thank you for your interest I share the details of circuits

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 doesn't even work with the Arduino when powered externally?

on the photo the ground is not connected between the esp8266 and the SD card

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.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.