Dears,
i am doing a project with Nodemcu v3, max 31865 and SD card datalogger. I am able to see the display on the phone with the IP address and also the temperature updates very well even visible in the serial monitor. The data needs to be logged into the SD card on every 2second, but the challenge which i face is; the file is freshly overwritten all the time with single value and not creating a log.
I have attached code along with this mail and please assist me how to solve this challenge? I google quite a bit but i couldnt understand the reason. Let me know how to proceed,
Test-6-AP-Max31865-C-SDCARD.txt (4.79 KB)
blh64
January 13, 2020, 3:47am
#2
You open the file in setup() but never close it.
You open it again inside loop() but never close it. That means that each time through loop, you are trying to open it again.
If you are going to open it in setup(), then don’t open it again each time through loop().
I tried the part of closing the file in the void Loop() section and still no luck. i changed my sd card adaptor and still quite unlucky. Everytime it stores the last value displayed on the serial monitor.
i changed the probe to DHt22 and wrote a fresh code… still the same challenge. I formatted the sd card to fat32 and still the same challenge. I really dont understand where i am making a mistake here…
i can see the values in the serial monitor very well but just this data logging is driving me crazy…
/*
ESP8266 SD Card Module
CS D8 (HCS)
SCK D5 (HSCLK)
MOSI D7 (HMOSI)
MISO D6 (HMISO)
VCC VV (+5)
GND GND
*/
#include <SD.h>
#include <DHT.h>
#define DHTPIN D2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#define CS_PIN D8
float mytemp;
float myhumi;
void setup()
{
Serial.begin(9600);
Serial.print(“initializing SD…”);
dht.begin();
if (!SD.begin(CS_PIN)) {
Serial.println(“Card is not present - FAILED.”);
return;
}
Serial.println(“Card Initialized.”);
}
void loop()
{
myhumi= dht.readHumidity();
Serial.print("Humidity: ");
Serial.println(myhumi);
mytemp = dht.readTemperature();
Serial.print("Temperature: “);
Serial.println(mytemp);
delay(200);
File dataFile = SD.open(“LOG.txt”, FILE_WRITE);
if (dataFile) {
Serial.println(“The file was opened successfully.”);
dataFile.print(myhumi);
dataFile.print(” | ");
dataFile.println(mytemp);
dataFile.close();
}
else {
Serial.println(“failed to log into LOG.txt”);
}
}
after an extensive search i found the answer.....
refer the link below
opened 08:31PM - 16 May 19 UTC
closed 12:12AM - 17 May 19 UTC
waiting for feedback
### Basic Infos
- [X] This issue complies with the [issue POLICY doc](https:/… /github.com/esp8266/Arduino/blob/master/POLICY.md).
- [X] I have read the documentation at [readthedocs](https://arduino-esp8266.readthedocs.io/en/latest) and the issue is not addressed there.
- [X] I have tested that the issue is present in current master branch (aka latest git).
- [X] I have searched the issue tracker for a similar issue.
- [X] If there is a stack dump, I have decoded it.
- [X] I have filled out all fields below.
#### Platform
- Hardware: [ESP-12]
- Core Version: [latest git hash or date]
- Development Env: [Arduino IDE 1.8.9]
- Operating System: [MacOS]
### Settings in IDE
- Module: [Generic ESP8266 Module and Adafruit Feather Huzzah]
- Flash Mode: [qio]
- Flash Size: [4MB/1MB]
- lwip Variant: [v1.4|v2 Lower Memory|Higher Bandwidth]
- Reset Method: [ck|nodemcu]
- Flash Frequency: [80Mhz]
- CPU Frequency: [80Mhz]
- Upload Using: [SERIAL]
- Upload Speed: [921600] (serial upload only)
### Problem Description
After updating to 2.5.1, data that gets pushed to an existing file on the SD-Card via
file.println(data); gets no longer added below the last line in the file, but replaces the whole file content. So only the last data, that was pushed to the file, stays there.
I was not able to figure out whether the whole file is replaced or only the content.
Same issue with short and long file name.
Examples to reproduce the Error: SD/Datalogger or SD/ReadWrite
Or the one below.
Output on Serial Monitor at readout should be:
> test.txt:
> testing 1, 2, 3.
> testing 4, 5, 6.
But only is:
> test.txt:
> testing 1, 2, 3.
```
#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {
Serial.begin(9600);
while (!Serial) {
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
myFile.println("testing 1, 2, 3.");
myFile.close();
myFile.println("testing 4, 5, 6.");
myFile.close();
Serial.println("done.");
}
else {
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
}
```
### Debug Messages
none
committed 08:55PM - 16 May 19 UTC
in the above link the interesting part is that old SD.h file doesnot allow to append