Frequently Asked Questions

Note

We have a big database with Frequently Asked Questions in our Community Forums. Please have a look at it.

General

What is PlatformIO?

Please refer to What is PlatformIO?

What is .pio directory

Please refer to workspace_dir.

What is .pioenvs directory

Please refer to build_dir.

Command completion in Terminal

Bash completion

Bash completion support will complete subcommands and parameters. To enable Bash completion for platformio subcommands you need to put into your .bashrc:

eval "$(_PLATFORMIO_COMPLETE=source platformio)"
eval "$(_PIO_COMPLETE=source pio)"

ZSH completion

To enable zsh completion please run these commands:

autoload bashcompinit && bashcompinit
eval "$(_PLATFORMIO_COMPLETE=source platformio)"
eval "$(_PIO_COMPLETE=source pio)"

Note

For permanent command completion you need to place commands above to ~/.bashrc or ~/.zshrc file.

Install Python Interpreter

PlatformIO Core (CLI) is written in Python that is installed by default on the all popular OS except Windows.

Windows Users, please Download the latest Python and install it. DON’T FORGET to select Add python.exe to Path feature on the “Customize” stage, otherwise, python command will not be available.

../_images/python-installer-add-path.png

Convert Arduino file to C++ manually

Some Cloud & Desktop IDE doesn’t support Arduino files (*.ino and .pde) because they are not valid C/C++ based source files:

  1. Missing includes such as #include <Arduino.h>

  2. Function declarations are omitted.

In this case, code completion and code linting do not work properly or are disabled. To avoid this issue you can manually convert your INO files to CPP.

For example, we have the next Demo.ino file:

void setup () {
    someFunction(13);
}

void loop() {
    delay(1000);
}

void someFunction(int num) {
}

Let’s convert it to Demo.cpp:

  1. Add #include <Arduino.h> at the top of the source file

  2. Declare each custom function (excluding built-in, such as setup and loop) before it will be called.

The final Demo.cpp:

#include <Arduino.h>

void someFunction(int num);

void setup () {
    someFunction(13);
}

void loop() {
    delay(1000);
}

void someFunction(int num) {
}

Finish.

Program Memory Usage

PlatformIO calculates firmware/program memory usage based on the next segments:

.text:

The code segment, also known as a text segment or simply as text, is where a portion of an object file or the corresponding section of the program’s virtual address space that contains executable instructions is stored and is generally read-only and fixed size.

.data:

The .data segment contains any global or static variables which have a pre-defined value and can be modified. The values for these variables are initially stored within the read-only memory (typically within .text) and are copied into the .data segment during the start-up routine of the program. Example,

int val = 3;
char string[] = "Hello World";
.bss:

Uninitialized data is usually adjacent to the data segment. The BSS segment contains all global variables and static variables that are initialized to zero or do not have explicit initialization in the source code. For instance, a variable defined as static int i; would be contained in the BSS segment.

The rough calculation could be done as:

  • PROGRAM (Flash) = .text + .data

  • DATA (RAM) = .bss + .data

If you need to print all memory sections and addresses, please use platformio run --verbose command.

Recommended for reading:

Troubleshooting

Installation

Multiple PIO Cores in a system

Multiple standalone PlatformIO Core (CLI) in a system could lead to the different issues. We highly recommend to keep one instance of PIO Core or use built-in PIO Core in PlatformIO IDE:

Finally, if you have a standalone PlatformIO Core (CLI) in a system, please open system Terminal (not PlatformIO IDE Terminal) and uninstall obsolete PIO Core:

pip uninstall platformio

# if you used macOS "brew"
brew uninstall platformio

If you need to have PlatformIO Core (CLI) globally in a system, please Install Shell Commands.

‘platformio’ is not recognized as an internal or external command

If you use PlatformIO IDE, please check in PlatformIO IDE Settings that “Use built-in PIO Core” is enabled.

If you modify system environment variable PATH in your Bash/Fish/ZSH profile, please do not override global PATH. This line export PATH="/my/custom/path" is incorrect. Use export PATH="/my/custom/path":$PATH instead.

99-platformio-udev.rules

Linux users have to install udev rules for PlatformIO supported boards/devices. The latest version of rules may be found at https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules

Note

Please check that your board’s PID and VID are listed in the rules. You can list connected devices and their PID/VID using platformio device list command.

