Overview
Setting up a proper development environment is crucial for productive embedded programming. We’ll use VSCode with PlatformIO, which provides excellent support for ESP32 development.Why VSCode + PlatformIO?
Better than Arduino IDE
- IntelliSense (code completion)
- Advanced debugging
- Git integration
- Professional IDE features
Library Management
- Easy library installation
- Dependency management
- Multiple boards/platforms
- Built-in examples
Installation Steps
Step 1: Install VSCode
- Windows
- macOS
- Linux (Ubuntu)
- Download from https://code.visualstudio.com/
- Run installer (VSCodeUserSetup-x64-X.XX.X.exe)
- Important: Check “Add to PATH” during installation
- Complete installation
Step 2: Install PlatformIO Extension
- Open VSCode
- Click Extensions icon (or Ctrl+Shift+X)
- Search for “PlatformIO IDE”
- Click “Install”
- Wait for installation (may take 5-10 minutes)
- Restart VSCode when prompted
Step 3: Install USB Drivers (Windows only)
ESP32 uses CP2102 or CH340 USB-to-Serial chips: CP2102 Driver:- Download from: https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers
- Run installer
- Restart computer
- Download from: http://www.wch.cn/downloads/CH341SER_ZIP.html
- Run installer
- Restart computer
Step 4: Verify Installation
- Open VSCode
- Click PlatformIO icon in left sidebar (alien head)
- Should see PlatformIO Home screen
- If not, check for error messages in Output panel
Create First Project
1
New Project
- Click “New Project” in PlatformIO Home
- Name: “ESP32_Blink_Test”
- Board: “Espressif ESP32 Dev Module”
- Framework: “Arduino”
- Location: Choose folder
- Click “Finish”
2
Project Structure
3
Write Blink Code
Open
src/main.cpp and replace with:4
Connect ESP32
- Plug ESP32 into computer via USB
- Check COM port in Device Manager (Windows) or
ls /dev/tty*(Mac/Linux)
5
Upload Code
- Click checkmark icon (Build) - should compile successfully
- Click arrow icon (Upload) - uploads to ESP32
- Watch for “Success” message
- LED should blink!
6
Open Serial Monitor
- Click plug icon (Serial Monitor)
- Set baud rate to 115200
- Should see “LED ON” / “LED OFF” messages
PlatformIO Configuration
platformio.ini Explained
Useful PlatformIO Commands
Build
- Icon: Checkmark ✓
- Shortcut: Ctrl+Alt+B
- Compiles code without uploading
Upload
- Icon: Right arrow →
- Shortcut: Ctrl+Alt+U
- Builds and uploads to board
Serial Monitor
- Icon: Plug icon
- Shortcut: Ctrl+Alt+S
- View serial output
Clean
- Via PlatformIO menu
- Removes build artifacts
- Use if strange compile errors
Installing Libraries
Method 1: PlatformIO Library Manager (Recommended)
- Click PlatformIO icon → Libraries
- Search for library (e.g., “PID”)
- Click desired library
- Click “Add to Project”
- Select your project
- Library added to
platformio.ini
Method 2: Manual in platformio.ini
Add to[env:esp32dev] section:
Method 3: Local Library
- Create folder in
lib/directory - Add
.hand.cppfiles - Include in code:
#include "MyLibrary.h"
Recommended Extensions
Enhance VSCode with these extensions:- C/C++ (Microsoft) - IntelliSense, debugging
- Serial Monitor (Microsoft) - Alternative serial viewer
- GitLens - Git visualization
- Bracket Pair Colorizer - Easier to read nested code
- Teleplot - Real-time data plotting from serial
Troubleshooting
PlatformIO won't install
PlatformIO won't install
Solutions:
- Check internet connection
- Disable antivirus temporarily
- Manually install Python 3.6+ first
- Try VSCode Insiders build
ESP32 not detected (Windows)
ESP32 not detected (Windows)
Solutions:
- Install CP2102 or CH340 drivers
- Try different USB cable (some are power-only!)
- Try different USB port
- Check Device Manager for unknown devices
Upload fails at 'Connecting...'
Upload fails at 'Connecting...'
Solutions:
- Hold BOOT button while clicking Upload
- Check correct COM port selected
- Close Serial Monitor before uploading
- Press RESET button after upload starts
Compilation errors
Compilation errors
Solutions:
- Check for typos in code
- Verify all
#includestatements - Clean project (PlatformIO → Clean)
- Delete
.piofolder and rebuild
Serial Monitor shows garbage
Serial Monitor shows garbage
Solutions:
- Check baud rate matches code (115200)
- Verify correct COM port
- Press ESP32 RESET button
- Check USB cable quality
Best Practices
Version Control
- Initialize Git in project folder
- Add
.pio/to.gitignore - Commit regularly
- Push to GitHub
Code Organization
- Separate concerns (motor.cpp, encoder.cpp)
- Use header files (.h)
- Modular functions
- Comments and documentation
Testing
- Test incrementally
- Unit test each component
- Use Serial.println() for debugging
- Log important values
Power Management
- Use external power for motors
- Don’t power motors from USB!
- Common ground between ESP32 and motor supply
Next Steps
ESP32 Basics
Learn ESP32 pinout and features
Motor Driver
Understand IBT-2 H-bridge
DC Motor Control
Start implementing motor control
Code Examples
See working code examples