Go Down

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

westfw

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++))) {
Serial.write(c);
    }
}

  :

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

WillR

#16
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() {

 Serial.begin(9600);

} //end setup

void  loop()
{
 Serial.print("Free Memory:  ");
 Serial.print(memoryFree());
 Serial.println("  ");  
 delay(1000);

} //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);
 }
 else
 {
   freeValue = ((unsigned long)&freeValue) - ((unsigned long)__brkval);
 }

 return freeValue;

}//end memoryFree()




Cheers!  ]:D

Hope that helps!
Just another Hacker

Go Up