Checking the Free RAM

Modified on Fri, 30 Dec 2022 at 04:16 PM

The bigger your code is, the more SRAM it uses. The thing is your Arduino only has a small amount of this memory. And when you run out of it, your code simply stops working correctly, and you encounter bugs that are usually hard to interpret. So, it is important to keep an eye on your SRAM, and particularly the amount of remaining SRAM, called Free RAM.


This example shows you how to use the SRAM Panel and the Chart to easily monitor the Free RAM of your Arduino projects.


Refer to section Solving bugs related to Arduino SRAM to learn what to do when you are running out of Free RAM.


Sketch

Upload this sketch : 3_Debugging \ 2_FreeRAM


SRAM measurement is automatically performed by function HC_communicate().


Our library supplies 3 different probes that can be put anywhere in your program to perform SRAM measurement. Probe 0 is used by HC_communicate().


#include <HITIComm.h>

void setup()
{
    // initialize library
    HC_begin();
}

void loop()
{
    // measure SRAM on Probe 0
    HC_communicate();
}



SRAM Panel

1) Open the SRAM Panel (CTRL+M or Tools\SRAM).



2) On the right side of the panel, the size of the Free RAM measured by probe 0 is displayed. For an Arduino UNO, we have 1293 bytes.


 

3) On the left side, the panel offers a visual overview of the SRAM content. It shows the different memory sections and their respective sizes based on the feedback from one of the probes. Here, Probe 0 is selected. Uncheck “True Scale” to better see the different memory sections. For an Arduino UNO, the Total memory size is 2048 bytes.


 

  


Chart

1) Open the Chart window (CTRL+T or Tools\Chart). The Chart is configured here to read the Free RAM values from Probe 0 every 10ms.



2) Start data acquisition.

3) Wait for few seconds then stop data acquisition. See how the Free RAM size measured by Probe 0 is stable at 1293 bytes.


 

 

 

 


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article