Learn how ESP32 with Arduino combines Arduino’s simplicity with ESP32’s dual-core power, WiFi, and Bluetooth. Complete technical guide covering architecture, programming differences, and real-world applications for makers and engineers. For more information on ESP32 visit the following blogs as well

Esp32 with arduino

Understanding the ESP32 Architecture

Core Processor Details

  • CPU: Dual-core Xtensa LX6 32-bit processors
    • Core 0: Handles WiFi/Bluetooth protocols (Protocol CPU)
    • Core 1: Available for user applications (Application CPU)
    • Clock Speed: 80MHz to 240MHz (configurable)
    • Instruction Set: Xtensa ISA (not ARM like many assume)

Memory Architecture

ESP32 Memory Layout:
├── Internal SRAM: 520KB total
│   ├── SRAM0: 192KB (0x3FFE0000 - 0x4000FFFF)
│   ├── SRAM1: 128KB (0x3F800000 - 0x3F81FFFF)
│   └── SRAM2: 200KB (0x3F820000 - 0x3F84FFFF)
├── External PSRAM: Up to 8MB (optional)
├── Flash Memory: 4MB-16MB (program storage)
└── RTC Fast Memory: 8KB (low-power operations)

Built-in Peripherals

  • WiFi: 802.11 b/g/n (2.4GHz)
  • Bluetooth: Classic + BLE 4.2
  • GPIO: 36 pins (but not all available on dev boards)
  • ADC: 2x 12-bit SAR ADCs (18 channels total)
  • DAC: 2x 8-bit DACs
  • PWM: 16 channels
  • UART: 3 hardware serial ports
  • SPI: 4 SPI interfaces
  • I2C: 2 I2C interfaces
  • I2S: Digital audio interface
  • CAN: Controller Area Network
  • Touch Sensors: 10 capacitive touch pins
  • Hall Effect Sensor: Built-in magnetic field sensor
  • Temperature Sensor: Internal temperature monitoring

Arduino Framework on ESP32: How It Actually Works

The ESP-IDF vs Arduino Core Relationship

Your Arduino Code
       ↓
Arduino-ESP32 Core (Abstraction Layer)
       ↓
ESP-IDF (Espressif IoT Development Framework)
       ↓
FreeRTOS (Real-Time Operating System)
       ↓
ESP32 Hardware

What Arduino-ESP32 Core Provides

The Arduino-ESP32 core is essentially a wrapper around Espressif’s native ESP-IDF framework:

  1. Familiar Arduino Functions: digitalWrite() → gpio_set_level() analogRead() → adc1_get_raw() Serial.begin() → uart_driver_install() delay() → vTaskDelay()
  2. Automatic Resource Management:
    • Handles FreeRTOS task creation
    • Manages WiFi stack initialization
    • Abstracts memory allocation
    • Simplifies interrupt handling

Under the Hood: What Happens When You Run Arduino Code

When you upload Arduino code to ESP32:

  1. Compilation Process: Arduino IDE → ESP32 Arduino Core → ESP-IDF toolchain → Binary
  2. Boot Sequence: 1. First-stage bootloader (ROM) 2. Second-stage bootloader (partition table) 3. Arduino setup() function 4. Arduino loop() function (wrapped in FreeRTOS task)
  3. Task Management:
    • Your loop() runs as a FreeRTOS task on Core 1
    • WiFi/Bluetooth stack runs on Core 0
    • Watchdog timer prevents infinite loops

Technical Comparison Arduino Uno vs ESP32

Detailed Specifications Table

FeatureArduino UnoESP32-WROOM-32
ProcessorATmega328P (8-bit)Xtensa LX6 (32-bit dual-core)
Clock Speed16 MHz240 MHz (15x faster)
Flash Memory32 KB4 MB (125x more)
SRAM2 KB520 KB (260x more)
EEPROM1 KBEmulated in Flash
Digital I/O14 pins36 pins
Analog Input6 pins (10-bit)18 pins (12-bit)
PWM6 pins16 channels
UART1 hardware3 hardware
SPI14
I2C12
ConnectivityNoneWiFi + Bluetooth
Operating Voltage5V3.3V
Power Consumption~45mA active~160mA active, <10µA deep sleep
Price~$25~$5-10

Performance Benchmarks

// Simple loop benchmark (1 million iterations)
Arduino Uno: ~4 seconds
ESP32: ~0.02 seconds (200x faster)

// Mathematical operations (floating point)
Arduino Uno: Software emulation (very slow)
ESP32: Hardware floating point unit (fast)

Programming Differences and Similarities

What Stays the Same (Arduino Compatibility)

// Basic Arduino functions work identically
void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
}

What’s Different (ESP32 Specific)

  1. Pin Numbering: // Arduino Uno pinMode(13, OUTPUT); // Physical pin 13 // ESP32 (depends on board) pinMode(2, OUTPUT); // GPIO2 (built-in LED on most boards)
  2. Voltage Levels: // Arduino Uno: 5V logic // ESP32: 3.3V logic (5V tolerant on most pins)
  3. Serial Baud Rates: // Arduino Uno typically: 9600 Serial.begin(9600); // ESP32 typically: 115200 (much faster) Serial.begin(115200);

