Skip to main content

PlatformIO for Robotics

info

Writing and building your robot software is one thing, compiling and flashing your robot firmware is another. Luckily PlatformIO is available as a natural evolution from ArduinoIDE to help you get up an running in no time with flashing your firmware locally, remotely, and anything in between.

PlatformIO in VSCode

  • this setup allows you to flash your robot firmware to an arduino directly from your VC Code

PC setup

  • Follow PlatformIO IDE for latest installation instructions as VS Code extension

Register for PlatformIO account

  • in VSCode press Ctrl+Shift+P
  • type in > PlaformIO: Home
  • register for account on the home page

New PlatformIO project

  • start a new PlatformIO terminal

    • press: ctrl+shift+p in VS Code and enter 'PlatformIO: New Terminal'
  • from the PlatformIO terminal create new project folder

mkdir myPioProject

  • change into the folder

cd myPioProject

pio project init --board <board> - select board from Development Boards

  • create file in src called main.cxx (i.e. main.c if usin C code or main.cpp if using C++)

touch src/main.cpp

  • write your code

  • build code to check if correct

pio run

  • deploy to a connected board (i.e. Arduino)
tip

It is also possible to use the popular Teensy board. However this requies a few additional steps:

  • upload the code

pio run --target upload

  • if only one board is connected then pio will automatically find the board, if more borads are connected then add

upload_port = <port> - port can be for example /dev/ttyACM0 (Linux) or COM3 (Windows)

Remote PlatformIO Development

  • allows remote connection and flashing of microcontrollers on the edge umožní vzdáleně

Login to PlatformIO account

pio account login

Setup the host machine

  • this is for example the RPi to which arduino is connected
  • install PlatformIO CLI on RPi

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

python3 get-platformio.py

  • update and install required dependencies

sudo apt update && sudo apt -y upgrade

sudo apt install python3-pip libffi-dev libssl-dev

  • add PIO to your path so that it can be launched in the CLI
    • edit ~/.bashrc in your home directory and add the following line: export PATH=$PATH:$HOME/.platformio/penv/bin
  • you will need to source your .bashrc or logout/login (or restart the terminal) for the changes to take effect. To source your .bashrc, simply type source ~/.bashrc
  • login to PlatformIO account

pio account login

  • start pio remote agent
    • this might take a couple of minutes to install everything and launch

pio remote agent start --name <nameICanRemember>

  • this should start a remote agent with ouput like so:

2022-02-22 09:16:56 [info] Name: <nameICanRemember>
2022-02-22 09:16:56 [info] Connecting to PlatformIO Remote Development Cloud
2022-02-22 09:16:56 [info] Successfully connected
2022-02-22 09:16:56 [info] Authenticating
2022-02-22 09:16:57 [info] Successfully authorized

danger

Make sure you install UDEV Rules for Teensy boards if you want to use Teensy boards.

Setup the dev machine

  • this is the PC or laptop you are using for development
  • open PlatformIO terminal and install remote agent utils

pio remote agent

  • list available remote agents

pio remote agent list

  • this should list all the available agents on the network

  • deploy and flash on remote agent

pio remote run --target upload