Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home IoT & Smart Home

ESP32 PSRAM: Use External RAM for Larger Buffers and Images

ESP32 PSRAM: Use External RAM for Larger Buffers and Images

March 11, 2026 /Posted byJayesh Jain / 0

If you have been building IoT projects with the ESP32, you have probably hit the memory wall sooner or later. The standard ESP32 PSRAM external RAM capability is one of the most powerful yet underused features of the ESP32 platform. With only 520 KB of internal SRAM on most variants, tasks like displaying JPEG images, running audio buffers, or handling large JSON payloads quickly exhaust available memory. This guide will walk you through everything you need to know about enabling and using PSRAM on your ESP32 board.

Table of Contents

  1. What Is PSRAM and Why Does the ESP32 Need It?
  2. ESP32 Variants with PSRAM
  3. Enabling PSRAM in Arduino IDE and PlatformIO
  4. Allocating Memory from PSRAM in Code
  5. Real-World Use Case: JPEG Image Decoding
  6. PSRAM Limitations and Performance Tips
  7. Frequently Asked Questions

What Is PSRAM and Why Does the ESP32 Need It?

PSRAM stands for Pseudo-Static RAM. It is a type of external flash RAM chip that is connected to the ESP32 via the SPI bus (usually QSPI for higher speed). Unlike the internal SRAM which is tightly integrated with the CPU, PSRAM is an additional chip soldered on the module that provides several additional megabytes of RAM.

The standard ESP32 has 520 KB of internal SRAM split across instruction RAM (IRAM), data RAM (DRAM), and a small RTC memory. For simple sensor reading, LED blinking, or MQTT messaging, this is perfectly adequate. But the moment you want to:

  • Decode and display a JPEG or PNG image on a TFT screen
  • Stream and buffer audio data
  • Store large JSON responses from REST APIs
  • Use LVGL (Light and Versatile Graphics Library) with multiple widgets
  • Run camera capture with frame buffering

…you will immediately run into heap allocation failures. This is where PSRAM comes in. With an ESP32 module that includes 4 MB or 8 MB of PSRAM, your heap is dramatically expanded, unlocking a whole new class of applications.

In India, projects involving weather dashboards, camera-based attendance systems, and voice-controlled smart home hubs are increasingly popular among engineering students and hobbyists. All of these benefit enormously from PSRAM-enabled boards.

ESP32 Variants with PSRAM

Not all ESP32 modules include PSRAM. Here is a breakdown of the most common variants you will find in the Indian market:

Module Internal SRAM PSRAM Notes
ESP32-WROOM-32 520 KB None Most common, no PSRAM
ESP32-WROVER 520 KB 8 MB PSRAM via SPI, classic choice
ESP32-S3 (N8R8) 512 KB 8 MB OPI Octal SPI, very fast PSRAM
ESP32-CAM (AI-Thinker) 520 KB 4 MB Essential for camera frame buffers
ESP32-S2 320 KB Optional 2MB USB-OTG capable

The ESP32-CAM is one of the most popular PSRAM-equipped boards in India, used extensively for camera streaming and image capture projects. It uses the OV2640 camera sensor and relies heavily on PSRAM for storing camera frame buffers.

Ai Thinker ESP32 CAM Development Board

Ai Thinker ESP32 CAM Development Board WiFi+Bluetooth with AF2569 Camera Module

This ESP32-CAM board includes 4 MB of PSRAM, making it ideal for JPEG image capture and streaming. The PSRAM is essential for holding camera frame buffers during image processing.

View on Zbotic

Enabling PSRAM in Arduino IDE and PlatformIO

Before you can use PSRAM, you need to explicitly enable it in your build environment. This is a step many beginners miss, leading to frustrating allocation failures even on PSRAM-equipped boards.

Arduino IDE Method

