Low memory warning on Nano

In a code that I wrote for Nano I seem to be getting into a low memory issue. All print statements use the F macro. And as far as possible variables are restricted to functions and of course some are at Global level.

The warning I get is :

Sketch uses 20582 bytes (66%) of program storage space. Maximum is 30720 bytes.
Global variables use 1796 bytes (87%) of dynamic memory, leaving 252 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.

Possibly I am running into this mess because of too many libraries I think … the list is as below :

#include <LiquidCrystal_I2C.h>
#include <AltSoftSerial.h>
#include "Wire.h"
#include <SPI.h>
#include <SdFat.h>
#include <phi_interfaces.h>
#include <Nanoshield_ADC.h>
#include <EEPROM.h>

Right now the code is working but I am scared as to when the thing will crash as I cannot simulate all of the field conditions. This is a data logger.

I suppose that depends on the different functions calls and if the balance 252 bytes can manage the local variables in them, then it will keep going fine ? Is there a method to evaluate this ?

Please post the complete program so that we can see what data types you are using

Posted as attachment as its large…

DataLogger_4Ch_4-20mA.zip (8.77 KB)

The sprintf() function has a version that stores the pattern in program memory, sprintf_P()

As an example:

//original line from your code
sprintf( lcdBuff, "Param00 Max. = %c%c%c%c", Param_Array[0], Param_Array[1], Param_Array[2], Param_Array[3]);

//same line, storing pattern in program memory
sprintf_P( lcdBuff, PSTR("Param00 Max. = %c%c%c%c"), Param_Array[0], Param_Array[1], Param_Array[2], Param_Array[3]);

You can also use strcpy_P instead of strcpy, and store the literal in program memory:

//original line from your code
strcpy(alphaMonth, "Jan");

//same line, storing literal text in program memory
strcpy_P(alphaMonth, PSTR("Jan"));

Those changes should give you a bit more room in the dynamic memory.