My Arduino ran out of RAM!

With the SD card enabled, and a modest size buffer for songs I want to play, when I ran the code on the arduino, it would just keep on resetting.  Very bazaar, I thought it was because of the Tone library conflicting, but it wasn’t! I reduced the song buffer size to 55, and poof, it worked!

Using the avr-size function bundled with Arduino (pointing to the elf file that avrdude generates while compiling), I see the following sections: text = 21840, data = 254, .bss = 1079. The Ram is data + .bss, in this case about 1300. But if you have a 500 byte array, plus other variables within the same function, you have the chance of causing a buffer overflow. You can actually look at the size of the global variables as explained here.

My new general strategy: Monitor ram size with avr-size, make sure my ram usage is below the allowable level in each function I use (and for all functions I’m nested in). I bet this explains why I couldn’t get the Tones working for the controller. Awesome!

I noticed this great video showing someone racing their RC car through the house, with a streaming camera on board that let them see things in real time. Very tempting to get a similar setup for my RC cars… The $300 price tag has me hesitating.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s