ESP32 GPIO & PWM Cheatsheet

Hardware ESP32 / Cheatsheet

ESP32 GPIO & PWM Cheatsheet

Digital I/O, ADC, DAC, LEDC PWM, touch pins at a glance.

Digital I/O
pinMode(pin, OUTPUT/INPUT/INPUT_PULLUP) Configure pin direction and pull mode
digitalWrite(pin, HIGH/LOW) Set a digital output pin high or low
digitalRead(pin) Read HIGH or LOW from a digital input pin
attachInterrupt(digitalPinToInterrupt(p), isr, FALLING) Attach an ISR to a pin edge
ADC & DAC
analogRead(pin) Returns 0߀“4095 (12-bit). Use GPIO 32߀“39 (ADC1)
raw * (3.3 / 4095.0) Convert ADC reading to voltage (3.3 V reference)
ADC2 conflicts with WiFi Do not use ADC2 pins (0,2,4,12߀“15,25߀“27) while WiFi is active
dacWrite(25, 128) Output ~1.65 V on GPIO 25 or 26 (true 8-bit DAC)
LEDC PWM
ledcSetup(ch, freq, bits) Configure PWM channel (0߀“15), frequency, and resolution
ledcAttachPin(pin, ch) Bind a GPIO pin to a LEDC channel
ledcWrite(ch, duty) Set duty cycle (0 to 2^bits - 1)
16 independent channels Each channel can have its own frequency and resolution
Touch & Misc
touchRead(pin) Returns capacitive reading ߀” lower = finger present
Touch pins: 4,12,13,14,15,27,32,33 Pins that support capacitive touch sensing
IRAM_ATTR on ISR functions Required attribute to ensure ISRs run from RAM
3.3 V max on all GPIO pins Never apply 5 V ߀” the ESP32 is NOT 5 V tolerant