HEllo, this is actually a rather tricky issue that is rarely covered, and I've found almost impossible to debug
http://arduino.cc/en/Tutorial/Memory is a good guide, but to precis:
There's two kinds of memory in arduino
1) Flash memory - 32,768 bytes. This is where your program goes (and the bootloader).
2) SRAM - 2048 bytes. This is where your variables go.
When you upload your program, it tells you how much flash memory you've used, but it can't tell ahead of time how much SRAM you're going to use, because that depends on how the program actually runs.
You can do things like
int massiveArray[5000];
Which will define an array that is bigger than the total amount of SRAM. It'll compile ok, and even probably run ok, but when you try to put something into that space and then read it back out later, it'll behave very oddly.
It isn't a big problem unless you are dealing with big arrays, or Strings (which are just big arrays with a bit of decoration). And Polargraph uses Strings a lot. Additionally, I'm sure it uses Strings in a pretty inefficient way, because I don't really understand how to housekeep that stuff tidily, pointers etc. (My background is java so I'm pretty sloppy on that low-level stuff.)
The takeaway is that you can easily check your program memory usage when you upload, but you cannot easily check your SRAM usage.
A command like
Serial.println("Hello");
Expands your program memory because it adds the serial.println command into the list of things to do. It also uses SRAM because the String it is sending is created on-the-fly in SRAM. Using the F(...) function is a little helper for arduino, so you will see most of the Serial.prints look like
Serial.println(F("Hello"));
The F(...) function actually puts the string "Hello" into the program memory area (the FLASH area), so it doesn't use up any SRAM. Often this is enough, but there are some things you can't put in there - anything generated dynamically.
sn
|