Getting started with ESP32 development is straightforward once the right tools are in place. This guide uses PlatformIO with Visual Studio Code — a free, cross-platform development ecosystem that provides dependency management, multi-board support, and integrated debugging in a single environment.
Core Features of Every ESP32 Board
Before setting up the environment, it helps to know what every ESP32 board brings to the table:
| Feature | Description |
|---|---|
| Wireless Communication | Built-in Wi-Fi and Bluetooth |
| Dual-Core Processor | For multitasking and compute-intensive workloads |
| Peripherals | GPIO, ADC, DAC, UART, SPI, I2C, PWM |
| Memory | Varying RAM and flash configurations; PSRAM in WROVER models |
| Low Power Modes | Multiple sleep modes — essential for battery projects |
Development Environment Options
Three development environments support ESP32:
| Environment | Pros | Best For |
|---|---|---|
| Arduino IDE | Simple, large library ecosystem | Beginners |
| PlatformIO (VS Code) | Professional, cross-platform, free | Intermediate to advanced |
| ESP-IDF | Most powerful, full ESP32 feature access | Advanced use |
This guide covers PlatformIO with Visual Studio Code — the best balance of power and accessibility.
What is PlatformIO?
PlatformIO is a development ecosystem that simplifies working with microcontrollers, especially in VS Code. It provides:
- Easy management of libraries and dependencies
- Support for multiple platforms including ESP32, STM32, AVR, and more
- Integrated tools for building, uploading, and debugging code
- A unified
platformio.iniconfiguration file for project settings
Prerequisites
Before installing PlatformIO, ensure these are installed:
- Visual Studio Code — code.visualstudio.com
- Python — PlatformIO requires Python to run — python.org
Step 1: Install PlatformIO
- Open VS Code and navigate to the Extensions panel (
Ctrl+Shift+Xor the square icon on the sidebar). - Search for PlatformIO IDE.
- Click Install.
After installation, PlatformIO adds icons to the VS Code sidebar and new options to the status bar at the bottom.
Step 2: Create Your First Project
- Click the PlatformIO icon in the VS Code sidebar.
- Click New Project and fill in:
- Name:
ESP32-Blink - Board:
ESP32 Dev Module - Framework:
Arduino
- Click Finish.
PlatformIO creates a project with this structure:
ESP32-Blink/
├── src/ <- Your source code (.cpp files)
├── include/ <- Header files
├── lib/ <- Local libraries
├── platformio.ini <- Project configuration
└── .pio/ <- Build artifacts (auto-generated)
Step 3: Write the Blink Program
Open src/main.cpp and replace its contents with:
#include <Arduino.h>
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Set built-in LED as output
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED on
delay(1000); // Wait for 1 second
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off
delay(1000); // Wait for 1 second
}
This program blinks the onboard LED every second — the classic first embedded program.
Step 4: Build and Upload
- Connect the ESP32 to your computer via USB.
- Select the Serial Port in the PlatformIO toolbar at the bottom of VS Code:
- Windows: usually
COM3orCOM4 - Linux/macOS: usually
/dev/ttyUSB0or/dev/cu.usbserial-*
- Build the project — click the checkmark (
✓) in the PlatformIO toolbar. - Upload the firmware — click the right arrow (
→) to flash to the ESP32.
The onboard LED should start blinking once upload completes.
Step 5: Use the Serial Monitor for Debugging
The serial monitor is essential for reading debug output from the ESP32. Add serial communication to the blink program:
#include <Arduino.h>
void setup() {
Serial.begin(115200); // Initialize serial at 115200 baud
pinMode(LED_BUILTIN, OUTPUT); // Set built-in LED as output
}
void loop() {
Serial.println("LED ON"); // Print to Serial Monitor
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
Serial.println("LED OFF"); // Print to Serial Monitor
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
Open the Serial Monitor by clicking the plug icon in the PlatformIO toolbar or selecting PlatformIO: Monitor. You should see LED ON and LED OFF alternating every second.
Configuring platformio.ini
The platformio.ini file controls all project settings. A typical ESP32 configuration:
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
upload_speed = 921600
monitor_speed = 115200
| Setting | Description |
|---|---|
platform | Espressif's platform package |
board | Target board identifier |
framework | Build framework (Arduino or ESP-IDF) |
upload_speed | Faster uploads with 921600 baud |
monitor_speed | Serial monitor baud rate must match Serial.begin() |
Adding Libraries
To add a library, either:
- Use the PlatformIO Library Manager in the sidebar to search and install
- Add to
platformio.inidirectly:
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
bblanchon/ArduinoJson@^6.21.0
knolleary/PubSubClient@^2.8
PlatformIO automatically downloads and compiles the dependencies.
Common Troubleshooting
| Problem | Solution |
|---|---|
| Upload fails | Hold the BOOT button on the ESP32 during upload |
| Port not found | Install CP2102 or CH340 USB driver for your OS |
| Serial Monitor shows garbage | Check that monitor_speed matches Serial.begin() baud rate |
| Board not recognized | Try a different USB cable (data cable, not charge-only) |
Next Steps
With the development environment working, you are ready to explore:
GPIO control → Digital input/output, button reading
Serial communication → UART, debugging, GPS modules
Wi-Fi connectivity → HTTP requests, MQTT, OTA updates
BLE → Device provisioning, sensor data
ADC → Analog sensor reading
I2C / SPI → Display and sensor interfacing
Final Thoughts
PlatformIO with VS Code provides a professional-grade embedded development experience for free. The combination of dependency management, multi-board support, and integrated serial monitor removes most of the setup friction so you can focus on writing firmware.
A working blink program is not just a test — it is proof that your entire toolchain is functional from editor to hardware.