Help with temp/humidty logger

Greetings all.

I think this should be a fairly simple thing. Arduino Mego board with three DHT22 temp/humidity sensors. An SD Card module. A RTC clock module.

Logic is simple enough: Read the values of the three sensors. Read time. Put it into a string. Open the SD Card, write string to log file. Close the SD card. Wait five minutes and do it all over again.

The only ‘fancy’ thing is to check that the readings are greater than zero and if not, delay two seconds and re-read the values.

The code I have works fine for some period of time, seems about 12 hours. Then the SD card fails to open the log file and the whole mess stops.

Inside the code, I have added sections that write the values to serial so I can see what is going on.
This includes the sensor values, date/time, what is about to be written, then it reads back the data in the log file.

Can anyone explain what might be going on?

Thanks in advance.

IndoorTempSensor-2.ino (11 KB)

Sure. The String class is causing fragmentation of the heap, causing it to crash when it runs out of memory.

So is there an easy solution?

I did some more reading - I think what you are saying is described here:

I commented out the file print back code thinking this might be the source.
Added freemem() from here:

and added a call for freemem() in the loop where the file print back code was.
Now I just need to let it run for a few hours to see what happens.

So far no change at all in the number returned. 6261.


Still get errors opening log file.
In Serial.Print:
error opening logfile

Am I to conclude then that this isn't a RAM issue and start looking elsewhere?