Checking your free RAM

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 memory, and particularly on your Free RAM.

Refer to section Identifying SRAM shortage to learn what to do when you are running out of it.

This example shows you how to monitor your Free RAM in no time.


1) Sketch: 3_Debugging \ 2_FreeRAM

SRAM measurement is automatically performed by function HC_communicate(). It is the first thing this function does. So, there is no additional code required.

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>

// run once at power on
void setup()
    // initialize library

// run repeatedly after setup() 
void loop()
    // measure SRAM on Probe 0


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


3) Chart

  1. Open the Chart window (CTRL+T or Tools\Chart). The Chart is configured 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 stabilized at 1293 bytes.


Was this article helpful?
0 out of 0 found this helpful