In Arduino IDE 2.x, once you have selected an ESP32 board from the Espressif ESP32 package:

  1. Go to Tools in the menu bar
  2. Look for PSRAM option (visible only for boards that support it)
  3. Select Enabled or OPI PSRAM (for ESP32-S3 with OPI interface)

For standard WROVER boards or ESP32-CAM, select Enabled. For ESP32-S3 boards with Octal SPI PSRAM (8R2, 8R8 variants), select OPI PSRAM.

PlatformIO Method

In your platformio.ini, add the following build flags:

[env:esp32cam]
platform = espressif32
board = esp32cam
framework = arduino
build_flags =
    -DBOARD_HAS_PSRAM
    -mfix-esp32-psram-cache-issue
board_build.arduino.memory_type = qio_qspi

For ESP32-S3 with OPI PSRAM, use:

build_flags =
    -DBOARD_HAS_PSRAM
board_build.arduino.memory_type = qio_opi

Verifying PSRAM is Available

Add this to your setup() to confirm PSRAM is detected:

void setup() {
  Serial.begin(115200);
  if (psramFound()) {
    Serial.printf("PSRAM found: %u bytesn", ESP.getPsramSize());
    Serial.printf("Free PSRAM: %u bytesn", ESP.getFreePsram());
  } else {
    Serial.println("No PSRAM detected!");
  }
}

Allocating Memory from PSRAM in Code

Once PSRAM is enabled, the ESP32 framework provides several ways to allocate from it. The key insight is that regular malloc() and new() will NOT automatically use PSRAM — you must use special allocation functions.

ps_malloc() — The Primary Method

#include <esp_heap_caps.h>

void setup() {
  Serial.begin(115200);
  
  // Allocate a 100KB buffer in PSRAM
  uint8_t* buffer = (uint8_t*) ps_malloc(100 * 1024);
  
  if (buffer == NULL) {
    Serial.println("PSRAM allocation failed!");
    return;
  }
  
  Serial.println("PSRAM allocation successful!");
  
  // Use the buffer...
  memset(buffer, 0, 100 * 1024);
  
  // Always free when done
  free(buffer);
}

heap_caps_malloc() — Fine-Grained Control

// Allocate specifically in external PSRAM
uint8_t* psram_buf = (uint8_t*) heap_caps_malloc(
    512 * 1024,           // 512 KB
    MALLOC_CAP_SPIRAM     // Capability flag for PSRAM
);

// Allocate in internal SRAM (for time-critical code)
uint8_t* fast_buf = (uint8_t*) heap_caps_malloc(
    4 * 1024,
    MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT
);

Automatic PSRAM Allocation (Arduino)

You can configure the Arduino framework to automatically allocate from PSRAM when internal heap runs low by adding this to your code:

// In platformio.ini or via build flags:
// -DCONFIG_SPIRAM_USE_MALLOC=1
// This makes malloc() prefer PSRAM when internal heap is <4KB
Waveshare ESP32-S3 AMOLED Display

Waveshare ESP32-S3 1.43inch AMOLED Display Development Board, 466×466, QSPI Interface

This ESP32-S3 board features OPI PSRAM and a stunning AMOLED display — perfect for LVGL UI projects that require large frame buffers stored in external RAM.

View on Zbotic

Real-World Use Case: JPEG Image Decoding

One of the most practical applications of ESP32 PSRAM external RAM in Indian maker projects is displaying JPEG images on TFT screens. Whether you are building a product display unit, a digital photo frame, or a weather dashboard, you need to decode JPEG data in RAM before pushing pixels to the display.

Here is a complete example using the TJpgDec library:

#include <TJpg_Decoder.h>
#include <TFT_eSPI.h>

TFT_eSPI tft = TFT_eSPI();

// JPEG decode callback — called for each decoded MCU block
bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap) {
  if (y >= tft.height()) return 0;
  tft.pushImage(x, y, w, h, bitmap);
  return 1;
}

