Lost Memory…

I’ve been programming for most of my life. Very very rarely have I had issues with memory or lack of memory.

Now that I’m hot an heavy into microcontroller programming I’ve stumbled across an issue that has apparently been causing me issues without me know it it.

Lack of memory!

The ATmega328 series chip that is the brain of the typical Arduino board has 3 memory locations.

  • The Flash is typically 32k bytes. This is what the Arduino IDE tells you about when you compile/upload your code.
  • The SRAM is something no one told me about…this is the actual operating program memory space (RAM). This is where your app runs and lives. Your variables live here. When this space is used up things get wonky. The Arduino crashes or worse does strange unexplainable things.
  • The EEPROM is generally not used by the average programmer so I won’t cover it here.

JeeLabs has a killer write up on the SRAM and…wait for it….how to see how much is used!

I added their little function to output RAM usage and holy cow. I had it all used up!

So I had to learn about memory management. Lesson one- strings use up a lot of space!

JeeLabs also has a killer write up on how to optimize your string usage. READ IT! The Arduino site also has a write up on how to use the Flash memory for storing static variables too.

After all this learning I finally got my code “optimized”. I thought my latest project was a gonner but putting variables in Flash, dumping A LOT of debug code made a huge difference. I went from zero bytes of RAM and crashes to about 646 bytes free.  Doesn’t sound like much but when you only have 2048 bytes to start with, that’s pretty good!

Now to figure out how to have my debug code and still keep the memory usage low!

 

LCC v5 is almost ready

Lots of code changes and some hardware. Here’s some of them:

  • Added ShiftBright RGB LED to pins D2, D12 and D13
  • Added code for ShiftBright
  • Updated DEBUG routines
  • Day overhead handling is updated to wait longer before turning off
  • Added yellow and red LED indications for day overhead conditions
  • Night cold conditions are mirrors of day as appropriate
  • Switch 1 is now only for UV lights
  • Switch 2 is only for heat- in my case the heat rock is on all the time and the heat lamp is switched
  • Cleaned some functions of unneeded statements

Version 5 should be released soon. It’s still not running live yet. If you want an advance copy let me know.