Getting started: Arduino IDE, VS Code and PlatformIO
You write ESP32 code on your computer. A software tool compiles the code and sends it to the board through the USB cable. This page tells you how to set up two tools for a classic ESP32-WROOM-32 DevKit. The Arduino IDE 2.x is the makerspace default. VS Code with PlatformIO is better for large projects. The code on this site uses the Arduino-ESP32 core 3.x API.
Which tool to choose
| Arduino IDE 2.x | VS Code + PlatformIO | |
|---|---|---|
| Best for | Beginners, short sketches, makerspace workshops | Large projects with many files, team projects |
| Setup | Easy. One installer and one board package. | More steps. The first build downloads many tools. |
| ESP32 core version | The newest 3.x core from Espressif | Set by the platform line in platformio.ini (see the note below) |
| Libraries | Installed one time for all sketches | Listed in each project, so each project keeps its own versions |
| Version pinning | Manual | Yes. You write the exact versions in platformio.ini. |
| Git and code editor | Basic editor | Full editor with autocomplete and Git |
Arduino IDE 2.x
Install the IDE and the ESP32 boards
- Install the Arduino IDE 2.x.Download it from arduino.cc/en/software. Run the installer.
- Open the preferences.On Windows, select File → Preferences. On macOS, select Arduino IDE → Settings.
- Add the Espressif boards URL.Paste this URL into Additional boards manager URLs:
https://espressif.github.io/arduino-esp32/package_esp32_index.json
Click OK. - Open the Boards Manager.Select Tools → Board → Boards Manager. Type
esp32in the search box. - Install the ESP32 core.Find esp32 by Espressif Systems. Select a 3.x version and click Install. The download is large, so wait some minutes.
- Install the USB driver if necessary.Connect the board. If a new port shows in Tools → Port, you do not need a driver. If no port shows, read the name of the small chip next to the USB connector (CP2102, CH340 or CH9102). Then download and install the driver for that chip. Read Install the ESP32 USB driver for the download links and the steps for Windows and macOS. Restart the Arduino IDE after the installation.
Select the board and the port
- Connect the DevKit.Use a USB cable that carries data.
- Select the board.Select Tools → Board → esp32 → ESP32 Dev Module.
- Select the port.Select Tools → Port. On Windows, the port is
COM3or a similar name. On macOS, the port is/dev/cu.usbserial-…or/dev/cu.wchusbserial…. - If no port shows, examine the driver and the cable.Install the USB driver (refer to step 6 above), or use a different USB cable. Read Install the ESP32 USB driver.
- Open the Serial Monitor.Select Tools → Serial Monitor. Set the baud rate list to 115200 baud. This value must agree with
Serial.begin(115200)in your code.
Keep the other settings in the Tools menu at their default values. The defaults are correct for a 4 MB ESP32-WROOM-32 DevKit.
Upload Blink
Many DevKits have a blue LED on GPIO 2. If your board has no LED on GPIO 2, connect an LED and a 220 Ω resistor from GPIO 2 to GND.
blink.ino
const int LED_PIN = 2; // on-board LED on many DevKits
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
digitalWrite(LED_PIN, HIGH);
Serial.println("LED on");
delay(500);
digitalWrite(LED_PIN, LOW);
Serial.println("LED off");
delay(500);
}
- Paste the code.Select File → New Sketch. Replace all the text with the code above.
- Upload the code.Click the Upload button (the right arrow). The first compile takes some minutes.
- Examine the result.The LED flashes. The Serial Monitor shows “LED on” and “LED off”.
Install libraries
- Open the Library Manager.Select Sketch → Include Library → Manage Libraries. You can also click the books icon in the left sidebar.
- Find the library.Type the name, for example
Adafruit NeoPixel. - Install the library.Click Install. If the IDE asks about dependencies, click Install all.
- Use the library.Add the
#includeline at the top of your sketch. Each page on this site tells you which library to install.
Common upload errors
| Message or symptom | Cause | Fix |
|---|---|---|
Failed to connect to ESP32: Wrong boot mode detected or the upload stops at Connecting… | The board did not go into download mode automatically. | Push and hold the BOOT button. Click Upload. Release BOOT when the percent values show. |
| No port in Tools → Port | The cable carries only power, or the USB driver is missing. | Use a different cable that carries data. Then install the driver. |
Port is busy or Access is denied | Another program uses the port. | Close other Serial Monitor windows and other serial programs. Then try again. |
| Upload is correct, but nothing happens | The board stays in download mode, or the pin is wrong. | Push the EN (reset) button. Make sure that the pin number in the code agrees with your wiring. |
| Random characters in the Serial Monitor | The baud rate is wrong. | Set the Serial Monitor to the same value as Serial.begin(). |
'ledcSetup' was not declared or a similar error | The code uses the old 2.x API. | Use ledcAttach() and ledcWrite(pin, duty). Read the PWM page. |
VS Code + PlatformIO
PlatformIO is an extension for Visual Studio Code. It keeps the board settings, the ESP32 platform version and the library list in one file: platformio.ini.
You can put this file in Git, so other people can build the same project.
Install and create a project
- Install VS Code.Download it from code.visualstudio.com.
- Install the PlatformIO extension.Open the Extensions view (Ctrl+Shift+X). Search for
PlatformIO IDE. Click Install. - Wait for the installation to complete.PlatformIO downloads its core tools. Restart VS Code when it asks.
- Create a project.Click the PlatformIO icon (the ant head) in the left bar. Select PIO Home → Projects → Create New Project.
- Set the project options.Type a name. For Board, select Espressif ESP32 Dev Module (
esp32dev). For Framework, select Arduino. Click Finish. - Edit
platformio.ini.Use the example on this page. Add themonitor_speedline.
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps =
adafruit/Adafruit NeoPixel@^1.12.0
monitor_speedsets the Serial Monitor baud rate. Make it agree withSerial.begin().lib_depslists the libraries. PlatformIO downloads them at the next build. Add one library on each line.- Find the exact library names in the PIO Home → Libraries search, or at registry.platformio.org.
platform = espressif32 gives the older Arduino-ESP32 core 2.0.x.
It does not give the 3.x core. Some code on this site uses 3.x functions, for example ledcAttach(), so that code does not compile with the official platform.
To get the 3.x core, many people use the community pioarduino platform. Replace the platform line with this line:
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
pioarduino is a community project. PlatformIO and Espressif do not maintain it. The pioarduino project also has its own VS Code extension, pioarduino IDE.
Do not install the PlatformIO IDE extension and the pioarduino IDE extension in the same VS Code profile, because they can conflict.Where the code goes
Put your code in src/main.cpp. A .cpp file needs #include <Arduino.h> at the top.
The Arduino IDE adds this line automatically, but PlatformIO does not.
src/main.cpp
#include <Arduino.h>
const int LED_PIN = 2;
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
Serial.println("toggle");
delay(500);
}
In a .cpp file, declare each function before you use it. The Arduino IDE does this step for .ino files.
Build, upload and monitor
Use the buttons in the blue status bar at the bottom of VS Code:
| Button | Action |
|---|---|
| ✓ (check mark) | Build. Compiles the code. |
| → (right arrow) | Upload. Compiles the code and sends it to the board. |
| Plug icon | Serial Monitor. Shows the output at monitor_speed. |
| Trash can icon | Clean. Deletes the build files. Use it after you change the platform. |
- PlatformIO usually finds the port automatically. To set it, add
upload_port = COM5(or/dev/cu.usbserial-…). - Close the Serial Monitor before you upload. If you do not, the upload can fail because the port is busy.
- The BOOT button fix and the driver fix are the same as for the Arduino IDE.
Resources
- Arduino-ESP32: Installing (Espressif)The official instructions and the boards manager URL.
- Arduino IDE 2 documentationBoards Manager, Library Manager and Serial Monitor.
- PlatformIO IDE for VS CodeInstallation, the toolbar and project settings.
- platformio.ini referenceAll options for
platform,lib_deps,monitor_speedand more. - pioarduino platform-espressif32 (GitHub)The community platform with the Arduino-ESP32 3.x core.
- Install the ESP32 USB driver · ESP32 GPIOThe next steps after the setup.