void displayJpegFromPsram(const uint8_t* jpeg_data, size_t data_size) {
  // Allocate decode buffer in PSRAM
  uint8_t* decode_buf = (uint8_t*) ps_malloc(data_size);
  if (!decode_buf) {
    Serial.println("Failed to allocate PSRAM for JPEG!");
    return;
  }
  
  memcpy(decode_buf, jpeg_data, data_size);
  
  TJpgDec.setSwapBytes(true);
  TJpgDec.setCallback(tft_output);
  TJpgDec.drawJpg(0, 0, decode_buf, data_size);
  
  free(decode_buf);
}

Without PSRAM, a 320×240 JPEG decode buffer (~150KB) would simply fail on standard ESP32 boards. With 4 MB of PSRAM available, you can comfortably decode multiple images and even implement a slideshow.

Camera Frame Buffering

The ESP32-CAM’s entire camera capture pipeline depends on PSRAM. When you initialize the camera with framesize = FRAMESIZE_UXGA (1600×1200), each frame requires about 480KB — impossible without PSRAM. The camera driver automatically allocates frame buffers in PSRAM when available:

camera_config_t config;
config.frame_size = FRAMESIZE_UXGA;   // Needs PSRAM
config.fb_location = CAMERA_FB_IN_PSRAM; // Explicit PSRAM allocation
config.fb_count = 2;                  // Double buffer in PSRAM
ESP32 CAM WiFi Module

ESP32 CAM WiFi Module Bluetooth with OV2640 Camera Module 2MP For Face Recognition

Built-in 4MB PSRAM makes this board capable of full-resolution JPEG capture and face recognition tasks that would be impossible on standard ESP32 boards without external RAM.

View on Zbotic

PSRAM Limitations and Performance Tips

While PSRAM dramatically expands available memory, it is not without trade-offs. Understanding these limitations will help you design better firmware:

Speed Difference

PSRAM accesses are slower than internal SRAM because data must travel over the SPI/QSPI bus. Typical bandwidth:

  • Internal SRAM: ~200 MB/s (single-cycle access)
  • PSRAM via QSPI: ~40-80 MB/s (bus overhead)
  • PSRAM via OPI (ESP32-S3): ~80-120 MB/s (faster OctalSPI)

This means PSRAM is excellent for storing large buffers, images, and lookup tables, but not ideal for time-critical interrupt handlers or real-time audio mixing. Keep your interrupt code and time-sensitive variables in internal SRAM using IRAM_ATTR and DRAM_ATTR attributes.

Cache Coherency

The ESP32 has a 64KB cache that automatically caches frequently accessed PSRAM data, mitigating the speed penalty for sequential access patterns. For random access patterns (like hash table lookups), performance degrades more noticeably.

The -mfix-esp32-psram-cache-issue Flag

Older ESP32 silicon revisions (before ECO3) have a bug where PSRAM cache interactions on CPU1 can cause rare crashes. The -mfix-esp32-psram-cache-issue build flag applies a software workaround that pins certain cache operations, at the cost of a small performance penalty. For production IoT devices, always include this flag for original ESP32 (not ESP32-S3/C3 which do not have this issue).

Best Practices Summary

  • Use ps_malloc() for large buffers (>32KB) like image data, audio, JSON strings
  • Keep interrupt handlers and ISR data in internal SRAM with IRAM_ATTR
  • Use DRAM_ATTR for global variables accessed from ISR context
  • Always check for NULL after ps_malloc() — PSRAM can fragment just like regular heap
  • Monitor free PSRAM with ESP.getFreePsram() during development
  • For ESP32-S3 boards, prefer boards with N8R8 (8MB flash + 8MB OPI PSRAM)
ESP32-CAM-MB MICRO USB Download Module

ESP32-CAM-MB MICRO USB Download Module for ESP32 CAM Development Board

Pair this USB programmer board with your ESP32-CAM to easily flash PSRAM-enabled firmware without any FTDI adapter. Simplifies development of camera and image buffer projects.

View on Zbotic

