DIY Projects

Start with PlatformIO, the alternative IDE for Arduino, ESP8266, ESP32 and other microcontrollers

platformio 3 atom home screen update

PlatformIO IDE is a development environment that can replace the traditional Arduino IDE. PlatformIO supports more than 400 development boards for the main microcontrollers (Atmel AVR, Espressif ESP8266 and ESP32, STMicro STM32, Teensy …). It is not a simple code editor, it is a true development platform that targets the professional market with very powerful tools. For example, it is possible to test the code on different microcontrollers, to deploy the updates remotely via the Internet. It is a solution that addresses the company with a paid offer. PlatformIO is perfectly usable for recreation or learning with a free version (Community) allows to use almost all functions with certain limitations. For example, it is not possible to make more than 50 remote updates (OTAs) per month. This is enough for personal use, start a small business venture or school. The fee schedule is available here.

Installing PlatformIO on MacOS, Windows or Linux

The PlatformIO IDE is an overlay that is added to a code editor or text editor. PIO is offered by default as an Open Source Atom Text Editor package developed by GitHub. Atom is fully developed in Javascript (the language of the Web) and compiled with the help of Electron. Electron is a compiler that allows to create cross-platform applications. The same javascript source code can be compiled to build a Windows, MacOS, Linux application.

Go to this page then download the version of Atom that corresponds to your environment

On macOS, simply unpack the archive and move Atom to the Applications folder. For Linux, only regret, the 32-bit version is no longer supported. It is therefore no longer possible to recycle a (too) old PC to turn it into a development platform.

Installing the PlatformIO package in Atom

Once Atom is installed, you must install the PlatformIO package. Open the preferences. Depending on your operating system, the path is different

In the search box, type platformio-ide. There are 3 packages available:

Install the ide and ide-terminal packages by clicking Install. The installation is silent but you can follow it by flying over the toothed wheel in the lower right corner of the screen. The installation can last a few minutes depending on your internet speed. Stay on this page until the package is marked as installed.

When installation is complete, a new PlatformIO Home tab is added to Atom. This tab can be opened automatically when Atom starts and allows you to manage your projects and update the PlatformIO package and Core. If a new version is available (here version 3.3.1), take advantage of it to update before continuing by clicking on Upgrade NOW !.

The PlatformIO menu and toolbar

A new menu is also added to the Atom menu bar. If you close the Home screen, do not panic, you can re-open it from the menu >> Home Screen.

In menu contains the following options

Install Clang

PlatformIO uses Clang for self-completion of commands. This installation is optional.

New project ESP8266 with PlatformIO

We will now create a small ESP8266 project to understand how the environment works. Compared to the Arduino IDE, PlatformIO sets up a more complex file structure. With the Arduino IDE, just create a new sketch to start a new project. With PlatformIO, it’s not that simple. PlatformIO works with a tree that contains the source code (src), the libraries, the configuration file … Fortunately, there is a tool to prepare all this. Open the menu and select Initialize or Update PlatformIO Project.

This dialog box does two things:

Creating the project structure

To create a new project, select the desired board from the list. You can enter the first few letters to find it easier. Then click Other to the right of the path entry field and select the destination directory.

Warning. Compared to the Arduino IDE, you must create the root folder. Otherwise, the tree and files will be added to the specified level.

Click Process. PlatformIO will retrieve all necessary dependencies and resources for the selected adapter. This is the magic of PlatformIO.

For example, if you want to develop with the new ESP32 boards, you will have nothing to install compared to the Arduino IDE. It is a real comfort. The first time you use a board, you must allow PIO a little time. It must download the resources, install them and in some cases compile.

Here is the resulting projects structure

project_dir
├── lib
│   └── readme.txt
├── platformio.ini
└── src
    └── main.cpp

Let’s take a closer look at the file platformio.ini

[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino

For the moment, it contains only the d1 mini target (Wemos d1 mini). At any time, you can add a target board by running the Initialize or Update PlatformIO Project tool again (recommended) or manually. In this case, all boards are listed here. We will see in more detail all the other options available in an upcoming tutorial.

Arduino Code

Now we have to create our first program. No base file is added. You have to do it yourself. To do this, right click on the scr folder and choose New File.

Give the file a name by giving it the .cpp extension

To run on Arduino, ESP8266, ESP32, you must include the Arduino library at the beginning of the program!

Then, the programming is identical to the Arduino IDE. Here is a small program that flashes a LED connected to the D2 pin of the ESP8266.

[ads1}

/*
 * Demo PlatformIO - ESP8266 - Blink a Led
 * Turns on an LED on for one second, then off for one second, repeatedly.
 * projetsdiy.fr - diyprojects.io
 */

#include <Arduino.h>

#define LED_BUILTIN 4  //or D2 but display an error

void setup()
{
  // initialize LED digital pin as an output.
  Serial.begin(115200);
  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);
  Serial.println("Blink");
   // wait for a second
  delay(1000);
}

Some remarks about the Arduino IDE

Adapt the code to your needs and save it (CTRL + S). Then choose Build from the menu (or use the dedicated icon).

Once the compilation is complete, upload the program.

Now open the serial monitor. Directly from the menu, via the keyboard shortcut Alt + Shift + M or from the icon bar.

Select the COM port on which the board is connected and the speed

You can trace the progress of your programs as on the Arduino IDE.

This completes this first tutorial to discover the PlatformIO development environment. A bit confusing the first time, PIO has many arguments in its favor. Completed the installation of the libraries, the resources of the boards. PIO takes care of everything!

Click to rate this post!
[Total: 0 Average: 0]
Exit mobile version