This file must be placed at /etc/udev/rules.d/99-platformio-udev.rules (preferred location) or /lib/udev/rules.d/99-platformio-udev.rules (required on some broken systems).

Please open system Terminal and type

# Recommended
curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules

# OR, manually download and copy this file to destination folder
sudo cp 99-platformio-udev.rules /etc/udev/rules.d/99-platformio-udev.rules

Restart “udev” management tool:

sudo service udev restart

# or

sudo udevadm control --reload-rules
sudo udevadm trigger

Ubuntu/Debian users may need to add own “username” to the “dialout” group if they are not “root”, doing this issuing

sudo usermod -a -G dialout $USER
sudo usermod -a -G plugdev $USER

Note

You will need to log out and log back in again (or reboot) for the user group changes to take effect.

After this file is installed, physically unplug and reconnect your board.

ImportError: cannot import name _remove_dead_weakref

Windows users can experience this issue when multiple Python interpreters are installed in a system and conflict each other. The easy way to fix this problem is uninstalling all Python interpreters using Windows Programs Manager and installing them manually again.

  1. “Windows > Start Menu > Settings > System > Apps & Features”, select Python interpreters and uninstall them.

  2. Install the latest Python interpreter, see Install Python Interpreter guide

  3. Remove C:\Users\YourUserName\.platformio and C:\.platformio folders if exist (do not forget to replace “YourUserName” with the real user name)

  4. Restart PlatformIO IDE.

Package Manager

[Error 5] Access is denied

PlatformIO installs all packages to “core_dir/packages” directory. You MUST HAVE write access to this folder. Please note that PlatformIO does not require “sudo”/administrative privileges.

Solution 1: Remove folder

A quick solution is to remove “core_dir/packages” folder and repeat installation/building/uploading again.

Solution 2: Antivirus

Some antivirus tools forbid programs to create files in the background. PlatformIO Package Manager does all work in the background: downloads package, unpacks archive in temporary folder and moves final files to “core_dir/packages” folder.

Antivirus tool can block PlatformIO, that is why you see “[Error 5] Access is denied”. Try to disable it for a while or add core_dir directory to exclusion/whitelist.

Solution 3: Run from Terminal

As we mentioned in “Solution 2”, antivirus tools can block background file system operations. Another solution is to run PlatformIO Core (CLI) from a system terminal.

  1. Open System Terminal, on Windows cmd.exe (not PlatformIO IDE Terminal)

  2. Build a project and upload firmware using PlatformIO Core (CLI) which will download and install all dependent packages:

    # Change directory to PlatformIO Project where is located "platformio.ini"
    cd path/to/platformio/project
    
    # Force PlatformIO to install PIO Home dependencies
    platformio home
    
    # Force PlatformIO to install toolchains
    platformio run --target upload
    

If “platformio” command is not globally available in your environment and you use PlatformIO IDE, please use built-in PlatformIO Core (CLI) which is located in:

  • Windows: C:\Users\{username}\.platformio\penv\Scripts\platformio Please replace {username} with a real user name

  • Unix: ~/.platformio/penv/bin/platformio

Note

You can add platformio and pio commands to your system environment. See Install Shell Commands.

Solution 4: Manual

If none of the solutions above do work for you, you can download and unpack all packages manually to “core_dir/packages”.

Please visit PlatformIO Package Storage and download a package for your platform. A correct package path is “core_dir/packages/{package_name}/package.json”.

Building

UnicodeWarning: Unicode equal comparison failed

Full warning message is “UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal”.

KNOWN ISSUE. Please move your project to a folder which full path does not contain non-ASCII chars.

UnicodeDecodeError: Non-ASCII characters found in build environment

KNOWN ISSUE. PlatformIO Core (CLI) currently does not support projects which contain non-ASCII characters (codes) in a full path or depend on the libraries which use non-ASCII characters in their names.

TEMPORARY SOLUTION

  1. Use PlatformIO IDE, it will automatically install PlatformIO Core (CLI) in a root of system disk (%DISK%/.platformio) and avoid an issue when system User contains non-ASCII characters

  2. Do not use non-ASCII characters in project folder name or its parent folders.

Also, if you want to place PlatformIO Core (CLI) in own location, see:

ARM toolchain: cc1plus: error while loading shared libraries

See related answers for error while loading shared libraries.

Archlinux: libncurses.so.5: cannot open shared object file

Answered in issue #291.

Monitoring a serial port breaks upload

Answered in issue #384.