The Arduino IDE has become the first programming experience for many people. While it gets the job done, it lacks key features found in most modern code editors.
Visual Studio Code (VS Code) has quickly become one of the most popular code editors but does not support Arduino development as a standard.
Enter PlatformIO, an open source tool for programming Arduino boards (and more)! Learn how to get PlatformIO and use it to create a simple Arduino sketch in VS Code.
You will need:
- Arduino compatible board. This tutorial uses a nano-clone.
- The Arduino IDE is available from the Arduino website (free).
- Visual Studio Code, available from Microsoft (free).
Today’s guide is for Windows 10, but it should also work on Linux and Mac.
Note. Arduino IDE version for Windows 10 will not work with this guide.
How to install PlatformIO
VS Code has many extensions to help programmers, and PlatformIO is no different. Open the VS Code Extensions Marketplace from the left pane and find PlatformIO IDE . Click «Install» and be prepared for a short wait.
Note . Do not close VS Code during this process, as this may result in installation errors.
Once the installation is complete, a prompt will appear in the bottom right corner to reload VS Code. Click on it and the program will restart showing the home page of the PlatformIO extension.
The PlatformIO home page has several options, including opening existing Arduino projects and links to project ideas. Today you will start from scratch, so click » New project» .
You will be prompted to enter a name for your project and the board you will be using. This tutorial uses an Arduino Nano; PlatformIO supports over 650 boards, so you’ll most likely find yours on the list.
Tab Framework should automatically fill in as arduino, if you are using an Arduino compatible board. Leave the checkbox » Location» filled in to use the default installation location. You only need to uncheck this box if you are working with a previously made Arduino project.
Click Ready and be prepared for a short wait. PlatformIO will download and install all the dependencies needed for the project and restart the IDE when it’s finished.
Once VS Code restarts, you will see the new project folder open in the panel explorer . At this point it is not necessary to know what each file in that directory does, you will use the directory SRC only for your Arduino sketches.
You’ll also notice a few new icons in the bottom bar of VS Code. This is the equivalent of the buttons in the Arduino IDE — a checkbox for compiling, an arrow for downloading, and a blank for the serial monitor.