Created
February 28, 2025 00:04
-
-
Save scottyob/33991f2381b088f9421ecab43d2643ce to your computer and use it in GitHub Desktop.
basic-demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include "esp_heap_caps.h" | |
#include "esp_system.h" | |
void printMemoryStats() { | |
Serial.println("=== Memory Stats ==="); | |
// Heap memory info | |
Serial.printf("Free Heap: %u bytes\n", esp_get_free_heap_size()); | |
Serial.printf("Largest Free Block: %u bytes\n", heap_caps_get_largest_free_block(MALLOC_CAP_8BIT)); | |
Serial.printf("Minimum Free Heap Ever: %u bytes\n", esp_get_minimum_free_heap_size()); | |
// Stack high water mark for the current task | |
Serial.printf("Main Task Stack High Water Mark: %u bytes\n", uxTaskGetStackHighWaterMark(NULL)); | |
// PSRAM stats (if available) | |
#if CONFIG_SPIRAM_USE_MALLOC | |
Serial.printf("Free PSRAM: %u bytes\n", heap_caps_get_free_size(MALLOC_CAP_SPIRAM)); | |
Serial.printf("Largest Free PSRAM Block: %u bytes\n", heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM)); | |
#else | |
Serial.println("PSRAM not available."); | |
#endif | |
Serial.println("====================\n"); | |
} | |
void setup() { | |
Serial.begin(115200); | |
delay(1000); // Allow time for serial monitor to start | |
} | |
void loop() { | |
printMemoryStats(); | |
delay(1000); // Print every second | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment