PlatformIO IDE is the next-generation integrated development environment for IoT.
Cross-platform build system without external dependencies to the OS software:
550+ embedded boards
30+ development platforms
15+ frameworks
C/C++ Intelligent Code Completion
C/C++ Smart Code Linter for rapid professional development
Library Manager for the hundreds popular libraries
Multi-projects workflow with multiple panes
Themes support with dark and light colors
Serial Port Monitor
Built-in Terminal with PlatformIO Core (CLI) and CLI tool (pio
, platformio
)
Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux. It comes with built-in support for JavaScript, TypeScript and Node.js and has a rich ecosystem of extensions for other languages (such as C++, C#, Python, PHP, Go) and runtimes (such as .NET and Unity)
Note
Please note that you do not need to install PlatformIO Core (CLI) separately if you are going to use PlatformIO IDE for VSCode. PlatformIO Core (CLI) is built into PlatformIO IDE and you will be able to use it within PlatformIO IDE Terminal.
This tutorial introduces you to the basics of PlatformIO IDE workflow and shows you a creation process of a simple “Blink” example. After finishing you will have a general understanding of how to work with projects in the IDE.
Click on “PlatformIO Home” button on the bottom PlatformIO Toolbar
Click on “New Project”, select a board and create new PlatformIO Project
Open main.cpp
file form src
folder and replace its contents with
the next:
Warning
The code below works only in pair with Arduino-based boards. Please follow to PlatformIO Project Examples repository for other pre-configured projects.
/**
* Blink
*
* Turns on an LED on for one second,
* then off for one second, repeatedly.
*/
#include "Arduino.h"
// Set LED_BUILTIN if it is not defined by Arduino framework
// #define LED_BUILTIN 13
void setup()
{
// initialize LED digital pin as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
// turn the LED on (HIGH is the voltage level)
digitalWrite(LED_BUILTIN, HIGH);
// wait for a second
delay(1000);
// turn the LED off by making the voltage LOW
digitalWrite(LED_BUILTIN, LOW);
// wait for a second
delay(1000);
}
Build your project with ctrl+alt+b
hotkey (see all Key Bindings in
“User Guide” section below) or using “Build” button on the PlatformIO Toolbar
Further for reading:
Tutorials and Examples (step-by-step tutorials with debugging and unit testing)
Learn more about PlatformIO Toolbar and other commands (Upload, Clean, Serial Monitor) below.
Happy coding with PlatformIO!
PlatformIO IDE Toolbar is located in VSCode Status Bar (left corner) and contains quick access buttons for the popular commands. Each button contains hint (delay mouse on it).
PlatformIO: Build
PlatformIO: Upload
PlatformIO: Clean
Run a task… (See “Task Runner” below)
PIO Terminal
You can override default “PlatformIO: Build” task for “Build” command which
is used by “Build” button in PlatformIO Toolbar and
Key Bindings. See platformio-ide.buildTask
setting
in Settings for more details.
Built-in PlatformIO tasks are available in “Menu > Terminal > Run Task…” list.
ctrl+alt+b
/ cmd-shift-b
/ ctrl-shift-b
Build Project
cmd-shift-d
/ ctrl-shift-d
Debug project
ctrl+alt+u
Upload Firmware
ctrl+alt+s
Open Serial Port Monitor
You can override existing key bindings or add a new in VSCode. See official documentation Key Bindings for Visual Studio Code.
PlatformIO provides access to “Project Task Explorer” where you can control build process of declared environments in “platformio.ini” (Project Configuration File). Project Task Explorer is located in VSCode Activity Bar under branded PlatformIO icon. You can also access it via “VSCode Menu > Open View… > PlatformIO”.
PlatformIO IDE provides base tasks Menu > Termina > Run Task...
(Build,
Upload, Clean, Monitor, etc) and custom tasks per “platformio.ini” (Project Configuration File) environment
([env:***]
). A default behavior is to use Terminal Panel for presentation.
Also, we use dedicated panel per unique task.
PlatformIO IDE provides own Problems Matcher named $platformio
.
You can use it later if decide to change base task settings.
You can override existing task with own presentation options. For example, let configure PlatformIO Task Runner to use NEW Terminal panel per each “Build” command:
Please click on “gear” icon near “Build” task in Menu > Tasks
Replace template in tasks.json
with this code
{ "version": "2.0.0", "tasks": [ { "type": "PlatformIO", "task": "Monitor", "problemMatcher": [ "$platformio" ], "presentation": { "panel": "new" } } ] }
See more options in official VSCode documentation.
Custom tasks can be added to tasks.json
file located in .vscode
folder
in the root of project. Please read official documentation Tasks in VSCode.
This simple example demonstrates a custom build process in verbose mode. There are a lot of other commands, please read more about PlatformIO Core (CLI) and its commands (CLI Guide).
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"command": "platformio",
"args": [
"device",
"monitor",
"--echo"
],
"problemMatcher": [
"$platformio"
],
"label": "PlatformIO: Monitor (local echo)"
}
]
}
If platformio
executable file is not in your system environment “PATH”, you
can provide a full path to binary folder using options
field for task. For example,
platformio
binary is located in home folder “~/.platformio/penv/bin”:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"command": "platformio",
"args": [
"device",
"monitor",
"--echo"
],
"problemMatcher": [
"$platformio"
],
"label": "PlatformIO: Monitor (local echo)",
"options": {
"env": {"PATH": "${env:HOME}/.platformio/penv/bin"}
}
}
]
}
You can work with multiple project folders in Visual Studio Code with multi-root workspaces. This can be very helpful when you are working on several related projects at one time. Read more in documentation Multi-root Workspaces.
You can customize Serial Port Monitor using Monitor options in “platformio.ini” (Project Configuration File):
Example:
[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev
; Custom Serial Monitor port
monitor_port = /dev/ttyUSB1
; Custom Serial Monitor speed (baud rate)
monitor_speed = 115200
Debugging in VSCode works in combination with PIO Unified Debugger. You should have PIO Account to work with it.
VSCode has a separate activity view named “Debug” (bug icon on the left toolbar). PIO Unified Debugger extends it with the next advanced debugging instruments and features:
Local, Global, and Static Variable Explorer
Conditional Breakpoints
Expressions and Watchpoints
Generic Registers
Peripheral Registers
Memory Viewer
Disassembly
Multi-thread support
A hot restart of an active debugging session.
There are 2 pre-configured debugging configurations:
Default configuration. PlatformIO runs Pre-Debug task and builds project using Debug Configuration. Also, it checks for project changes.
PlatformIO skips Pre-Debug stage and DOES NOT build or check project changes. If you do changes in project source files, they will not be reflected in a debug session until you switch back to “PIO Debug” configuration or manually run “Pre-Debug” task.
This configuration is very useful for quick debug session. It is super fast and skips different checks. You manually control project changes.
Note
Please note that PIO Unified Debugger will use the first declared build environment in “platformio.ini” (Project Configuration File) if env_default option is not specified.
Currently, VSCode does not provide UI/API to change variable format. See related VSCode Issue #28025.
Temporary solution is to set the default numeric base in which the debugger displays numeric output using Debug Console (you will see it during active debugging session). For example, show variables in hexadecimal format (copy below and paste into “Debug Console”):
set output-radix 16
Possible values, listed in decimal base, are: 8, 10, 16.
Please read GDB: Setting Watchpoints before.
Currently, VSCode does not provide an API to change value format of watch points. You can manually cast output setting it as a watch of a pointer:
$pc
, default decimal integer format
*0x10012000
, an address, default decimal integer format
(void*)$pc
, $pc register, hexadecimal format
*(void**)0x10012000
, an address, hexadecimal format
Please navigate to PIO Core Install Shell Commands.
How to configure VSCode settings?
platformio-ide.activateOnlyOnPlatformIOProject
¶Activate extension only when PlatformIO-based project (with “platformio.ini” (Project Configuration File))
is opened in workspace, default value is false
.
platformio-ide.autoCloseSerialMonitor
¶Automatically close platformio device monitor before uploading/testing,
default value is true
.
platformio-ide.autoRebuildAutocompleteIndex
¶Automatically rebuild C/C++ Project Index when “platformio.ini” (Project Configuration File) is changed
or when new libraries are installed, default value is true
.
platformio-ide.buildTask
¶A build task (label) which is used by “Build” button in the
PlatformIO Toolbar and Key Bindings. Default is set to
PlatformIO: Build
.
You can create custom Custom Tasks and assign to platformio-ide.buildTask
.
platformio-ide.customPATH
¶Custom PATH for platformio
command. Paste here the result of echo $PATH
(Unix) / echo %PATH%
(Windows) command by typing into your system terminal
if you prefer to use custom version of PlatformIO Core (CLI), default value is null
.
platformio-ide.forceUploadAndMonitor
¶Force “Upload and Monitor” task for Upload (platformio-ide.upload
) command,
default value is false
.
platformio-ide.reopenSerialMonitorDelay
¶Configure time in milliseconds after which reopen Serial Port Monitor,
default value is 0
, which means reopen instantly.
platformio-ide.updateTerminalPathConfiguration
¶Update Terminal configuration with patched PATH environment, default value
is true
.
platformio-ide.useBuiltinPIOCore
¶Use built-in PlatformIO Core (CLI), default value is true
.
platformio-ide.useDevelopmentPIOCore
¶Use development version of PlatformIO Core (CLI), default value is false
.
This is a known bug in VSCode Terminal issue #61.
A temporary solution is to install packages using a system terminal (not VSCode Terminal). Please use “Solution 3: Run from Terminal” in FAQ > Package Manager > [Error 5] Access is denied.
Now, back to VSCode.
Please visit releases page.