How to check if the Arduino Uno has a memory problem?

Hi All,

I have a Arduino Uno with a program that is around 14,000 bytes great, so in theory i have enough left.

I have the Uno connectot to a BOE shield with a compass sensor, 3 servos and a BlueSMiRF. For the program i have made a state machine with some functions. In a state i print out some informatation but when i looked at the serial monitor it gives al lot of strange symbols and the program runs wrong. When i remove some code lines then the program gives the write information and runs correctly? Is this a memory problem? Because when i remove some code lines the program works fine, and how do i check if this is a memory problem?

I have a Arduino Uno with a program that is around 14,000 bytes great

That's flash (program) memory - it says nothing about how much RAM you're using.

Simple test for memory problems: Look for the word "String" in your sketch :wink:

Hi,

Yes you are ofcourse right! the lines that i removed where prints, so this also has impact on the RAM? When the Uno runs out of RAM does is give strange sybols in the serial print?\

@majenko: Maby a stupid question but why? Do strings take up a lot of memory?

When it runs out of RAM, just about anything can happen.
Make sure you use the F() macro for your constant string prints.
Maybe post your code.

Datoeter:
Hi,

Yes you are ofcourse right! the lines that i removed where prints, so this also has impact on the RAM? When the Uno runs out of RAM does is give strange sybols in the serial print?

When ram is overrun just about anything wierd can happen, none of which are useful. Note that you can store constant string messages in program memory (flash memory) and print them out from there, thus unburdening the ram use in your sketch.

Maby a stupid question but why? Do strings take up a lot of memory?

He wrote "String", not "string".

It depends how long the "strings" or "Strings" are.

Tips:

Use F("foo") instead of "foo" where you can (not all functions support it)

Use char * instead of String.

Use byte instead of int for things that don't need the range of an int.

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

String objects use dynamic allocation. They can mess up your heap and waste bytes besides the overhead they use.
When you have 2k for heap and stack, using C++ String objects is like having truck races in a 2 acre field. You can but it's not going to be pretty.