• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

MicroSD card with ESP8266 NodeMCU file does not open

Q&A Forum › MicroSD card with ESP8266 NodeMCU file does not open
0 Vote Up Vote Down
Abdulmagid Omar asked 6 years ago

Here is my code :Details are at the end

//================================================

#include "FS.h"
#include <SD.h>
#include <SPI.h>
#include <DHT.h>
#define DHTPIN D2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const int CS_PIN=D8;
void setup() {
pinMode(CS_PIN,OUTPUT);
Serial.begin(9600);
Serial.print("Inicializando o cartão SD...");
dht.begin();

if (!SD.begin(CS_PIN)) {
Serial.println("Falha, verifique se o cartão está presente.");
//programa encerrrado
return;
}

Serial.println("Cartão inicializado.");

}

void loop() {
float Humidity = dht.readHumidity();
Serial.print("Humidity: ");
Serial.println(Humidity);
float temperature = dht.readTemperature();
Serial.print("Temperature: ");
Serial.println(temperature);

File dataFile = SD.open("LOG.txt", FILE_WRITE);

if (dataFile) {
Serial.println("writing data in DS file LOG.txt");
dataFile.print(Humidity);
dataFile.print(" | ");
dataFile.println(temperature);
dataFile.close();
}

else {
Serial.println("error opening file");
}
delay(2000);
}

//================================================

Sample output on the serial monitor:

Humidity: 64.00
Temperature: 24.00
error opening file
Humidity: 64.00
Temperature: 24.00
error opening file
Humidity: 64.00
Temperature: 24.00
error opening file

//@@@@@@@@@@@@@@@@@@@@@

I am using:

Micro SD Card Module  The micro SD card module has six pins:

VCC , GND ,MISO, MOSI, SCK, and SS

Connections used:

// PIN DEFINITIONS /////////////////////////////////////////////

//

SD_SCK_PIN  connects to ESP8266 NodeMCU  pin D5

SD_MISO_PIN  connects to ESP8266 NodeMCU  pin D6

SD_MOSI_PIN  connects to ESP8266 NodeMCU pin D7

SD_CHIP_SELECT_PIN  connects to ESP8266 NodeMCU pin D8

 

3 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago
  • Does that module ever worked before (like with an Arduino)?
  • How did you format the MicroSD Card?
  • Can you double-check the connections again?
  • How are you powering your module? With 5V or 3.3V?
  • Can you check that the MicroSD card is fully inserted in the module?

Thanks!

0 Vote Up Vote Down
Abdulmagid Omar answered 6 years ago

Thanks for responding

  • It works with Arduino nicely
  • I formatted it in the same way as in your blog (ESP32 Data Logging Temperature to MicroSD Card)
  • Connections are correct 
  • I used 3.3V
  • Yes, because I used the same module and card with Arduino and was fine.

 
Thanks

1 Vote Up Vote Down
Abdulmagid Omar answered 6 years ago

Never mind, I figured it out.
I just needed to use 5 V for Vcc and add a slash before the file name as follows:

File dataFile = SD.open("/LOG.txt", FILE_WRITE);


Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.