Skip to content

Configure Platformio

Read first: Install Platformio

PlatformIO projects have a configuration file called platformio.ini. It is located in the root folder of the project. In this file we indicate which hardware (microcontroller) we have connected to the computer and PlatformIO will select the tools needed to compile and upload the code.

Create your platformio.ini file

The first time you download the source code you may find it renamed to platformio.sample.ini . As the name implies, this is just a sample configuration.

You must duplicate (not delete) the file removing ".sample" part so that it remains platformio.ini.

before
platformio.sample.ini

after
platformio.ini

This configuration file can be very powerful for advanced users, please read official docs.

Default sample file

The default platformio.ini file may look like this:

[user]
upload_port = SELECT_PORT
monitor_port = SELECT_PORT
monitor_speed = 115200

[platformio]
default_envs = esp32

; you shouldn't edit from here

[common]
lib_deps =
  SparkFun BME280
  1655
  19
  https://github.com/timotto/Readline

[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
upload_port = ${user.upload_port}
monitor_port = ${user.monitor_port}
monitor_speed = ${user.monitor_speed}
lib_deps = ${common.lib_deps}
monitor_filters = esp32_exception_decoder

[env:zeroUSB]
platform = atmelsam
board = zeroUSB
framework = arduino
upload_port = ${user.upload_port}
monitor_port = ${user.monitor_port}
monitor_speed = ${user.monitor_speed}
lib_deps =
  ${common.lib_deps}
  FlashStorage

[env:espressif8266]
platform = espressif8266
board = esp_wroom_02
framework = arduino
monitor_port = ${user.monitor_port}
monitor_speed = ${user.monitor_speed}

[env:uno]
platform = atmelavr
framework = arduino
board = uno
monitor_port = ${user.monitor_port}
monitor_speed = ${user.monitor_speed}
lib_deps = ${common.lib_deps}

[env:mega]
platform = atmelavr
board = megaatmega2560
framework = arduino
upload_port = ${user.upload_port}
monitor_port = ${user.monitor_port}
monitor_speed = ${user.monitor_speed}
lib_deps = ${common.lib_deps}

Normally you will only need to edit this file once, during the first setup, but sometimes we need to go back and make small changes, such as adjusting the COM ports.

Section [user]

This is the only configuration than a normal user should change.

Each microcontroller has its own configuration section (see below) and with [user] we have some global parameters for all of them.

[user]
upload_port = COM11 ; Set your com port, /dev/tty on unix
monitor_port = COM11 ; Serial Monitor, /dev/tty on unix
monitor_speed = 115200

Section [platformio]

[platformio]
default_envs = esp32 ; Set our microcontroller

With default_envs we can stablish the hardware configuration on build and upload the code. Platformio will read the [env:] section for this hardware.

On the previously example:

[platformio]
default_envs = esp32

PlatformIO will load:

[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
upload_port = ${common.upload_port}
monitor_port = ${common.monitor_port}
monitor_speed = ${common.monitor_speed}
lib_deps = ${common.lib_deps}
monitor_filters = esp32_exception_decoder

If you are working with a Duino Zero configure it like:

[platformio]
default_envs = zeroUSB

and PlatformIO will use:

[env:zeroUSB]
platform = atmelsam
board = zeroUSB
framework = arduino
upload_port = ${common.upload_port}
monitor_port = ${common.monitor_port}
monitor_speed = ${common.monitor_speed}
lib_deps =
  ${common.lib_deps}
  FlashStorage

There is information about lib_deps in the Devs Documentation.

Configure your default_envs

Select your microcontroller before build/upload

[platformio]
default_envs = esp32
[platformio]
default_envs = espressif8266
[platformio]
default_envs = zeroUSB
[platformio]
default_envs = uno
[platformio]
default_envs = mega
[platformio]
default_envs = leonardo

Section [common]

Contains the dependencies of rhomb.IoT. PlatformIO will try to download this libraries from internet

[common]
lib_deps =
  SparkFun BME280
  1655
  19
  https://github.com/timotto/Readline

Comments