Pages: 1 [2]   Go Down
Author Topic: memory usage? problem with Sketch over 8200 bytes  (Read 2309 times)
0 Members and 1 Guest are viewing this topic.
SF Bay Area (USA)
Offline Offline
Tesla Member
Karma: 137
Posts: 6792
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#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");

Georgina Ontario
Offline Offline
Sr. Member
Karma: 5
Posts: 437
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...

  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!  smiley-twist

Hope that helps!
« Last Edit: March 24, 2011, 09:42:51 pm by WillR » Logged

Just another Hacker

Pages: 1 [2]   Go Up
Jump to: