Installing PlatformIO

Overview

Teaching: 0 min
Exercises: 45 min
Questions
  • How will I manage extensive Arduino libraries?

  • What are the benefits of a code text editor?

  • How can I easily compare two codes files?

  • Which buttons do I push in PlatformIO?

Objectives
  • Download PlatformIO and VSCode. Test PlatformIO.

Episode 4: Installing PlatformIO

In this lesson we will prepare you to use PlatformIO, an Integrated Development Environment (IDE) for Internet of Things (IoT). PlatformIO IDE is extremely helpful (and we believe necessary) for keeping track of libraries and code differences when programming a data logger with the EnviroDIY Modular Sensors library. You will install PlatformIO, and become acquainted with many of its features, including file management, syntax highlighting, code difference tracking, code debugging, library management, and integration with Arduino and GitHub.

VSCode and PlatformIO

PlatformIO IDE is hosted within a text editor designed for editing code. Most code text editors highlight syntax and have special auto-complete and debugging features based on elements of the code. PlatformIO can be hosted by several text editors, so if you are a coder and already use VSCode or Sublime, please feel free to install PlatformIO for your favorite editor. The original combination was PlatformIO hosted within VSCode text editor. Since Microsoft took ownership of GitHub, their VSCode has become the “recommended” download for PlatformIO (we used to use Atom, but have found that support for Atom is dwindling). If you choose a different text editor, some of the buttons and commands will be located in different places, but all of the functionality will be preserved.

What you can see in PlatformIO

In the following sections we will take you on a tour through the PlatformIO user interface to describe which features of PlatformIO you will need for using EnviroDIY Modular Sensors sketches.

PlatformIO Toolbar:

Source and Destination Files

PlatformIO Home. This is where you will manage software updates for PlatformIO and other libraries that PlatformIO sees you using. You will know when updates are needed because they will be marked with bright badges. You also create a PlatformIO account here, which you need if you use some of the development capabilities (not necessary as you get started).

Projects. All of your Arduino work will be stored as projects. Once you add a project in PlatformIO, you will have more menu items across the bottom bar of the VSCode window. You may have work open from multiple projects at a time.

Inspect. Details about each of your projects will be here, including memory usage and debugging information.

Libraries. This makes it easy for you to see the libraries and versions that are currently installed in your project. PlatformIO manages the libraries for your Arduino projects.

Boards. Many Arduino framework microcontroller boards are listed here as pre-configured boards. This means that PlatformIO will know your board’s platform, memory, and clock frequency. If you are using the EnviroDIY Mayfly, you will select that board here.

Devices. Each Arduino board that you connect to your computer will have a unique port assignment. On a PC this will be a COM + a number. On a Mac this will be a character string containing USB.

Home (house icon). This is the most direct way to go the PlatformIO Home in VSCode. When you have a project installed/open, there will be several more PlatformIO icons next to this Home icon, and these are the tools you will use most for your Arduino work, as shown below. This is where you will manage software updates for PlatformIO and other libraries that PlatformIO sees you using. You will know when updates are needed because they will be marked with bright badges. You also create a PlatformIO account here, which you need if you use some of the development capabilities (not necessary as you get started).

Source and Destination Files

The Bar of EVERYTHING:

Build (checkmark). This is the button you push when your sketch is ready and your platformio.ini is pointing to all of the right files and repositories for your sketch. This process will list color-coded errors (and successes) as it runs the build. I have found that the error messages are usually pretty understandable and repairable, so keep calm and READ THE MESSAGES. Red error messages will not allow you to proceed. Yellow error messages will allow you to proceed.

Upload (right arrow). This is the button that will send your sketch to your Arduino board. You need to Build before you Upload.

Clean (trash can). This removes previously compiled files and can be helpful to clear any compile errors. The only downside is that it will need to recompile all files, which can take a bit longer to complete.

Serial Monitor (power plug). This is your window into what’s happening on your Arduino board. The print statements that update you regarding the progress of your sketch show up here. Every time I upload a sketch this is where I see if it’s working correctly.

Terminal (cursor box). Command line access to the functions of PlatformIO. I use this when my pushes to GitHub create conflicts (while sharing a repository with others). You may not need to use this.

Project Environment (file folder). One of the most important things to notice in the PlatformIO environment is this directory name. This directory indicates which project is the active project, meaning that the platformio.ini file in the root directory of that project is where PlatformIO will look for instructions. You could have a dozen files open in PlatformIO, but the one named in the platformio.ini file in this directory is the only one that will Build and Upload. In the screen shot provided “EnfiorDIY_deployments” is the active project.

Explorer

This is basically Finder/Windows Explorer conveniently located right in PlatformIO. You can add, move, copy, and delete files and folders in this tab. Right-clicking on any of the items in your project will give you a list of possible actions. I also frequently use the “Copy Relative Path” option for naming the source directories in my platformio.ini file.

In the next episode, we will start uploading code to the Mayfly!

Key Points

  • PlatformIO provides an Integrated Development Environment (IDE) that combines all the capabilities of the Arduino IDE along with many advanced capabilities of a code editor that you will come to appreciate.