Go Down

Topic: memory usage? problem with Sketch over 8200 bytes (Read 5012 times) previous topic - next topic


Code: [Select]
#include <avr/pgmspace.h>
#define fp(string) flashprint(PSTR(string))
* flashprint
* print a text string direct from flash memory to Serial
void flashprint (const char p[])
    byte c;
    while (0 != (c = pgm_read_byte(p++))) {


   fp("\nThis is a debug message in flash");


Mar 25, 2011, 03:40 am Last Edit: Mar 25, 2011, 03:42 am by WillR Reason: 1
Amount of free memory..

Try this.. I have some simple instructions in the program.

Put the function at the end of your code.

Call it from the end of setup.

Probably the best place for the extern variables is near the top of the sketch.  You'll figure it out...

Put the two extern variables near the top of your program -- call the memory free routine from the end of setup for example...

Code: [Select]
 Free Memory detection
From Arduino Cookbook
Modified by WillR March 22, 2011
Did I improve it or change it?
Good Question!


// external variables from build process

//String mystring[] = "testing";

void setup() {


} //end setup

void  loop()
 Serial.print("Free Memory:  ");
 Serial.println("  ");  

} //end loop

extern unsigned long __bss_end; // put this at top of your sketch
extern void *__brkval;   // put this at top of your sketch        

int memoryFree()     // In YOUR Program -- call this from the end of setup and wherever else you wish
 //  long myValue;
 int freeValue;
 freeValue = 0;

 if ((unsigned long)__brkval == 0)
   freeValue = ((unsigned long)&freeValue) - ((unsigned long)&__bss_end);
   freeValue = ((unsigned long)&freeValue) - ((unsigned long)__brkval);

 return freeValue;

}//end memoryFree()

Cheers!  ]:D

Hope that helps!

Go Up