ESP32-Specific Arduino Functions

  1. WiFi Capabilities: #include <WiFi.h> WiFi.begin("SSID", "password"); WiFi.localIP(); // Get IP address
  2. Bluetooth Functions: #include <BluetoothSerial.h> BluetoothSerial SerialBT; SerialBT.begin("ESP32test");
  3. Dual-Core Programming: void setup() { xTaskCreatePinnedToCore(Task1, "Task1", 10000, NULL, 1, NULL, 0); xTaskCreatePinnedToCore(Task2, "Task2", 10000, NULL, 1, NULL, 1); }

5. Advanced ESP32 Features in Arduino Environment

Touch Sensors

void setup() {
  Serial.begin(115200);
}

void loop() {
  int touchValue = touchRead(T0);  // GPIO4
  Serial.println(touchValue);
  delay(500);
}

Hall Effect Sensor

void setup() {
  Serial.begin(115200);
}

void loop() {
  int hallValue = hallRead();
  Serial.println(hallValue);
  delay(500);
}

Analog Output (DAC)

void setup() {
  // DAC pins: GPIO25, GPIO26
}

void loop() {
  for(int i = 0; i < 256; i++) {
    dacWrite(25, i);  // Output 0-3.3V
    delay(10);
  }
}

Deep Sleep Mode

void setup() {
  Serial.begin(115200);
  esp_sleep_enable_timer_wakeup(10 * 1000000);  // 10 seconds
  esp_deep_sleep_start();
}

6. Memory Management Differences of Esp32 and Arduino

Arduino Uno Memory

// Very limited memory management
String str = "Hello";  // Uses precious SRAM

ESP32 Memory

// Much more flexible memory options
String str = "Hello";           // Uses SRAM
char* heap_str = (char*)malloc(100);  // Dynamic allocation
// PROGMEM not needed (flash access is fast)

ESP32 Memory Allocation

// Check available memory
size_t freeHeap = ESP.getFreeHeap();
size_t heapSize = ESP.getHeapSize();
size_t psramSize = ESP.getPsramSize();  // If PSRAM available

7. Real-World Performance Examples for Esp32 with arduino

Web Server Performance

// Arduino Uno: Cannot run web server natively
// ESP32: Can handle multiple simultaneous connections

#include <WiFi.h>
#include <WebServer.h>

WebServer server(80);

void handleRoot() {
  server.send(200, "text/html", "<h1>ESP32 Web Server</h1>");
}

void setup() {
  WiFi.begin("SSID", "password");
  server.on("/", handleRoot);
  server.begin();
}

void loop() {
  server.handleClient();  // Non-blocking
}

Sensor Data Processing

// Arduino Uno: Limited processing capability
// ESP32: Can perform complex calculations in real-time

void loop() {
  float sensor1 = analogRead(A0) * 3.3 / 4095.0;
  float sensor2 = analogRead(A1) * 3.3 / 4095.0;
  
  // Complex calculations possible
  float result = sqrt(pow(sensor1, 2) + pow(sensor2, 2));
  
  // Send data over WiFi
  WiFiClient client;
  client.print("Result: " + String(result));
}

8. Development Environment Setup

Arduino IDE Configuration

  1. Install ESP32 Board Package:
    • File → Preferences
    • Additional Board Manager URLs: https://dl.espressif.com/dl/package_esp32_index.json
    • Tools → Board → Boards Manager → Search “ESP32” → Install
  2. Board Selection: Tools → Board → ESP32 Arduino → ESP32 Dev Module Tools → Upload Speed → 921600 Tools → CPU Frequency → 240MHz Tools → Partition Scheme → Default 4MB

Alternative IDEs

  • PlatformIO: Professional development environment
  • ESP-IDF: Native Espressif framework
  • Arduino IDE 2.0: Modern Arduino development

9. Common Issues and Solutions with esp32 and arduino

Pin Compatibility Issues

// Some pins have restrictions
GPIO 6-11: Connected to flash (don't use)
GPIO 0, 2: Boot pins (be careful with pullups)
GPIO 34-39: Input only pins

Power Supply Requirements

// ESP32 needs more current than Arduino
Arduino Uno: ~45mA
ESP32: ~160mA (WiFi active), up to 500mA peak

Voltage Level Issues

// ESP32 is 3.3V, but most pins are 5V tolerant
// However, analog pins are NOT 5V tolerant

10. What to Choose

Choose ESP32 When You Need:

  • WiFi or Bluetooth connectivity
  • More processing power
  • More memory for complex algorithms
  • Multiple serial communications
  • Touch interfaces
  • Audio processing (I2S)
  • Real-time applications
  • Cost-effective solution

Stick with Arduino When:

  • Simple, basic projects
  • 5V logic requirement
  • Very low power consumption needed
  • Learning electronics basics
  • Maximum stability required
  • Shield compatibility important

Conclusion

ESP32 with Arduino represents the evolution of maker-friendly microcontroller programming. It maintains the simplicity and familiarity of Arduino while providing professional-grade capabilities like WiFi, Bluetooth, dual-core processing, and extensive peripheral support.

The Arduino framework on ESP32 is not just a simple port—it’s a sophisticated abstraction layer that makes complex embedded systems programming accessible to makers while still allowing access to advanced features when needed.

This combination has democratized IoT development, making it possible for Arduino users to create professional-quality connected devices without abandoning the familiar Arduino programming model they know and love.

Spread knowledge

Leave a Comment

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