ESP32

Why the ESP32 is the microcontroller of choice for home cockpit builds — GPIO, PWM, Wi-Fi, and how to wire it up.

Why the ESP32?

The ESP32 is a dual-core 240 MHz microcontroller with built-in Wi-Fi and Bluetooth. For a home cockpit it removes the need for a USB cable to every panel — each ESP32 connects wirelessly to the CockpitConnect backend and receives real-time dataref updates from X-Plane or MSFS over WebSockets.

FeatureESP32Arduino UnoArduino Mega
Clock speed240 MHz (dual core)16 MHz16 MHz
Flash memory4 MB32 KB256 KB
RAM520 KB2 KB8 KB
Wi-FiBuilt-in (802.11 b/g/n)NoNo
BluetoothBuilt-in (BLE + Classic)NoNo
PWM channels16 (LEDC)615
ADC channels18 (12-bit)6 (10-bit)16 (10-bit)
Logic voltage3.3 V5 V5 V
Price (approx.)€3–6€5–20€10–30
Pin Reference — ESP32 DevKit (38-pin)
ESP32 DevKit USB antenna 3V3 EN GPIO 36 (input only) GPIO 39 (input only) GPIO 34 (input only) GPIO 35 (input only) GPIO 32 GPIO 33 GPIO 25 GPIO 26 GPIO 27 GPIO 14 GPIO 12 GND GPIO 13 5V (VIN) GND GPIO 15 GPIO 2 GPIO 4 GPIO 16 (RX2) GPIO 17 (TX2) GPIO 5 GPIO 18 (SCK) GPIO 19 (MISO) GPIO 21 (SDA) GPIO 3 (RX0) GPIO 1 (TX0) GPIO 22 (SCL) GPIO 23 (MOSI) GPIO / PWM capable Power / special
Pin / BusGPIO(s)Notes
I²C (SDA / SCL)GPIO 21 / 22 Default; reassignable in Wire.begin(sda, scl)
SPI (MOSI / MISO / SCK)GPIO 23 / 19 / 18VSPI default; HSPI on 13/12/14
UART 0 (USB serial)GPIO 1 (TX) / 3 (RX)Used by Serial monitor — avoid as general IO
UART 2GPIO 17 (TX) / 16 (RX)Free for RS-232 / DMX / SBUS peripherals
Input-onlyGPIO 34, 35, 36, 39No internal pull-up; no output; ADC capable
Strapping pinsGPIO 0, 2, 5, 12, 15Affect boot mode — safe to use after boot, but avoid pull-downs at startup
Cockpit Wiring Strategy

A typical cockpit panel gets its own dedicated ESP32. Each board handles the inputs and outputs for one section — MCP, overhead, radio stack, gear lever — and communicates with the CockpitConnect backend over Wi-Fi. This means:

  • No USB hubs, USB cable routing across the cockpit frame, or COM port management on the sim PC
  • Panels can be physically removed or relocated without reconfiguring the simulator software
  • Each panel is independently powered and can be swapped or updated over-the-air (OTA)
PanelTypical inputsTypical outputsI/O count
MCP / FCURotary encoders, pushbuttons7-segment displays, backlight LEDs20–30
Overhead panelToggle switches, pushbuttonsAnnunciator LEDs30–60 (use I/O expanders)
Radio stackDual rotary encoders, flip-flop button7-segment or LCD displays10–20
Gear / flapGear lever switch, flap leverGear position LEDs, warning horn5–10
Instrument gaugesServos / steppers for needle drives4–8 per gauge cluster
Expanding GPIO with I²C

The ESP32 has ~25 usable GPIOs on a standard DevKit. Overhead panels can require 50+ inputs. The MCP23017 I²C I/O expander adds 16 GPIO pins per chip; up to 8 chips can share one I²C bus (addresses 0x20–0x27), giving 128 additional pins on just two wires.

Expander chipExtra GPIOsInterfaceMax per bus
MCP2301716I²C8 chips (128 pins)
MCP23S1716SPI8 chips (128 pins)
PCF85748I²C8 chips (64 pins)
74HC595 (shift register)8 outputs onlySPI / bit-bangChainable, unlimited
// I²C bus scanner — finds all connected devices
#include <Wire.h>

void setup() {
    Serial.begin(115200);
    Wire.begin(21, 22);   // SDA = GPIO 21, SCL = GPIO 22 (default)

    Serial.println("Scanning I2C bus...");
    for (uint8_t addr = 1; addr < 127; addr++) {
        Wire.beginTransmission(addr);
        if (Wire.endTransmission() == 0) {
            Serial.print("Device found at 0x");
            Serial.println(addr, HEX);
        }
    }
    Serial.println("Done.");
}

