Maker.io main logo

Get Started with PlatformIO for Your Next Arduino Project

2022-08-10 | By Maker.io Staff

Arduino

The standard Arduino IDE is the first contact point for many new makers venturing out into the world of microcontroller development. While the software is incredibly easy to pick up and get started with, more advanced users will quickly find themselves limited by the beginner-friendly tool. Therefore, this article investigates PlatformIO, an extension for the popular Visual Studio Code development environment that lets its users develop applications for many embedded platforms (such as Arduino-based boards). Beginners will notice that the tool is easy to use, and more advanced users can benefit from a range of powerful tools for boosting their efficiency and code quality.

What is PlatformIO?

The problem with many embedded development tools is that they are platform-dependent and often complicated to learn and use, especially for beginners and hobbyists. In addition, some of these programs may also require users to pay hefty license fees. PlatformIO aims to solve these problems by offering a vendor-independent and simple-to-use IDE that automatically sets up the toolchain for compiling, debugging, and uploading programs.

PlatformIO is not another standalone IDE. Instead, it is an extension for Visual Studio Code, a modern, intuitive, and free-to-use development environment. Therefore, makers and professionals alike can quickly develop embedded applications for an extensive range of hardware development kits, microcontrollers, and standalone development platforms like the Arduino without installing additional editors or setting up any complicated toolchains. In addition, the underlying IDE offers more experienced developers access to advanced features such as source control with GitHub integration, a professional debugging environment, static code analysis with refactoring support, automated unit tests, and typing suggestions for a more streamlined experience. Additional third-party extensions can bring in many more advanced features, for example, CI/CD integration, and add support for other programming languages, such as Python.

PlatformIO supports over 1000 boards, over 40 development platforms, and 20+ frameworks, such as Arduino, Mbed, Zephyr RTOS, and many more.

Installing PlatformIO

When installing PlatformIO, the first step consists of installing VS Code, which can be downloaded from the official website for free. Once done, navigate to the IDE’s extensions tab on the left-hand side of the window. Then, use the search bar to find the PlatformIO IDE package and click the install button.

Get Started with PlatformIO for Your Next Arduino Project Follow these steps to install PlatformIO in Visual Studio Code.

Once the installation finishes, reload the IDE when the program instructs you to do so.

Getting Started with a Simple Hello World Arduino Program

Getting started with PlatformIO is a very smooth process. Once the IDE reloads, click the small home icon in the bottom toolbar of VS Code. Then, use the new project button to open the project configuration dialog.

Get Started with PlatformIO for Your Next Arduino Project Use the home icon to open the PIO home tab. Then, use the new project button to get started with a new Arduino project.

Next, use the project wizard to enter a name and select your development board from the dropdown list. In this case, the dialog already automatically chooses the Arduino framework as the project target. Therefore, you can click the Finish button without changing any other settings.

Get Started with PlatformIO for Your Next Arduino Project Use the project wizard to create a new Arduino project.

The IDE will then download all necessary files and set up the standard toolchain for this project. It might not seem much for typical Arduino projects. However, this step can reduce the complexity of developing embedded applications, especially when creating prototypes for various platforms. Wait for the download to finish, which shouldn’t take longer than a few seconds.

Get Started with PlatformIO for Your Next Arduino Project The IDE downloads and configures all necessary files for the project.

When done, the IDE will display the project’s configuration file (platformio.ini). You can close that file, as there’s no need to change its contents at this point. Instead, use the file explorer on the left-hand side of the window to open the main.cpp file located within the src folder.

Get Started with PlatformIO for Your Next Arduino Project Open the highlighted file using the IDE’s file explorer.

This file contains the standard empty Arduino program that’s also present when creating a new project in the Arduino IDE. Next, add your program logic, and then use the buttons in the bottom menu bar to compile and upload your program.

Get Started with PlatformIO for Your Next Arduino Project Use the highlighted buttons to compile and upload your program. The small plug icon opens the serial monitor.

When uploading the sketch, the IDE automatically detects the serial port and board to use, so there’s nothing more you have to do besides clicking the button.

Summary

PlatformIO is an excellent extension for the popular Visual Studio Code IDE. Besides offering a few features targeting more professional users, PlatformIO is also extremely easy to pick up and get started with, even for absolute beginners.

The development tool supports thousands of boards without requiring the user to install any SDKs, external tools, or compilers manually. Furthermore, it automatically configures the entire toolchain and automatically detects the serial port and device when uploading programs.

Getting started with a new project is only a matter of a few clicks, and the advanced code editing features boost the productivity of beginners and professionals. Let us know what features you’d like us to write about in upcoming blogs and how-to articles!

制造商零件编号 A000066
ARDUINO UNO R3 ATMEGA328P BOARD
Arduino
¥190.97
Details
制造商零件编号 A000073
ARDUINO UNO SMD R3 ATMEGA328
Arduino
¥182.01
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum