My sketch reads data from 2 DS18b20s, a DHT 11, and a DS3231 rtc, then logs the data, and displays an LCD.
The most recent compilations are acting a little strange, however…sometimes the serial data gets corrupted, sometimes it quits after just a few iterations, and sometimes it works ok for a while, but reports an error opening the datalog.
I had this circuit working nicely, before trying to add the rtc module...I am wondering if this is just because I am running low on memory:
"Sketch uses 23,956 bytes (74%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,652 bytes (80%) of dynamic memory, leaving 396 bytes for local variables. Maximum is 2,048 bytes.
Low memory available, stability problems may occur."
Are the errors I am experiencing typical, of low memory conditions?
Would switching the project to a Mega enable me to work around this difficulty?
Actually, the sketch memory is less than 32K because of the bootloader. Still, my guess is that it is SRAM that's the major problem. Keep in mind that string literals are duplicated in SRAM. Try using the F() macro to move the string literals from SRAM in flash memory and see if that helps. That is, instead of:
Serial.print("Write something on the Serial Monitor");
try framing it with the F() marco:
Serial.print(F("Write something on the Serial Monitor that is stored in FLASH"));
Yup - you can use F() for any place where you're print()ing or println()ing.
Those are definitely the sort of symptoms I'd expect if you were running out of memory. I suspect you're also throwing around the String class, which behaves horribly in low memory situations.
charlestonchu:
Would switching the project to a Mega enable me to work around this difficulty?
While a Mega is commonly used for datalogging projects, what you are doing should fit in a Uno OK. A sketch using 23900 should not cause problems and, as remarked elsewhere, using strings is probably the cause of all your problems. In that event, moving to a Mega may simply be putting off the inevitable. As it is, I bet there is no need to use strings, there hardly ever is. For the DS18B20s, just read the floats and print them. I imagine the DHT is the same.
F() works when you wrap it around a constant string. Like a menu item or other human-readable sentence. F("This is a string because it has quotes around it.")
You can't wrap it around variables and function calls. That makes no sense to the compiler.
(an aside - it takes 2 or 4 extra bytes of flash to put a string in the F() macro. I have been in a situation where I was removing F() macros to make my program fit in flash - I had enough RAM to spare, but had filled the flash)
F macro works like a charm. I ran into this message -- 77% of memory used -- and just by introducing F macro into all of my Serial.print and Serial.println statements involving literals, it instantly went down to 55%, warning went away. The repetitive editing forced me to refresh my memory of vim macro recording a beneficial side effect.