$USD
  • EUR€
  • £GBP
  • $USD
TUTORIALS ESP32

ESP32 Arduino Tutorial: Getting the Free Heap

DFRobot Dec 27 2017 1476

The objective of this ESP32 Arduino Tutorial is to explain how to obtain and print the ESP32 free heap, using the Arduino core. The tests of this ESP32 tutorial were performed using a DFRobot’s ESP-WROOM-32 device integrated in a ESP32 development board.

Introduction

The objective of this ESP32 Arduino Tutorial is to explain how to obtain and print the ESP32 free heap memory, using the Arduino core.

The tests of this ESP32 tutorial were performed using a DFRobot’s ESP-WROOM-32 device integrated in a ESP32 FireBeetle board.

The code

The code for this will be very simple, since we already have defined in the EspClass a method for obtaining the free heap value. Note that the methods of this class are exposed in an extern variable called ESP.

So, in the Arduino setup function, we starting by opening a serial connection, so we can output the value of the free heap.

Serial.begin(115200);

Next, to obtain the free heap, we simply call the getFreeHeap method of the ESP extern variable.

This method takes no arguments and returns as output the free heap, in bytes. Note that in its implementation, the getFreeHeap method calls the esp_get_free_heap_size function of the IDF framework, which is defined in this header file.

Serial.println(ESP.getFreeHeap());

You can check the full source code below. Note that we left the main loop function empty since we don’t need to use it for this tutorial.

void setup() {
  Serial.begin(115200);
  Serial.println(ESP.getFreeHeap());
}
 
void loop() {}

Testing the code

To test, simply open the Arduino IDE serial monitor after compiling and uploading the code to your ESP32 device. You should get an output similar to figure 1, which shows the available heap space on the device.


Figure 1 – Output of the program.


DFRobot supply lots of esp32 arduino tutorials and esp32 projects for makers to learn.


REVIEW