Frequently Asked Questions

Q: How do I know if my ESP32 board has PSRAM?

Check the module name on the PCB. Any board with “WROVER” in the name has PSRAM. ESP32-CAM boards from AI-Thinker include 4MB PSRAM. ESP32-S3 boards with “R8” or “R2” in the part number have 8MB or 2MB PSRAM respectively. You can also check in code with psramFound() after enabling PSRAM in your build settings.

Q: Can I use malloc() normally and have it automatically use PSRAM?

Not by default. You must use ps_malloc() or heap_caps_malloc(size, MALLOC_CAP_SPIRAM). However, you can configure the framework with CONFIG_SPIRAM_USE_MALLOC to make malloc() fall back to PSRAM when internal heap is below 4KB. For most projects, explicit ps_malloc() calls are preferred for clarity.

Q: Why is my PSRAM allocation returning NULL even though I have 4MB?

PSRAM can fragment just like regular heap, especially after many alloc/free cycles. Also ensure PSRAM is enabled in your Arduino IDE Tools menu or PlatformIO config — it does not activate automatically. Restart the device and check with ESP.getFreePsram() immediately in setup() to see if PSRAM is being detected.

Q: Does using PSRAM consume more battery?

Yes, slightly. The PSRAM chip itself consumes a small amount of power even in standby (around 80-150 µA for 4MB PSRAM). During active access, current draw increases proportionally to access frequency. For deep sleep modes, you can put the PSRAM into power-down mode using esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO, ESP_PD_OPTION_OFF) in ESP-IDF (not directly available in Arduino framework).

Q: Which is better for an LVGL project — ESP32-WROVER or ESP32-S3 with PSRAM?

ESP32-S3 is significantly better for LVGL projects. It has the LCD interface peripheral (supporting parallel RGB and SPI displays at higher refresh rates), OPI PSRAM with higher bandwidth, and a faster CPU. For any new display project, choose an ESP32-S3 based board with at least 8MB OPI PSRAM.

Ready to Build PSRAM-Powered Projects?
Explore our full range of ESP32 development boards at Zbotic — India’s trusted source for quality electronics components with fast shipping across Mumbai, Delhi, Bangalore, Hyderabad and all major cities.
Tags: embedded systems, ESP32, External RAM, iot, PSRAM
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
ESP32 Low-Power Motion Detecto...
blog esp32 low power motion detector 2 year battery sensor 595432
blog wemos d32 vs doit devkit best esp32 value boards india 595434
Wemos D32 vs DOIT Devkit: Best...

Related posts

Svg%3E
Read more

IoT Home Insurance Sensor Kit: Leak, Smoke, and Motion

April 1, 2026 0
Table of Contents IoT and Home Insurance Water Leak Detection Smoke and Fire Detection Motion and Intrusion Sensing Building the... Continue reading
Svg%3E
Read more

IoT Pet Tracker: GPS Collar with Geofencing Alerts

April 1, 2026 0
Table of Contents Introduction and Overview Hardware Components Required GPS Module Integration with ESP32 Cloud Platform Setup Real-Time Tracking Dashboard... Continue reading
Svg%3E
Read more

IoT Aquaponics Controller: Fish and Plant Automation

April 1, 2026 0
Table of Contents The Water Monitoring Challenge in India Sensor Technologies for Water Building the Sensor Node Data Transmission and... Continue reading
Svg%3E
Read more

IoT Composting Monitor: Temperature and Moisture Tracking

April 1, 2026 0
Table of Contents Why Temperature Monitoring Matters Sensor Selection Guide Hardware Assembly and Wiring Firmware Development Cloud Data Logging Alert... Continue reading
Svg%3E
Read more

IoT Beehive Monitor: Weight, Temperature, and Humidity

April 1, 2026 0
Table of Contents Why Monitor Beehives Weight Measurement System Temperature and Humidity Sensing Building the Monitor Data Analysis for Bee... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now