Install PlatformIO Core on Ubuntu 20.04

Install PlatformIO Core on Ubuntu 20.04

PlatformIO Core is a command line tool to develop applications for embedded systems. This tool allows to manage libraries, build projects, upload firmware to development boards, and more.

This tutorial explains how to install PlatformIO Core on Ubuntu 20.04.

Install PlatformIO Core

Download installation script:

wget -q https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py

Install PlatformIO Core:

sudo PLATFORMIO_CORE_DIR=/opt/platformio python3 get-platformio.py

We can create a symbolic link to the pio command in /usr/local/bin directory:

sudo ln -s /opt/platformio/penv/bin/pio /usr/local/bin/pio

Now pio can be used as a system-wide command for all users.

By default, root and user with sudo privileges can read and write to a serial port. So if you want to allow to upload program to the device for non-root users, you can add user to the dialout group.

Add current user to dialout group:

sudo usermod -a -G dialout $USER

To make changes to take effect, logout and login to your machine. After you're reconnected, check PlatformIO Core version:

pio --version

Remove installation script and cache that created during installation:

rm -rf get-platformio.py
sudo find /root/.cache -iname "*platformio*" -delete

Testing PlatformIO Core

Create a new directory to store project files and navigate to this directory:

mkdir helloworld && cd helloworld

The pio project init command allows to initialize a new PlatformIO based project. For example, the following command initializes project for ESP8266 NodeMCU development board:

pio project init --board nodemcuv2

Next, create a main.cpp file:

nano src/main.cpp

Add the following code:

helloworld/src/main.cpp

#include <Arduino.h>

void setup()
{
}

void loop()
{
}

Connect ESP8266 NodeMCU development board to the USB port. Build project and upload program to the device:

pio run --target upload

Uninstall PlatformIO Core

Remove PlatformIO Core installation directory:

sudo rm -rf /opt/platformio

Remove symbolic link:

sudo rm -rf /usr/local/bin/pio

You can also remove PlatformIO Core data:

rm -rf ~/.platformio

Leave a Comment

Cancel reply

Your email address will not be published.