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 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.
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.
Follow this step-by-step tutorial to connect the FireBeetle 2 ESP32-C5 to Home Assistant using MQTT. Learn to configure the Mosquitto broker, flash your board with Arduino, and display sensor data for your smart home automation projects.
Explore the new FireBeetle 2 ESP32-C5, a powerful IoT development board featuring dual-band 2.4/5GHz Wi-Fi 6, multi-protocol support (BLE, Zigbee, Thread), and integrated solar charging. See how it outperforms the ESP32-C6 for advanced, low-power projects.
DFRobot showcases its revolutionary Unihiker K10 AIoT board at FAB25 Czechia with interactive workshops, free device trials, and exclusive maker gifts for attendees.