Techniques for reducing memory needed

Hi - I'm at a 'post-beginner', 'pre-intermediate' Wiring/C++ programming level. I've created custom libs, etc. and generally can get stuff done (tho' often with help.. ).

Anyway - with a recent project with some custom classes for controlling LEDs on an atmega168 I ran into what had to be memory issues: if I added Serial.print statements, the program would stop working. The sketch itself only took up @ 1/3 of available storage space.

To save ram I made sure that I: --used bytes/chars instead of ints where possible --used bitshifting instead of arrays where possible

I looked into PROGMEM but there wasn't much that was static so ended up not using it.

Are there other relatively easy things to do? If not, what would be a next step? Is it possible to store functions in PROGMEM? (and/or is that worth the effort).

Library (class) instances seem to take up lots of memory but the alternative is more confusing/tedious/harder programming (e.g. having to have loads of global variables).

tx for any tips!

if I added Serial.print statements, the program would stop working. ... I looked into PROGMEM but there wasn't much that was static so ended up not using it.

The prints are exactly where you should be using the PROGMEM

if I added Serial.print statements, the program would stop working

Serial.print( "This string consumes both Flash memory AND SRAM. You can easily eliminate the SRAM consumption by using Mikal Hart's Flash library (see below) or one of the plethora of print-from-PROGMEM functions available on the forum." );

http://arduiniana.org/libraries/flash/

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1193587488/12#12

Don't forget EEPROM... 512 bytes on the ATMEGA168, 1k on the ATMEGA328, and more on the other versions. EEPROM lib is even a core library, no mucking about.

The EEPROM has a limit on write cycles, supposedly, but I really doubt you (or any of us) will ever need to rewrite the ROM tens of thousands of times.. and if by some means we do, a fresh ATMEGA328 with the bootloader already burned can be had off eBay for about five bucks. The chip is socketed on the Arduino, so you could just toss the 328 with the spent ROM and start all over fresh for the price of a cup of Starbucks cappucino.

Thanks for the replies. From my reading of the docs. PROGMEM can not be written to when the program is running - it is read only. Did I get that wrong?

I can see the value of off loading static stuff like lookup tables or static string data but I tend not to have much of that.

Also, I do not see how Serial.print of dynamic vars (e.g. when debugging) is helped by PROGMEM. Again, perhaps I misunderstood the docs.

Thanks for the replies. From my reading of the docs. PROGMEM can not be written to when the program is running - it is read only. Did I get that wrong?

You are correct. (Essentially) read-only.

Also, I do not see how Serial.print of dynamic vars (e.g. when debugging) is helped by PROGMEM

It's not.

I can see the value of off loading static stuff like lookup tables or static string data but I tend not to have much of that.

This is the time for you to provide more details about your Sketch...