Skip to content

In Memory Files

Phil Schatzmann edited this page Jun 11, 2025 · 1 revision

You can access the the PSRAM or HIMEM like a file

#include "esp32-psram.h"

void setup() {
  Serial.begin(115200);
  
  // Initialize PSRAM file system (or replace with HIMEM)
  if (!PSRAM.begin()) {
    Serial.println("PSRAM initialization failed!");
    return;
  }
  
  // Create and write to a file
  auto file = PSRAM.open("test.txt", FILE_WRITE);
  if (file) {
    file.println("Hello PSRAM!");
    file.println("This is a test file.");
    file.close();
    Serial.println("File written successfully");
  }
  
  // Read from the file
  file = PSRAM.open("test.txt", FILE_READ);
  if (file) {
    Serial.println("File contents:");
    while (file.available()) {
      Serial.write(file.read());
    }
    file.close();
  }
}
Clone this wiki locally