GOAT logo

Join the conversation! The forum activity is now at GOATeach.org!  We are working to cross pollinate our conversations. Document and share tools at farm hack and talk at GOAT!  Also join GOAT riot and introduce yourself and your projects!

Pushing Arduino Memory

Topic Type: 

Just thought I'd give you guys a little update on my progress since we're coming up on the field testing the weekend after this! The following discussion may not be of interest to everyone, but for the curious, here it goes (for the hurried, see end of post). Last week I was working on two different Arduino sketches that would be the brain of Fido - one was the loop that would take measurements, log data, and send updates and one was the one that would manage text messages. When they were both working great I merged the two programs only to realize that I was out of program memory! What exactly is program memory? Here's a breakdown of what is available on an AVR ATMega328P, the processor on the Arduino

  1. RAM - Program read-write (2k)
  2. EEPROM - Program read-write (1k)
  3. PROGMEM - Program read-only (32k)

In case this is all jibberish to you, here's an easy way to think about it: EEPROM and PROGMEM are both like your computer's hard drive - you can save things there and access them later. You write the Arduino sketches to the PROGMEM and this is what it runs when it turns on. EEPROM is a little piece of memory for the PROGMEM to save stuff to - it's where I'm having Fido save user preferences that can be reprogrammed via text message without plugging Fido back into your computer. Finally, RAM is the "active memory" just like the RAM in your computer, it goes away when the device is turned off.

So last week when I merged the files, I ran out of PROGMEM. I was somewhat expecting this and I knew exactly that I had to do: cut out the Strings and replace them with chars (while Strings are very easy to work with, they are quite greedy with space). This cut my program down from 33k to about 26k which was great, but today I ran into a new problem: I ran out of RAM! My program was using too many variables and I was getting some crazy bugs; luckily, I found a very helpful blogpost that gave me a lot of ideas on how to remedy the situation. For one, I realized that character arrays written into print statements (eg: Serial.println("Hello, world")) take up RAM as well as PROGMEM, so I will spend some time modifying the code so that it puts some of those only in PROGMEM. Overall, these problems have been very interesting for me because until now I'd never actually filled up the AVR chip's memory!

To make a long story short, I'm currently optimizing the program so that it will actually fit on the Arduino - it's cool to be pushing this device to it's limits but it means adding anything other than basic sensors will be a challenging. Nonetheless, we should have a Fido that is reprogrammable by text message, implements user permissions, and does all the data logging, update, and summary sending you could ask for. Not bad for a four dollar processor!

estoffer's picture

I don't have much to add since my Arduino has not even arrived yet, but sounds like we are pushing it to the limit which is pretty exciting.