void loop() {}
Wi-Fi & WebSocket Connection

The ESP32 connects to the home network and opens a WebSocket connection to the CockpitConnect backend. The backend proxies dataref values from X-Plane/MSFS in real time. Each panel subscribes to the datarefs it needs and reacts to changes — updating displays, moving servos, or lighting annunciators.

Complete Wiring Examples

Each diagram shows the full circuit including the external power supply, shared GND bus, and the control signal from the ESP32. The key principle is the same in every case: the ESP32 provides only the signal; a separate supply provides the current.

Servo — external 5 V supply

ESP32 GPIO drives the signal wire only. VCC comes from a dedicated 5 V supply capable of delivering the stall current (500 mA for SG90, 2+ A for MG996R). Both the ESP32 VIN and the servo VCC are fed from the same 5 V rail; all GNDs join on a common bus.

5 V PSU 3 A+ 5V+ GND ESP32 VIN GND GPIO 23 Common GND bus SERVO SG90 / MG996R SIG VCC GND 5 V power Signal (3.3 V) GND

LED — single vs. multi-LED panel

A single LED can be driven directly from a GPIO pin through a series resistor (purple dashed path using 3.3 V). For a bank of annunciator LEDs use a 5 V external supply with an NPN transistor (BC547) as a low-side switch — the GPIO drives the base through a 1 kΩ resistor, keeping GPIO current well under the 12 mA recommended limit.

5 V PSU optional for many LEDs 5V+ GND ESP32 VIN GND GPIO 2 3V3 68 Ω LED 1 kΩ NPN BC547 C E LED bank multiple annunciators 5V+ GND Common GND bus single LED 5 V power GPIO signal 3.3 V (single LED alt.) transistor path (multi-LED)

Stepper motor — two separate supplies

The A4988 driver needs two distinct supplies: 12 V for the motor coils (VMOT) and 3.3 V for its logic (VDD). The ESP32 3V3 pin feeds VDD directly. Three GPIO pins carry STEP, DIR, and EN signals. A 100 µF electrolytic capacitor must be fitted across VMOT and GND close to the driver to suppress back-EMF spikes. All four GND connections — 12 V PSU, 5 V PSU, ESP32, and A4988 — tie together on the common bus.

12 V PSU 2 A+ 12V+ GND 5 V PSU 1 A 5V+ GND ESP32 VIN GND GPIO 23 STEP GPIO 22 DIR GPIO 21 EN 3V3 A4988 VMOT GND VDD (3.3V) STEP DIR EN 1A / 1B 2A / 2B 100 µF cap VMOT↔GND NEMA 17 Coil A Coil B Common GND bus Power (5/12 V) GPIO signals 3.3 V logic Motor coils GND
Powering the ESP32

The ESP32 itself draws ~240 mA peak (during Wi-Fi transmit bursts). The peripherals connected to a cockpit panel — servos, LED banks, stepper drivers — can draw several amperes. These loads must not be sourced from the ESP32's onboard 3.3 V regulator or the USB port. Use separate, appropriately rated supplies for each voltage rail, and connect all GNDs together at a single common point.

Powering the ESP32 board itself

MethodInput voltageWhen to use
USB (Micro-USB port)5 VDevelopment and bench testing only — USB supplies ~500 mA which is marginal under Wi-Fi load
VIN pin5–12 VFinished panels — feed from a dedicated 5 V rail; passes through the onboard AMS1117 regulator (800 mA max)
3V3 pin (direct)3.3 V regulatedWhen a lab PSU or external LDO already provides clean 3.3 V — bypasses the onboard regulator entirely

Powering peripherals from external supplies

Each voltage rail that drives actuators or many LEDs should come from its own dedicated external power supply. The ESP32 only provides the control signals.

RailTypical sourcePeripheralsRecommended rating
5 VUSB charger (5 V) or bench PSUServos (SG90, MG996R), 5 V LEDs, ULN2003 stepper boards3 A per panel minimum; 5–10 A for servo-heavy panels
12 VDesktop ATX PSU (12 V rail) or dedicated 12 V adapterNEMA 17 stepper motors via A4988/DRV8825, solenoids, relays2–5 A depending on motor count; always fit 100 µF cap near driver
3.3 V (logic only)ESP32 3V3 pin or LDO regulatorI²C sensors, display logic, I/O expanders (MCP23017)Keep total draw under 300 mA from ESP32's onboard regulator

Common ground rule

Every supply in the system — ESP32 board, 5 V servo PSU, 12 V stepper PSU — must share a common GND. Without a shared ground the control signals from the ESP32 GPIOs have no return path and the peripherals will behave erratically or not at all.