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
- 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!
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