Overview
The ESP32 is a powerful, low-cost microcontroller with built-in WiFi and Bluetooth. Understanding its capabilities and pin configuration is essential for successful robot development.ESP32 Specifications
Key Features
- Processor: Dual-core Xtensa 32-bit LX6 @ 240MHz
- Memory: 520KB SRAM, 4MB Flash (typical)
- Connectivity: WiFi 802.11 b/g/n, Bluetooth 4.2 + BLE
- GPIO: 34 programmable pins
- ADC: 2× 12-bit SAR ADCs (18 channels)
- DAC: 2× 8-bit DACs
- PWM: 16 channels
- Interfaces: UART, SPI, I2C, I2S, CAN
- Operating Voltage: 3.0-3.6V (typically 3.3V)
- Input Voltage: 5V via USB or VIN pin
Pinout Reference
Safe GPIO Pins (Recommended for Use)
These pins are safe to use without issues:| GPIO | Functions | Notes |
|---|---|---|
| GPIO 4 | Digital I/O, ADC2_0 | ✅ Safe |
| GPIO 5 | Digital I/O | ✅ Safe, VSPI CS |
| GPIO 12 | Digital I/O, ADC2_5 | ⚠️ Pull-down at boot |
| GPIO 13 | Digital I/O, ADC2_4 | ✅ Safe |
| GPIO 14 | Digital I/O, ADC2_6 | ✅ Safe |
| GPIO 15 | Digital I/O, ADC2_3 | ✅ Safe |
| GPIO 16 | Digital I/O | ✅ Safe, UART2 RX |
| GPIO 17 | Digital I/O | ✅ Safe, UART2 TX |
| GPIO 18 | Digital I/O | ✅ Safe, VSPI CLK |
| GPIO 19 | Digital I/O | ✅ Safe, VSPI MISO |
| GPIO 21 | Digital I/O | ✅ Safe, I2C SDA |
| GPIO 22 | Digital I/O | ✅ Safe, I2C SCL |
| GPIO 23 | Digital I/O | ✅ Safe, VSPI MOSI |
| GPIO 25 | Digital I/O, DAC1, ADC2_8 | ✅ Safe |
| GPIO 26 | Digital I/O, DAC2, ADC2_9 | ✅ Safe |
| GPIO 27 | Digital I/O, ADC2_7 | ✅ Safe |
| GPIO 32 | Digital I/O, ADC1_4 | ✅ Safe |
| GPIO 33 | Digital I/O, ADC1_5 | ✅ Safe |
Input-Only Pins
These pins can ONLY be used as inputs:| GPIO | Notes |
|---|---|
| GPIO 34 | Input only, ADC1_6 |
| GPIO 35 | Input only, ADC1_7 |
| GPIO 36 (VP) | Input only, ADC1_0 |
| GPIO 39 (VN) | Input only, ADC1_3 |
Use Case: Input-only pins are perfect for reading sensors or buttons. Use them for encoder inputs to save output-capable pins.
Pins to AVOID
| GPIO | Reason |
|---|---|
| GPIO 0 | Boot mode selection, pulled HIGH, pull LOW to enter flash mode |
| GPIO 1 | UART0 TX (USB serial) - used for programming |
| GPIO 2 | Boot mode, must be LOW at boot, connected to LED on many boards |
| GPIO 3 | UART0 RX (USB serial) - used for programming |
| GPIO 6-11 | Connected to SPI flash (DO NOT USE!) |
Pin Configuration for Our Robot
Recommended Pin Assignments
GPIO Functions
Digital I/O
PWM Output
ESP32 has 16 independent PWM channels with high resolution:- Frequency: 1-40MHz (typically 1-20kHz for motors)
- Resolution: 1-16 bits (higher res = lower max frequency)
- Duty Cycle: 0 = 0%, 255 = 100% (for 8-bit)
Analog Input (ADC)
ESP32 has two ADC units:- ADC2 cannot be used with WiFi!
- Non-linear, especially at extremes
- Use ADC1 pins when using WiFi
I2C Communication
Interrupts
ESP32 supports interrupts on all GPIO pins:RISING- Trigger on LOW to HIGH transitionFALLING- Trigger on HIGH to LOW transitionCHANGE- Trigger on any changeLOW- Trigger while pin is LOW (not recommended)HIGH- Trigger while pin is HIGH (not recommended)
Power Considerations
Power Supply Options
-
USB (5V):
- Convenient for programming
- Limited current (~500mA)
- Don’t power motors from USB!
-
VIN Pin (5-12V):
- Regulated down to 3.3V on-board
- Can provide more current
- Still limited for motors
-
3.3V Pin:
- Direct 3.3V supply
- Bypass internal regulator
- Max ~600mA from on-board regulator
- ESP32: Powered from 5V USB or VIN
- Motors: Separate 12V power supply
- Common Ground: Connect ESP32 GND to motor power GND
Current Limits
| Pin | Max Current | Notes |
|---|---|---|
| Single GPIO | 40mA | Don’t exceed! |
| All GPIO combined | 200mA | Total for all pins |
| 3.3V regulator | ~600mA | On-board LDO |
WiFi and Bluetooth
WiFi Basics
Bluetooth Serial
WiFi vs Bluetooth: WiFi uses more power but has longer range and higher bandwidth. Bluetooth is lower power and good for short-range control.
Troubleshooting
ESP32 won't boot / endless restart
ESP32 won't boot / endless restart
Causes:
- GPIO 0 pulled LOW
- GPIO 2 pulled HIGH
- Power supply insufficient
- Code crashes immediately
- Check boot pins (0, 2)
- Use stable power supply
- Upload minimal test code
- Monitor Serial for error messages
GPIO not working
GPIO not working
Solutions:
- Check if pin is input-only
- Avoid GPIO 6-11 (flash pins)
- Verify pin isn’t used by WiFi (ADC2)
- Check pinMode() correctly set
ADC readings incorrect
ADC readings incorrect
Solutions:
- Use ADC1 pins (ADC2 conflicts with WiFi)
- Calibrate ADC (non-linear)
- Add smoothing/filtering
- Check voltage range (0-3.3V)
I2C device not found
I2C device not found
Solutions:
- Run I2C scanner
- Check SDA/SCL wiring
- Verify pull-up resistors (4.7kΩ)
- Try lower clock speed (100kHz)
Best Practices
Pin Planning
- Plan pin assignments before wiring
- Group related pins (all motor PWM together)
- Document in code and schematic
- Leave some pins unassigned for future expansion
Voltage Levels
- ESP32 is 3.3V logic (NOT 5V tolerant on most pins!)
- Use level shifters for 5V devices
- Check sensor/module voltage compatibility
Power Management
- Separate power domains (logic vs motors)
- Common ground essential
- Add bulk capacitors near ESP32
- Monitor power consumption
Code Organization
- Define pins in header file
- Use meaningful names
- Comment pin purposes
- Test pins individually before integration
Next Steps
Motor Driver Guide
Learn to interface with IBT-2
DC Motor Control
Implement motor control with PID
IMU Integration
Connect and read IMU sensor
Hardware Reference
Detailed ESP32 specifications