ESP32 Tutorial (based on Arduino and more)

Many years ago, I bought an Arduino but did not play too much.

Recently, I bought an ESP32 board (DOIT ESP32 DevKit V1, 30-pin) and related "accessories".

Time changed, and my "energy" has shifted from "Work-Live-Play" to "Live-Play" (since Jun 2023). Also, since 2024, I use AI for my daily reading, coding, and THINKING process.

I want to re-pickup my amateur likings for "doing something fun".

So this is it: Build something with ESP32. I decided to start from the ready-made Arduino samples. To migrate Arduino samples to ESP32 may face some challenges but I think I can handle them.

After some time - maybe one month, one year, who knows - I will try to see how much further I can go with ESP32 (and those accessories come with it).

TR@SOE

2026.5.21

Table of Contents

Appendix I: The Final Cheat Sheet

This is a very comprehensive guideline generated by AI and I found it very critical to remember.

NOTE: This guideline is based on my board and your board may have a different configuration.

1. System Limits & Power Rules

  • Operating Voltage: Strictly 3.3V logic. No pins are 5V tolerant.
  • Current Draw: Maximum 12mA to 20mA per GPIO pin. Use transistors or relay modules for inductive loads (motors, buzzers).
  • USB Power Routing: When powering via Micro-USB, the 3V3 pin acts as a 3.3V source for low-draw peripherals. Do not connect external voltage to VIN while USB is plugged in.
  • The Silicon Silence: Pins GPIO 6 through GPIO 11 are missing from the headers because they are permanently hardwired to the internal SPI flash memory chip. Never use them in code.

2. Physical Layout & Firmware Rules (Top-Down Mapping)

Board Mark Code Pin Primary Role Hardware Constraints & Hidden Features
3V3 3.3V Output Power rail for 3.3V external sensors.
GND Ground Common system ground connection.
D15 15 Digital I/O ADC2 / Touch 3. Boot strapping pin (Do not pull low on boot).
D2 2 Digital I/O ADC2 / Touch 2. Internally tied to the onboard Blue LED.
D4 4 Digital I/O ADC2 / Touch 0. Free-use pin. (Used for your touch sensor input).
RX2 16 UART2 RX High-speed Hardware Serial Receiver (safe for external modules).
TX2 17 UART2 TX High-speed Hardware Serial Transmitter (safe for external modules).
D5 5 Digital I/O Hardware SPI Chip Select (CS) pin.
D18 18 Digital I/O Hardware SPI Clock (SCK) pin.
D19 19 Digital I/O Hardware SPI Master-In-Slave-Out (MISO) pin.
D21 21 I2C SDA Dedicated Hardware I2C Data line for OLEDs and sensors.
RX0 / TX0 3 / 1 UART0 Do not use. Hardwired to USB-to-UART chip for code uploads and Serial printing.
D22 22 I2C SCL Dedicated Hardware I2C Clock line for OLEDs and sensors.
D23 23 Digital I/O Hardware SPI Master-Out-Slave-In (MOSI) pin.
D13 13 Digital I/O ADC2 / Touch 4. Free-use pin. (Used for your external LED output).
D12 12 Digital I/O ADC2 / Touch 5. Boot strapping pin (If pulled HIGH at boot, flash fails).
D14 14 Digital I/O ADC2 / Touch 6. Free-use pin.
D27 27 Digital I/O ADC2 / Touch 7. Free-use pin.
D26 26 Digital I/O ADC2 / DAC2. Outputs a true variable DC analog voltage (0V to 3.3V).
D25 25 Digital I/O ADC2 / DAC1. Outputs a true variable DC analog voltage (0V to 3.3V).
D33 33 Digital I/O 🟢 ADC1 / Touch 8. Wi-Fi safe analog input. Full output support.
D32 32 Digital I/O 🟢 ADC1 / Touch 9. Wi-Fi safe analog input. Full output support.
D35 35 Digital Input 🟢 ADC1. Wi-Fi safe analog input. INPUT ONLY (No output circuitry).
D34 34 Digital Input 🟢 ADC1. Wi-Fi safe analog input. INPUT ONLY (No output circuitry).
VN 39 Digital Input 🟢 ADC1. Wi-Fi safe analog input. INPUT ONLY (No output circuitry).
VP 36 Digital Input 🟢 ADC1. Wi-Fi safe analog input. INPUT ONLY (No output circuitry).
EN HW Reset Connected to the left push button. Pull low to restart program.
VIN Power Input External power entry point (Accepts 5V to 9V DC when USB is detached).

3. The Functional Constraints (The "Gotchas")

  • The Wi-Fi Blindness: If your code invokes WiFi.begin(), the entire ADC2 block is hijacked by the internal network driver. Any attempt to use analogRead() on an ADC2 pin will return garbage data or static flatlines. Stick to ADC1 pins for analog when using network protocols.
  • The Output Wall: Pins D35, D34, VN (39), and VP (36) do not possess output silicon drivers or internal pull-up/pull-down resistors. Executing digitalWrite() or ledcWrite() on them does nothing.
  • The Onboard Buttons:
    • EN Button: Hardwired reset.
    • BOOT Button: Drives the chip into flashing mode. If PlatformIO gets stuck on Connecting......._____....., hold down the BOOT button until the progress percentage begins.

4. Code Syntax Reminders (PlatformIO)

  • No "D" prefixes: In your source code files, refer to pins exclusively by their raw integer values (e.g., use 4, not D4).
  • Universal PWM: Every single output-capable GPIO pin can generate independent PWM signals using the ESP32's internal LEDC hardware peripheral.