Introducing PlatformIO for ESP8266




Introduction: Introducing PlatformIO for ESP8266

About: Just me!

The ESP8266 revolutionized the IoT development, specially with the Arduino IDE port!

But although the Arduino IDE is simple to use, it is not the best ti use. PlatformIO is one ofthe available options if you are looking for a good IDE.

I started to play with the ESP8266 using the Arduino IDE then I decided to use something different for my home automation project.

Here is step-by-step to get it working under Windows.

Step 1: Download & Install PlatformIO IDE

  1. Just go there or just download the IDE for Windows.
  2. Install the IDE.
  3. When asked click 'Reload Now'.
  4. Open any ESP8266 project Menu -> PlatformIO -> Project Example (WiFiScan.ino will do)
  5. Click "Enable" for Smart code Linter.
  6. When asked to install Clang (for Intelligent Code Autocompletion - a nice-to-have!) go ahead & install LLVM:
    1. Go down to "Pre-Built Binaries:"
    2. Select 32 or 64 version, depending on your Windows installation.
    3. Select “Add LLVM to the system PATH” option on the installation step.
    4. You may need to correct the 'Path' (not ('PATH'!!) environment variable for Clang to work properly with PlatformIO.
  7. Restart PlatformIO to finish the installation.

Step 2: Compiling & Uploading an Example Project

  1. Connect your ESP8266 board.
  2. Make sure that your board's COM port by going to Menu -> PlatformIO -> List Serial Ports.
  3. Press the 'Arrow' button on the right corner & you should have WiFiScan.ino compiled & uploaded to the board.
  4. Open the Serial port by going to Menu -> PlatformIO -> Serial Monitor & select the right COM port & 115200 for the Baudrate.
  5. You should get a list of the nearby Access Points with their signal strengths.

Step 3: Writing Our First Program (Blink of Course!)

  1. Create a new project by going to Menu -> PlatformIO -> Initialize or Update PlatformIO Project
  2. Right-click "src" & Add new file "Blink.ino"
  3. Add the regular blink code:
#include <Arduino.h>

void setup(/* arguments */) {
pinMode(BUILTIN_LED, OUTPUT); } int i=HIGH; void loop(){
digitalWrite(BUILTIN_LED, i);

Click the "Arrow" key on the left side & the built-in led should be blinking.

(You may also have the Serial Monitor on)

Step 4: Using Libraries

We need to use the Command Line Library Manager, Menu -> PlatformIO -> Library Manager

pio lib search DHT

10 Libraries will be found & we'll install Adafruit DHT Unified which is #[18] in the list.

So we'll install it by:

pio lib -g install 18

The Library Manager will install all the dependencies needed to the global (-g) library storage folder so that it may be used by any project.

Step 5: Writing a Simple Program Using the DHT Library

We'll use the DHT library we just installed.

Normally I split my projects in multiple files for better organization of the project to make things easy during the development and easy reuse of repetitive functions.

I'll split this project into two files:

  • Main part (with setup & loop).
  • DHT routines.
  1. Create a new project call it DHTtest: Menu -> PlatformIO -> Initialize or Update PlatformIO Project
  2. In the src folder add a new file name it: main.ino with the below code:

    #include <Arduino.h>

    void setup(){
    } void loop(){
    Serial.print("Temperature = "); Serial.print(ReadT());Serial.println(" C");
    Serial.print("Humidity = "); Serial.print(ReadH());Serial.println(" %");
  3. In the src folder add another file name it: DHTfunctions.ino with the below code:

    #include <DHT.h>

    #define DHTPIN D3
    #define DHTTYPE DHT21 // I'm using DHT21


    void DHTstart(){
    dht.begin(); }

    float ReadT(){
    float t = dht.readTemperature();
    return t;

    float ReadH(){
    float h = dht.readHumidity();
    return h;
  4. Compile & upload the project &open the Serial Monitor to check the result.

Be the First to Share


    • Leather Challenge

      Leather Challenge
    • Tinkercad to Fusion 360 Challenge

      Tinkercad to Fusion 360 Challenge
    • Digital Fabrication Student Design Challenge

      Digital Fabrication Student Design Challenge



    2 years ago

    doesn´t seem to work like this anymore


    5 years ago


    very good description, very helpful regarding PlatformIO

    Only the fact thethe project is divided in 2 files is clear.

    The "functions" on never start.: "Humidity= nan%" no measurments.

    Any idea?



    Reply 5 years ago

    Did you include the proper DHT library? it should be "Adafruit DHT Unified"


    Reply 4 years ago


    Thank you for your answer which I never saw....1 year!!!

    I don't know anymore my problem at that time but I'll dig into in the next days.

    Thanks again


    5 years ago

    Are the libraries the same as the Arduino IDE or are we dependent on "special" libraries being created for this platform?


    Reply 5 years ago

    As per the documentations all standard libraries are supported & easily updated too to latest versions.

    Other libraries I am not sure - normally I am adding the libraries to my projects manually.

    DIY Hacks and How Tos

    Interesting. I had never heard of that system before. I am going to have to check it out.


    Reply 5 years ago

    It is way better than the Arduino IDE.