A collection of motor control implementations for the ESP32-S2 Mini with DRV8833 motor driver.
- Simple motor test sequence
- Basic forward/backward/turn movements
- No fault detection
- Multiple movement modes (wander, rotate, test)
- Mode switching logic
- Basic error handling
- Improved power handling
- Speed ramping
- Basic fault detection
- Reduced motor speeds
- Slow, rock-like movement patterns
- Advanced fault detection
- PWM-based motor control
- Random movement generation
- Detailed debugging
- Continuous forward movement
- Basic PWM control
- Minimal code for testing
- No mode switching or complex logic
- Tests all motor directions sequentially
- Basic PWM control
- Auxiliary pin control (GPIO39)
- Cycle between directions automatically
- ESP32-S2 Mini (Lolin)
- DRV8833 Motor Driver
- 2 DC Motors
- Power Supply (5V recommended)
- Motor A: GPIO11 (IN1), GPIO9 (IN2)
- Motor B: GPIO7 (IN1), GPIO5 (IN2)
- Fault Pin: GPIO12
- LED: GPIO15
This project is organized into two versions:
- v1: Uses the ESP32-CAM and L298N motor driver (older, traditional driver)
- v2: Uses the ESP32-S2 Mini and DRV8833 motor driver (more efficient, modern setup)
Each version contains its own complete implementation for its respective hardware. For detailed wiring and implementation specifics, see the WIRING.md file in each subproject folder.
- 2-wheel drive robot car chassis with DC motors
- Jumper wires
- Small breadboard (optional, for cleaner wiring)
-
v1:
- ESP32-CAM development board
- L298N dual H-bridge motor driver (detailed documentation)
- MP1584EN buck converter module (for power regulation)
- Power supply for motors (battery pack/power bank)
-
v2:
- Wemos ESP32-S2 Mini development board
- DRV8833 dual H-bridge motor driver (detailed documentation)
- 5V powerbank with USB output
- USB splitter/hub or adapter
- USB in-line power switch (for global power control)
- Step-up converter (boosts 5V from powerbank to 6V for motors)
The v1 and v2 versions use different power supply approaches:
v1 Power Supply:
- Battery/power source → MP1584EN buck converter → ESP32-CAM (5V)
- Battery/power source → L298N motor driver (higher voltage)
v2 Power Supply:
- Powerbank USB output → Global power switch → USB splitter/hub
- First output: USB-C connection to ESP32-S2 Mini (direct connection)
- Second output: 5V to Step-up converter → DRV8833 motor driver (6V)
The v2 setup uses a true global power switch that controls the entire system with a single switch, turning both the microcontroller and motors on/off together.
| Feature | v1: ESP32-CAM | v2: ESP32-S2 Mini |
|---|---|---|
| USB Connection | External programmer required | Built-in USB-C port |
| Size | Larger | Compact |
| Power Input | 5V via pins | Direct USB-C |
| Programming | Via serial adapter | Native USB |
| Unnecessary Features | Camera module | None |
| Form Factor | Less robot-friendly | Ideal for robotics |
| Feature | v1: L298N | v2: DRV8833 |
|---|---|---|
| Efficiency | ~70% | >90% |
| Control Pins | 6 total | 4 total |
| Heat Generation | High | Low |
| Size | Large | Compact |
| Control Method | Enable + Direction pins | PWM on all pins |
| Feature | v1 Approach | v2 Approach |
|---|---|---|
| Power Switch | Controls motors only | True global control (entire system) |
| Power Source | Separate paths | Single source with distribution |
| Wiring Complexity | More complex | Simplified with USB connectivity |
| Development Mode | ESP32 always on | System fully controlled by one switch |
For detailed pin connections, wiring diagrams, and implementation specifics, see:
This project uses PlatformIO for development and deployment:
- Install Visual Studio Code
- Install the PlatformIO extension
- Clone or download this repository
- Open either the v1 or v2 project folder in VS Code
- Build and upload the project using PlatformIO
The v2 version with ESP32-S2 Mini can be programmed directly via USB-C connection without additional hardware, making development and testing significantly easier. During development, you can disconnect the powerbank and connect the ESP32-S2 Mini directly to your computer.
The robot car supports three different movement modes:
- Test Mode: Demonstrates basic movements in a sequence
- Wander Mode: Robot randomly wanders with organic movements
- Rotate Mode: Robot slowly rotates around its axis
By default, the robot switches between Wander Mode and Rotate Mode every 30 seconds.
The code includes the following standard movement functions:
moveForward(speed): Moves the robot forwardmoveBackward(speed): Moves the robot backwardturnLeft(speed): Turns the robot leftturnRight(speed): Turns the robot rightstopMotors(): Stops all motor movement
Advanced movement control is achieved through differential steering:
moveDifferential(leftSpeed, rightSpeed): Allows independent control of each wheelcurveLeft(leftSpeed, rightSpeed): Creates curved left movementcurveRight(leftSpeed, rightSpeed): Creates curved right movement
All movement functions support variable speed control through PWM, with speed values ranging from 0 (stop) to 255 (full speed).
Cycles through a series of basic movements to test motor functionality:
- Forward → Stop → Backward → Stop → Left turn → Stop → Right turn → Stop
Implements organic, randomized movement with varying speeds and paths:
- Straight forward movement
- Gentle left and right curves
- Sharp left and right curves
- 180° spin turns
- Backward movement
- Random stops
Performs a slow, controlled rotation around the robot's center:
- Rotates in a random direction (left or right)
- Changes direction every 10 seconds
- Uses reduced speed for careful rotation
You can customize the pin assignments at the beginning of the motor_control.cpp file if you need to use different GPIO pins on your microcontroller.
To implement additional movement modes or alter the existing ones, refer to the corresponding mode files in the src directory.
Basic troubleshooting tips are included in the WIRING.md file for each version:
For each version (v1 and v2):
platformio.ini: PlatformIO configurationWIRING.md: Detailed wiring and implementation documentationinclude/motor_control.h: Header file for motor control functionsinclude/movement_modes.h: Defines the movement modes enuminclude/test_mode.h: Header for test modeinclude/wander_mode.h: Header for wander modeinclude/rotate_mode.h: Header for rotate modesrc/motor_control.cpp: Motor control functions implementationsrc/main.cpp: Main program with setup, loop, and mode switching logicsrc/test_mode.cpp: Test mode implementationsrc/wander_mode.cpp: Wander mode implementation with organic movementsrc/rotate_mode.cpp: Rotate mode implementation
This project is open source and available under the MIT License.