Skip to main content

Microcontrollers and the ESP32

Before wiring anything, it helps to understand what a microcontroller is, how the ESP32 fits into that category, and how programming one differs from writing software for a computer.


What Is a Microcontroller?

A microcontroller is a small, self-contained computer on a single chip. It has a processor, RAM, flash storage, and a set of hardware peripherals (timers, communication buses, analog-to-digital converters) — all integrated into one package.

How it differs from a desktop computer

Desktop / LaptopMicrocontroller
ProcessorMulti-GHz, multi-core, out-of-order execution~240 MHz, 1–2 cores, in-order
RAM8–64 GB512 KB – 8 MB
StorageSSD, hundreds of GBFlash, 4–16 MB
Operating systemLinux, macOS, WindowsNone, or a real-time OS (RTOS)
I/OUSB, HDMI, Ethernet — through complex controller chipsGPIO pins — direct electrical connections to the outside world
Power15–300 W0.01–1 W
Cost$500–3000$2–15

A microcontroller does not run an operating system in the traditional sense. When it boots, it starts executing your code immediately — there is no kernel, no filesystem layer, no process scheduler (unless you add one). This is both simpler and more demanding: you have complete control, but you are responsible for everything.

The software analogy

Think of a microcontroller as a bare-metal server with no OS. You write a single program that starts at main(), runs in an infinite loop, and directly controls the hardware. There are no other processes competing for resources, no virtual memory, and no system calls — just your code and the hardware registers.


What Is the ESP32?

The ESP32 is a family of microcontrollers made by Espressif Systems, a Chinese semiconductor company. The ESP32 line is popular in hobby and IoT projects because it includes WiFi and Bluetooth on the chip — most other microcontrollers at this price point require an external wireless module.

The ESP32-S3 specifically

This project uses the ESP32-S3, a newer member of the ESP32 family. Key specs:

FeatureESP32-S3-WROOM-2 (32 MB flash / 16 MB PSRAM)
CPUDual-core Xtensa LX7, up to 240 MHz
RAM512 KB SRAM + 16 MB PSRAM (external)
Flash32 MB
WiFi802.11 b/g/n, 2.4 GHz
BluetoothBLE 5.0
GPIO pins~45 (not all usable; some reserved for flash/PSRAM)
USBNative USB-OTG (no external UART chip needed on some boards)
Operating voltage3.0–3.6 V

The PSRAM (pseudo-static RAM) is important for this project: the e-ink display frame buffer, WiFi stack, and audio DMA buffers collectively need more RAM than the 512 KB internal SRAM provides. The extra flash (32 MB) provides room for a 4 MB LittleFS audio partition alongside the firmware, with headroom left over for future image and font assets.

The module vs the development board

You do not buy the ESP32-S3 chip by itself. For the final build this project uses the ESP32-S3-WROOM-2 module (N32R16 variant), which is the chip plus flash, PSRAM, and an antenna integrated into a compact castellated package. It needs to be soldered to a carrier board or custom perfboard.

For breadboard prototyping, use an ESP32-S3 DevKitC-1 (any variant with ≥16 MB flash and ≥8 MB PSRAM). A dev board adds:

  • A USB-C connector for power and programming
  • A voltage regulator that converts USB 5 V to the 3.3 V the chip needs
  • A crystal oscillator (40 MHz) that provides the CPU clock
  • Pin headers that break out the GPIO pins to breadboard-friendly rows
  • A reset button and a boot button

See the ESP32 Dev Board page for setup.


How You Program a Microcontroller

Programming a microcontroller is different from writing a desktop application. There is no compiler running on the device — you compile code on your computer and transfer the resulting binary to the chip.

The development cycle

┌──────────┐ compile ┌──────────┐ flash ┌──────────┐
│ Write C │ ─────────────► │ Binary │ ────────────► │ ESP32 │
│ code on │ (on your │ (.bin) │ (over USB) │ runs it │
│ laptop │ laptop) │ │ │ │
└──────────┘ └──────────┘ └──────────┘

serial output


┌──────────┐
│ Terminal │
│ on laptop │
└──────────┘
  1. Write code in C (or C++) on your computer using any editor
  2. Compile using the ESP-IDF toolchain, which cross-compiles for the Xtensa LX7 architecture
  3. Flash the compiled binary to the ESP32's flash memory over USB
  4. Monitor the serial output in a terminal to see printf debug messages
  5. Repeat

The command that does steps 2–4 in one shot:

idf.py flash monitor

ESP-IDF: the official framework

ESP-IDF (Espressif IoT Development Framework) is the official SDK for ESP32 development. It provides:

  • Hardware abstraction — functions like gpio_set_level(), spi_bus_initialize(), i2s_channel_write() that hide the raw register manipulation
  • FreeRTOS — a real-time operating system kernel that gives you tasks (threads), queues, semaphores, and timers. This is not a full OS — there is no filesystem, no process isolation, no virtual memory — but it lets you run multiple tasks concurrently on the dual-core CPU
  • WiFi and networking stacks — TCP/IP, SNTP, HTTP server, mDNS
  • Driver libraries — I2C, SPI, I2S, UART, ADC, PWM, and more
  • Build system — CMake-based, handles cross-compilation and flash partitioning

