Memory storage issue. Cannot use whole memory

Hello everyone.

I am working on a hobby project to monitoring things at home. Now I am working with pH probes and conductivity probes for my aquario.

So this probes (Atlas Scientifics probes) has several options: you can ser a name, reset, power on/off led, calibrating... So I made a sketch with a brief menú so configuration is much easier.

I am working with arduino uno and have 32Kbytes of memory. The problem I have is that when I reach more or less 11,5 KB, the programa gets Crazy. I have program the same but with different code (to see if it was my mistake) and the same problem.

What happens bassically for example, I have a 5 option in my menú and control the option with a switch case statement. So for example I start the program and with not touching nothing (by default only appears the menu and I have to write in a number which I send by SPI from computer and with that I select in the switch case statement) the Serial.print inside the cases appears. Anything you can imagine happens, what I think is that the program is bad allocated un memory, because sometimes funcions that I do not call get executed and so on.

I know code is correct because if I start commenting Serial.print to reduce memory, everything works well.

Anyone experiencias can help me?

Thanks so much

I know code is correct because if I start commenting Serial.print to reduce memory, everything works well.

Each print statement with a string uses SRAM. If you use too much SRAM your program will crash or fail in another way.

Use the F() macro like this in print statements:

  Serial.println("This string is stored in SRAM and can cause a problem");


  //  Change to something like this.

  Serial.println(F("This string is stored in flash and does not use SRAM"));

fat16lib:
Each print statement with a string uses SRAM. If you use too much SRAM your program will crash or fail in another way.

Use the F() macro like this in print statements:

  Serial.println("This string is stored in SRAM and can cause a problem");

//  Change to something like this.

Serial.println(F("This string is stored in flash and does not use SRAM"));

Thanks. I will try and tell you. It seems is something like that the problem.

You can actually check the currently available SRAM memory during runtime.

int freeRam () 
{
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}

Found here, along with other examples: Arduino Playground - AvailableMemory
It works with me.