Microcontrollers like the ESP32 and Arduino are constrained devices. Unlike a desktop computer with gigabytes of RAM and an unlimited power supply, these chips operate with kilobytes to megabytes of memory and are often powered by small batteries. Understanding these constraints is not optional — it is the foundation of reliable embedded software.
Two resources are almost always in short supply:
Memory — The ESP32 has around 520 KB of internal SRAM. A classic Arduino Uno has just 2 KB. Run out of RAM at runtime and your program crashes silently or behaves unpredictably. Overflow the stack and you corrupt other data. These bugs are notoriously hard to reproduce and diagnose.
Power — A sensor node running off two AA batteries at full speed will drain them in hours. The same node, spending 99% of its time in deep sleep and waking only to take a reading, can last years. Power management is what turns a prototype into a deployable product.
This book covers two widely used platforms:
The classic Arduino boards (Uno, Nano, Mega) use Atmel/Microchip AVR microcontrollers (ATmega328P, ATmega2560, etc.). These are 8-bit RISC processors with Harvard architecture — separate address spaces for program memory (Flash) and data memory (SRAM). They are simple, well-documented, and have a huge community. Their constraints are severe: 2–8 KB SRAM, 32–256 KB Flash.
The ESP32 (Espressif Systems) is a much more capable chip: a dual-core 32-bit Xtensa LX6 processor running up to 240 MHz, with 520 KB internal SRAM, up to 4 MB (or more) of external PSRAM, and 4–16 MB of external SPI Flash. It includes WiFi and Bluetooth, making it the dominant choice for IoT applications. Its power management hardware is sophisticated, with multiple sleep modes that can reduce consumption from ~240 mA (WiFi active) to under 10 µA (deep sleep, ULP co-processor off).
| Topic | Arduino (AVR) | ESP32 |
|---|---|---|
| RAM types | SRAM | Internal SRAM, IRAM, DRAM, external PSRAM |
| ROM/Flash | Flash, EEPROM | SPI Flash, partitions, NVS |
| Storage APIs | PROGMEM, EEPROM.h | Preferences, SPIFFS, LittleFS |
| Sleep modes | Idle, ADC noise reduction, Power-down, Power-save, Standby | Active, Modem sleep, Light sleep, Deep sleep |
| Wake sources | Watchdog, external interrupt, TWI address match | Timer, GPIO, touch, ULP, ext0/ext1 |
avr-objdump or arm-none-eabi-size for inspecting binary sizesAll Arduino code is written as .ino sketches (C++ with Arduino framework). All ESP32 code uses the Arduino-ESP32 framework unless otherwise noted. Code snippets in the text are kept under 20 lines; full working examples are provided as separate .ino files in the examples/ subdirectory.
| Next: Memory Architecture | Home |