PlatformIO Cheat Sheet
A professional embedded build system, usually used as a VS Code extension. Supports Arduino, ESP-IDF, STM32, RP2040 and more, with per-project library versions.
On this page
VS Code Shortcuts #
| Shortcut | Action |
|---|---|
Ctrl + Alt + B | Build |
Ctrl + Alt + U | Upload |
Ctrl + Alt + S | Serial monitor |
| PlatformIO icon (sidebar) | Project tasks, libraries, boards, PIO Home |
CLI (pio) #
| Command | Action |
|---|---|
| New project in the current folder | |
| Build all environments | |
| Build one environment | |
| Build and upload | |
| Upload to a specific port | |
| Clean the build | |
Upload the data/ folder (LittleFS / SPIFFS) | |
| ESP-IDF configuration menu | |
| Connected serial ports | |
Serial monitor (Ctrl + C to exit) | |
| Add a library to the project | |
| Update packages | |
| Installed packages | |
| Search board IDs | |
| Run unit tests | |
| Static code analysis | |
| Update PlatformIO itself |
Project Layout #
project/
├── platformio.ini # configuration
├── src/main.cpp # your code
├── include/ # headers
├── lib/ # private libraries
├── data/ # files for the filesystem (uploadfs)
└── test/ # unit tests
platformio.ini Example #
[platformio]
default_envs = esp32dev
[env] ; shared by all environments
framework = arduino
monitor_speed = 115200
lib_deps =
bblanchon/ArduinoJson@^7.0.0
adafruit/Adafruit BME280 Library
[env:esp32dev]
platform = espressif32
board = esp32dev
board_build.filesystem = littlefs
build_flags = -DDEBUG=1
[env:esp32s3]
platform = espressif32
board = esp32-s3-devkitc-1
build_flags = -DARDUINO_USB_CDC_ON_BOOT=1
monitor_filters = esp32_exception_decoder, time
Useful ini Options #
| Option | Use |
|---|---|
upload_port = COM5 / /dev/ttyUSB0 | Fix the upload port |
upload_speed = 921600 | Faster uploads |
monitor_filters = esp32_exception_decoder | Decode crash backtraces |
build_flags = -DVERSION=\"1.0\" | Defines / compiler flags |
build_src_filter = +<*> -<old/> | Exclude files |
board_build.partitions = huge_app.csv | Custom partition table |
extends = env:esp32dev | Inherit from another environment |
Tips #
- Commit
platformio.iniandsrc/, ignore.pio/. - Arduino sketches: rename
.inoto.cpp, add#include <Arduino.h>and declare functions before using them. - A "Library not found" error usually means it's missing from
lib_deps.
pio projectCreate and configure projects. pio project command [options]
| Command / option | What it does |
|---|---|
init | New project in the current folder |
-b esp32dev | Board (repeat for several) |
-O "monitor_speed=115200" | Add an option to platformio.ini |
--project-option "framework=espidf" | Same, long form |
--ide vscode | Generate IDE files |
--sample-code | Add a main.cpp example |
config | Show the parsed platformio.ini |
metadata -e env | Build metadata (include paths, defines) |
pio runBuild and upload a PlatformIO project. pio run [options]
| Option | What it does |
|---|---|
| (none) | Build every environment (or default_envs) |
-e esp32dev | One environment (repeat for more) |
-t upload | Build and upload |
-t clean | Clean the build |
-t uploadfs / -t buildfs | Upload / build the data/ filesystem image |
-t monitor | Open the serial monitor after the other targets |
-t menuconfig | ESP-IDF configuration menu |
-t erase | Erase the flash |
-t compiledb | Generate compile_commands.json (IntelliSense) |
--upload-port COM5 | Upload port |
-j 8 | Parallel jobs |
-v | Verbose output |
-s | Silent |
-d folder | Project folder |
--list-targets | All targets for the environment |
pio deviceSerial devices and monitor. pio device command [options]
| Command / option | What it does |
|---|---|
list | Connected serial ports (--json-output) |
monitor | Serial monitor (Ctrl + C to exit) |
-b 115200 | Baud rate (or monitor_speed in platformio.ini) |
-p COM5 | Port |
-f esp32_exception_decoder | Filters: time, colorize, log2file, send_on_enter |
--echo | Show what you type |
--eol LF | Line ending sent (CR, LF, CRLF) |
-e esp32dev | Use settings from an environment |
pio pkgLibraries, platforms and tools. pio pkg command [options]
| Command / option | What it does |
|---|---|
install -l "bblanchon/ArduinoJson@^7" | Add a library to the project (lib_deps) |
install -p espressif32 | Install a platform |
install -g -t tool-name | Global tool |
uninstall -l name | Remove a library |
update | Update packages (--dry-run to preview) |
outdated | Outdated packages |
list | Installed packages (-e env) |
search "ds18b20" | Search the registry |
show bblanchon/ArduinoJson | Details and versions |
-e esp32dev | Only for one environment |
pioPlatformIO command line. pio [command] [options]
| Command | What it does |
|---|---|
boards esp32 | Search board IDs (--json-output) |
test | Run unit tests (-e env, -f test_name, --without-uploading) |
check | Static analysis (--skip-packages, --fail-on-defect high) |
upgrade | Update PlatformIO Core (--dev = development version) |
home | Open PIO Home in the browser |
system info | Versions and folders |
system prune | Remove unused packages and cache |
account login | Log in to a PlatformIO account |
--version | Version |
Nothing on this sheet matches “”.