Programming ESP8266 using VSCode and PlatformIO

In this tutorial, I am going to show you how to install the PlatformIO extension on VSCode, as well as some packages.

PlatformIO is a cross-platform build system that can be used to develop software for Arduino, ESP32, ESP8266, PIC 32, among other platforms. In this tutorial, PlatformIO will be used as a VSCode extension, providing a powerful set of tools to the developer. When developing applications specifically for ESP family modules, and if configuration flexibility is needed, there are other options available, namely the one described in one of our previous tutorials called “Build, Flash and Monitor ESP32 using VSCode“.

Parts Required

Installing PlatformIO IDE on VSCode

Confirm that you have Python 3.6 (or higher version) installed on your computer, as well as Visual Studio Code and then go through the following steps:

1. Open VSCode.

test 01

2. On the side bar click in “Extensions” or (Ctrl+Shift+X).

3. Search for “PlatformIO IDE” and click on install.

4. Check the side bar for “PlatformIO IDE” icon (means that the installation was successful).

5. After reboot VSCode, the home page of “PlatformIO” should appear.

If the home page does not appear, open it using the side bar.

Adding an Embedded Platform

To open a project example like blink, you need to install the platform required for the microcontroller that you will be programming. In this case, we need to install the “Embedded Platform” for ESP8266. Note: The following steps can also be used, in case you want to work with other embedded platforms available on PlatformIO, e.g. ESP32 boards.

1. When selecting “Project Examples” option if it is not installed any “Embedded Platform”, select “Install Embedded Platform”.

2. In “Platforms” section inside of “PlatformIO IDE” on the “Embedded” tab, all platforms available to install will be listed, as well as the supported microcontrollers.

3. Search for “esp”.

4. Open “Espressif 8266” and select install.

When the istallation process is completed, the following popup will appear. Click “OK”.

5. Go to “Home” section and click on “Project Examples”. Now select the pretended example “arduino-blink”.

Note: In projects examples names, the first word will be the framework used (like Arduino, for example).

Project Configurations and Board Programming

In order to programming your development board, you need to build and upload the project. Before that, it is shown where the file with the main code is located and some project settings.

1. In explorer you can see various folders. The main file containing the code you want to run is in the “src” folder.

2. In the “platformio.ini” file you can find and change the environment configurations for your development board.

3. On PlatformIO all environments found in the file “platform.ini” can be viewed.

4. Now choose the environment that suits the development board you are using. (In this example, the development board used was “Wemos NodeMCU ESP8266” and the appropriate environment is “nodemcuv2”.) Now just “Build” the project and “Upload” to your board.

Note: After building the project, a “[SUCCESS]” message should appear in your terminal (as shown in the following image). The same should happen for the upload process.

Example of successful “Build” process.
Example of successful “Upload” process.

1 thought on “Programming ESP8266 using VSCode and PlatformIO

  1. I’ve been waiting for a tutorial like this for a long time. Very complete and completely useful. Congratulations on the publication.

Leave a Reply

Your email address will not be published. Required fields are marked *