Can anybody tell me how to measure the consumed RAM for a particular code running on Arduino Mega or Due.
3 Answers
There is two kinds of numbers to this question: Global static usage and current run time.
The static estimated usage can be determined by adding the following line to (if it does not already exist)
.\arduino-1.5.5\hardware\arduino\avr\boards.txt
uno.upload.maximum_ram_size=2048
This then allows the compiler to output the additional 2nd line in the following example in the IDE's result window
Binary sketch size: 25,880 bytes (of a 32,256 byte maximum)
Estimated used SRAM memory: 990 bytes (of a 2048 byte maximum)
To see the amount of memory used at any given point. Including memory space currently in use, that exists while only in functions and members. This includes the HEAP and such. I use the following MemoryFree library at specific points in the code to reveal the high-water. The readme explains how to save unnecessarily/unintentionally used RAM by prints.
Note: That while the original Arduino IDE 1.0.5's boards.txt files does contain these ram_sizes, it does not actually use display usage. Where the original Arduino IDE 1.5.5 does, along with Arduino ERW 1.0.5 does (an non-supported fork).

- 2,807
- 2
- 15
- 19
-
uno.upload.maximum_ram_size=2048 - Will this work for arduino mega 2560 and arduino due as well? I am using arduino ide 1.5.2. Will it work there? – Sampi Aug 06 '13 at 17:04
-
For mega2560.upload.maximum_ram_size=8192 Not sure but would expect it to work for Due... 98304 – mpflaga Aug 06 '13 at 23:41
-
I suddenly ponder that maximum_ram_size in the boards.txt, may only be a feature of "Arduino ERW"s IDE. and not in the stock IDE's. – mpflaga Aug 06 '13 at 23:52
-
Will this work in any version of the IDE ? I am using version 1.5.2 – Sampi Aug 08 '13 at 12:12
-
2Will this work in any version of the IDE ? I used 1.0.5 and edited the boards.txt file with the line mega2560.upload.maximum_ram_size=8192. But nothing happened. – Sampi Aug 08 '13 at 12:39
In my Arduino IDE 2.1.0
I edit the file: /usr/share/arduino/hardware/arduino/boards.txt
but the second line don't appear
After read: check-ram-memory-usage-arduino-optimization
I tried:
Show vervose output during compilation
and use avr-size /tmp/build4042914391435450796.tmp/XXXXXXX.cpp.elf
then i get my memory used
Best Regards!

- 1
- 1

- 809
- 1
- 19
- 25
int freeRam () {
extern int __heap_start, *__brkval;
int v;
int fr = (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
Serial.print("Free ram: ");
Serial.println(fr);
}

- 53
- 3