[FIXED] Too many constants in my project cause weird bugs

Hi all,

I'm new to Arduino and I encounter a weird problem with my main project. I'm working with an arduino Uno R3, and my projetc is quite big (22,018 bytes of 32,256 bytes maximum)

After adding some code to my project, I noticed some random parts of my code were no longer executed without any reason.

After some tries, I found out the problem appears when adding more constants to the code. By "constants" I mean not only values defined as const, but also variables declared with an initial value like int i=1; and also hard coded strings like in Serial.print("abc") or lcd.print("def").

I am at a point where if I add a few chars more of constants, my code will no longer work, but I still have around 10,000 bytes availaible for Code and adding code is fine as long as it doesn't contains constants.

Can anyone explain me where it comes from and why the compiler doesn't issues a warning about this ?

Is there a maximum memory size that can be allocated to constants and that is less than the 32kB available for code ?

Thanks in advance for your answers !

also hard coded strings like in Serial.print("abc") or lcd.print("def").

For those use the F macro. Like Serial.print(F("abc")); The F macro reads the "abc" from flash and does not copy to SRAM.

Many Thanks groundfungus for your quick reply !

The F Macro fixed my issue :)

I thought it was a problem with code storage in flash, but now I understand it is an SRAM overflow problem, I guess my project is using almost all the SRAM available...

I wonder if ALL these hard coded strings in print() statements are copied to SRAM on sketch startup ?

I'll have to learn how to optimize my code for lower SRAM usage...

[u]EDIT:[/u] I just saw the PROGMEM modifier that allows to store large variables in flash instead of SRAM I also found a very useful link: Arduino RAM Overflow