Overview
The ESP32-WROOM-32 is a powerful, low-cost microcontroller with WiFi and Bluetooth capabilities. In this project, it handles motor control, encoder reading, IMU interfacing, and serial communication with the Raspberry Pi.Role: Real-time motor control and sensor interfacing. Communicates with Raspberry Pi via USB serial at 115200 baud.
Specifications
Core Processor
| Feature | Specification |
|---|---|
| CPU | Dual-core Xtensa LX6, 32-bit |
| Clock Speed | Up to 240 MHz (adjustable) |
| RAM | 520 KB SRAM |
| Flash | 4 MB (external SPI flash) |
| ROM | 448 KB (bootloader) |
Interfaces
| Interface | Quantity | Notes |
|---|---|---|
| GPIO | 34 pins | 18 usable (some shared) |
| ADC | 18 channels, 12-bit | 0-3.3V input |
| DAC | 2 channels, 8-bit | GPIO 25, 26 |
| PWM | 16 channels | LEDC, up to 40 MHz |
| I2C | 2 controllers | Configurable pins |
| SPI | 4 controllers | 1 used for flash |
| UART | 3 controllers | UART0 for USB serial |
| Touch | 10 capacitive inputs | GPIO 0, 2, 4, 12-15, 27, 32, 33 |
Communication
| Feature | Specification |
|---|---|
| WiFi | 802.11 b/g/n, 2.4 GHz |
| Bluetooth | v4.2 BR/EDR and BLE |
| Antenna | PCB trace or external |
| Range | ~50m (open space) |
Power
| Parameter | Value |
|---|---|
| Operating Voltage | 3.0V - 3.6V (3.3V nominal) |
| Input Voltage (via USB) | 5V |
| Active Current | 80-160 mA (CPU active) |
| Deep Sleep | 10 µA |
| Power Consumption | ~0.5W typical |
Physical
| Parameter | Value |
|---|---|
| Dimensions | 48mm × 26mm × 3mm (DevKit V1 board) |
| Weight | ~10g |
| Operating Temperature | -40°C to +85°C |
Pinout Diagram
ESP32 DevKit V1 (30 pins)
Pin Functions Summary
Input Only Pins (no pull-up/down):- GPIO 34, 35, 36, 39
- GPIO 0: Must be HIGH at boot (pulled up)
- GPIO 2: Must be LOW at boot (has LED)
- GPIO 5: Must be HIGH at boot
- GPIO 12: Must be LOW at boot (affects voltage)
- GPIO 15: Must be HIGH at boot
| Pin | Use | Notes |
|---|---|---|
| GPIO 4, 16, 17, 18 | Motor PWM outputs | LEDC channels |
| GPIO 23, 19, 18, 5 | Motor direction control | Digital outputs |
| GPIO 34, 35, 36, 39 | Encoder inputs | Input-only, interrupts |
| GPIO 21, 22 | I2C (IMU) | SDA, SCL |
| GPIO 1, 3 | UART (USB serial) | TX, RX (USB) |
| GPIO 13, 14, 27, 32 | Additional encoder inputs | |
| GPIO 2 | Status LED | Built-in LED |
Pin Configuration for Robot
Motor Control (4 motors)
Motor 1 (Front-Left):Encoders (4 motors)
Use interrupt-capable pins for encoder inputs:IMU (I2C)
Serial Communication (USB)
UART0 (USB CDC):Status LED
PWM Configuration
LEDC (LED Controller) for Motor PWM
ESP32 has 16 PWM channels (LEDC) with independent configuration:- 1-10 kHz: Audible whine, good motor control
- 20-25 kHz: Ultrasonic (silent), excellent for brushed DC motors
-
25 kHz: Potential EMI issues
Interrupt Configuration
Encoder Interrupts
ISR (Interrupt Service Routine) for encoders:RISING: Trigger on LOW → HIGHFALLING: Trigger on HIGH → LOWCHANGE: Trigger on any change (2× resolution)
I2C Configuration
Communicating with IMU
- Standard: 100 kHz
- Fast: 400 kHz (recommended)
- Fast Plus: 1 MHz (if IMU supports)
Serial Communication
USB Serial (UART0)
Communication with Raspberry Pi:- 115200: Standard, reliable
- 230400: Faster, may have errors on long cables
- 921600: Very fast, requires good USB cable
Power Considerations
Powering ESP32
Options:-
USB Power (5V):
- Via USB-C or Micro-USB port
- Provides 5V → onboard regulator → 3.3V
- Current limit: 500 mA (USB 2.0)
-
VIN Pin (5V):
- Connect 5V from buck converter
- Onboard regulator provides 3.3V
- Current limit: ~800 mA
-
3.3V Pin (direct):
- Bypass onboard regulator
- Requires clean, stable 3.3V supply
- Risk: No protection from overvoltage
Current Draw
| Mode | Current | Power (3.3V) |
|---|---|---|
| Deep Sleep | 10 µA | 0.03 mW |
| Light Sleep | 0.8 mA | 2.6 mW |
| CPU Idle | 20-30 mA | 66-99 mW |
| CPU Active | 80-160 mA | 264-528 mW |
| WiFi Active | 120-200 mA | 400-660 mW |
| WiFi TX | 160-240 mA | 530-790 mW |
Programming
Development Environment
Recommended: PlatformIO + VSCode- Install ESP32 board support:
- File → Preferences → Additional Board Manager URLs:
- Tools → Board → Boards Manager → Search “ESP32” → Install
- File → Preferences → Additional Board Manager URLs:
Upload Methods
Via USB (Serial):- Connect ESP32 to PC via USB
- Select correct COM port
- Click Upload
- Hold BOOT button if upload fails
- Update firmware over WiFi (advanced)
- Useful for deployed robots
Troubleshooting
ESP32 not detected by PC
ESP32 not detected by PC
Solutions:
- Install CH340 or CP2102 USB-to-serial driver
- Try different USB cable (some are power-only)
- Press BOOT button during upload
- Check USB port works (try different port)
Upload fails / timeout
Upload fails / timeout
Solutions:
- Hold BOOT button, click Upload, release after “Connecting…”
- Lower upload speed: 460800 or 115200
- Disconnect devices from GPIO pins during upload
- Power cycle ESP32
GPIO not working
GPIO not working
Check:
- Pin is output-capable (36-39 are input-only)
- Pin not used by flash (GPIO 6-11)
- Strapping pin has correct pull-up/down
pinMode(pin, OUTPUT)called in setup()
I2C device not found
I2C device not found
Debug:Common issues:
- Wrong I2C address (check datasheet)
- SDA/SCL swapped
- Missing pull-up resistors (use INPUT_PULLUP)
- Device not powered
Encoder counts incorrect
Encoder counts incorrect
Debug:
- Check both channels connected (A and B)
- Verify interrupt attached:
attachInterrupt(...) - Print raw encoder values:
Serial.println(encoder_count) - Manually rotate wheel, check count direction
- Interrupt routine not in IRAM (
IRAM_ATTRmissing) - Channels swapped (A ↔ B)
- Bounce/noise (add capacitor 100nF on encoder lines)
Next Steps
Raspberry Pi Details
Raspberry Pi specifications
Motor Specifications
DC motor details and wiring
ESP32 Programming
ESP32 programming guide
Motor Control Code
Complete motor control implementation