What Is PlatformIO?

PlatformIO is an extension for Visual Studio Code that lets you run and debug code for embedded systems. It currently supports 1,395 development boards from all kinds of manufacturers, letting you use it for more than just the Arduino. Comparing PlatformIO to the Arduino IDE can be more like a “use it and you’ll know it” kind of thing. In my opinion, it’s definitely better because you can add more features to it, like better C/C++ linters, autocomplete, and even MicroPython support. It also supports Git, which is good if you work in teams.

Installing PlatformIO

Coding With PlatformIO

Compared to the Arduino IDE, coding with PlatformIO requires a few extra steps. For this example, we’ll use an Arduino Uno and make it blink its internal LED.

Find Where to Code

You should be ready to program your Arduino after you press that button. To start coding, you have to go to “src -> main.cpp”. This opens a file with the following code: Looks familiar? That’s the thing that shows up on the Arduino IDE as soon as you open it. There’s just one difference: it says #include <Arduino.h> at line 1. The reason is simple. You’re coding with pure C++ now. PlatformIO shows all of the hidden things you never see while using the Arduino programming language. That’s also why you get to see all those new folders to the left. They’re there for you to do stuff on. On the other hand, the Arduino IDE only lets you program Arduino boards with the Arduino programming language, which is based on C++. With that over, let’s make the Arduino blink its internal LED!

Uploading to Arduino

Like in the Arduino IDE, PlatformIO allows you to either Build or Build and Upload your Arduino program to your board. In the blue bar under Visual Studio Code, you should see a check and arrow next to the house icon. The check icon lets you build your code and see if there are any problems while converting it into machine code. Meanwhile, the arrow icon lets you build your current code and then upload it straight to your board (assuming that it’s connected to your computer). The next two buttons let you delete the current saved build (trash can icon) from your computer and do a unit test (flask icon) on your board.

Try an External LED

With that out of the way, your Arduino’s built-in LED should start blinking once every second. If you really want to see it work on an external LED, then you should try putting an LED and a 250 Ω resistor between the pin 13 and GND in series.

Use the Serial Monitor

An IDE for embedded systems is not an IDE if it doesn’t have a serial monitor. Press the plug icon to open the serial monitor. It will open a new terminal process that shows you whatever your board wants to tell you. In this case, our Blink code should make the Arduino say “One cycle of on and off LED” on the serial monitor after each blink cycle. Slightly longer answer: You can program Arduino and many other boards with PlatformIO for your business. But they also offer an in-house IDE solution for businesses in PIO Labs.