ESP-IDF is written in C. You can use C++ if you prefer, but the SDK APIs are C.

What about Arduino?

The Arduino framework is an alternative way to program ESP32 boards. It provides a simpler API (digitalRead(), analogWrite(), Serial.println()) and uses the Arduino IDE or PlatformIO.

ESP-IDFArduino
LanguageC (with C++ support)C++ (simplified)
Abstraction levelLower — closer to hardwareHigher — easier to start
FreeRTOS accessFull — create tasks, queues, semaphoresLimited — available but not the default pattern
WiFi / BLE controlFine-grainedSimplified wrappers
Build systemCMake + idf.pyArduino IDE or PlatformIO
Best forProduction firmware, complex projectsPrototyping, simple projects

This project uses ESP-IDF because:

  • The audio playback system needs precise control over I2S DMA buffers and FreeRTOS task pinning to specific CPU cores
  • The WiFi + NTP + alarm scheduling logic benefits from FreeRTOS queues and timers
  • ESP-IDF gives direct access to the ESP32-S3's PSRAM, which the frame buffer requires

If you have used Arduino before, the concepts transfer — GPIO, SPI, I2C, and interrupts work the same way. The API names are different and the project structure is more complex, but the underlying hardware is identical.


How the ESP32 Compares to Other Microcontrollers

The ESP32 is not the only microcontroller family. Here is how it stacks up against alternatives you may have heard of:

Arduino Uno / Mega (ATmega328P / ATmega2560)

The original Arduino boards use Atmel AVR chips. These are 8-bit processors running at 16 MHz with 2 KB of RAM (Uno) or 8 KB (Mega). They have no WiFi or Bluetooth.

The Arduino Uno is an excellent learning platform because of its simplicity and enormous community. But it is too underpowered for this project: not enough RAM for a display frame buffer, no WiFi for NTP, and no I2S peripheral for audio.

Raspberry Pi Pico (RP2040 / RP2350)

The RP2040 is a dual-core ARM Cortex-M0+ at 133 MHz with 264 KB of RAM. It is fast, cheap ($4), and well-documented. The RP2350 (Pico 2) adds more RAM and a faster core.

The Pico has no WiFi or Bluetooth on the base chip (the Pico W variant adds WiFi via a separate CYW43439 module). It has PIO (Programmable I/O) state machines that can implement custom protocols — powerful but a steeper learning curve. For this project, the ESP32-S3's integrated WiFi and larger RAM (with PSRAM) make it a better fit.

STM32 (STMicroelectronics)

STM32 is a vast family of ARM Cortex-M microcontrollers ranging from tiny (STM32C0, $0.50) to powerful (STM32H7, 480 MHz, 1 MB RAM). They are the industry standard for commercial embedded products.

STM32 chips have no built-in WiFi (you add an external module). Their development tooling (STM32CubeIDE, HAL libraries) is more complex than ESP-IDF. STM32 is the right choice for battery-powered devices, high-reliability systems, and projects where you need precise analog performance — but for a WiFi-connected hobby project, the ESP32 is simpler to start with.

Nordic nRF52 / nRF53

Nordic's chips are optimised for Bluetooth Low Energy. They are excellent for wearables, sensors, and wireless peripherals. They have no WiFi (the nRF7002 companion chip adds it). Not a good fit for this project, which needs WiFi for NTP.

Why ESP32-S3 for this project

RequirementESP32-S3
WiFi for NTP time syncBuilt-in
I2S for digital audioBuilt-in peripheral
Enough RAM for e-ink frame buffer16 MB PSRAM
Flash for LittleFS audio partition32 MB (4 MB partition + firmware + headroom)
SPI for displayBuilt-in, with DMA
I2C for RTCBuilt-in
Dual-core for audio + displayYes, two LX7 cores
Affordable~$3–8 for the WROOM-2 module
Good documentation and communityExtensive, with official examples

The ESP32-S3 is not the best at any single thing, but it covers every requirement of this project in a single chip at a low price. That is why it is the most popular choice for WiFi-connected hobby hardware.


Key Concepts to Carry Forward

  • A microcontroller is a single-chip computer. You write C code on your laptop, compile it, and flash it over USB.
  • The ESP32-S3 has WiFi, Bluetooth, dual cores, and a rich set of peripherals (SPI, I2C, I2S, GPIO) built in.
  • ESP-IDF is the official framework. It includes FreeRTOS for multitasking and drivers for every peripheral used in this project.
  • The dev board adds USB, a voltage regulator, a crystal, and pin headers around the raw chip. You program and power the chip through the dev board's USB-C port.