Memory limits

I am using an Arduino Nano which has 2 K of dynamic memory. The program I have been developing is about 800 lines of C, fairly involved, and was going fine. Then it utterly quit functioning! I notice after a compile that it tells me that I have used 1649 bytes of dynamic memory for global variables, so "stability problems may occur".

But when I carefully count up my global variables, I only find about 300 bytes allocated. I do import the LiquidCrystal_I2C, Wire, SoftwareSerial, and EEPROM libraries.

Any idea what is going wrong here, and is there any way to use program memory for variables?

Thanks in advance for any insights.

Without seeing how your code is actually using memory? Would you ask a mechanic to tell you what's wrong with your car, without letting him see your car?

Regards,
Ray L.

jrdoner:
Any idea what is going wrong here, and is there any way to use program memory for variables?

Beginners typically waste memory when printing static texts like

  Serial.println("This is wasting RAM");

instead of using the F-macro and printing static text from flash memory:

  Serial.println(F("This is saving RAM by using the F-macro"));

Just a guess, without seeing your code...

BTW: Using "Serial" alone costs you more than 128 bytes of RAM: 64 bytes for the incoming buffer and 64 bytes for the outgoing buffer. Of course, all the RAM needed by your included libraries counts into the RAM limit. So if you include RAM-wasting libraries, you waste RAM.

You cannot use program memory for variables. If you use all those libraries, it is probably too much for the nano. There is probably several hundred bytes of memory used in each of them.

michinyon:
You cannot use program memory for variables. If you use all those libraries, it is probably too much for the nano. There is probably several hundred bytes of memory used in each of them.

I have the following libraries in my project now. I’m just over the warning limit for memory, so it is definitely a concern. But I have a feeling the OP has used too much memory in the sketch. It is, after all, just a tiny 8 bit single chip MCU.

#include <EEPROM.h>
#include <Time.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <DS3232RTC.h> 
#include <Timezone.h>
#include <HT1621.h>

By the way, the term “dynamic memory” is a quirky and arguably incorrect name that only exists in the IDE compile messages, as far as I know. It’s really static memory, or static RAM.

Jurs,
Thanks for that tip. I have a lot of text in that program, and I was never aware of why people user the F() function with text. I have easily melted away about 1 KB of memory use because of that suggestion. I'm not exactly a beginner, since I've been programming since 1962. But I "backed into" a knowledge of C by just relying on the Arduino reference. Again, I'm really glad to learn that.