Almost every microcontroller developer has started or, at least once, used the Arduino Integrated Development Environment (IDE) as a coding platform. In fact, it is an easy and straightforward tool, which integrates most of the available Arduino libraries and facilitates the compilation and upload of the code onto the Arduino board. The Arduino IDE is a good tool for beginner developers or pretty quick and simple implementations. When dealing with more robust and scalable projects, this IDE imposes several drawbacks and may reduce significantly the time and flexibility of the development process.
To try to fulfill this gap, there are other options, such as Eclipse (with Arduino plugin), Programino IDE, EmbedXCode, Atmel Studio, and others. Although, none of them, in my opinion, perform as better as the PlatformIO.
Beyond an IDE, the PlatformIO is an opensource ecosystem for IoT development. The tool contains integrations with multiple platforms, frameworks and boards. When creating a project, we have about 690 already available boards and multiple development frameworks to choose from. Through the home screen, we can easily access the libraries marketplace and search for the library that better suits the needs of the project. Besides, PlatformIO supports unit testing and has seamless integration with GitHub and TravisCI (GitHub CI alternative).
The PlatformIO most commonly integrates with the VisualStudio Code (VSCode), which is an advanced text editor that is available for all the main operational systems such as Windows, Linux and macOS. In order to download the PlatformIO, it is possible to search for it in the VSCode marketplace or download it directly from the website.
Let’s take a look at some of the features available for the PlatformIO!
Right in the ProjectIO home screen, we can see some news and links to the most recent projects. It is possible for us to quickly create a new project, import an already existent Arduino project (*.ino), or open existent projects and examples.
When creating a new project, the user can choose the board and the framework most suitable for the project. After this step, the project will load and the files will be organized based on the structure presented in the image below.
To download a library, in the home screen, go to the Libraries section, search and download the desired library. Another approach is to find the library identifier in the PlatformIO documentation and include this in the platformio.ini file, for example:
When the code is compiled, PlatformIO will search and download the library automatically. In addition, it is also possible to add external libraries to the project. For that, it is necessary to include the path of the library into the platformio.ini file, for example:
For this example, I have used as reference the Calculator project available in the PlatformIO GitHub. The unit tests are running over the calculator class and some other utility functions.
Below, an example of a unit test implemented using the unity.h library.
It is possible to run the tests by clicking on the little Erlenmeyer icon in the bottom bar. This bar also holds many other quick access icons that facilitate the compilation and execution of the code.
The unit test process will open a terminal to build the code, and later, will build another terminal to present the unit tests results.
Clicking on the little arrow icon in the bottom icon bar will instantly build the code, find your board (if attached to your computer) and upload the binary to it. It is possible to open a Serial Monitor terminal and monitor the output of your program (if any).
Besides proving to be a useful tool for the IoT developer, the PlatformIO provides us with a wide range of supported platforms and development features that aim to facilitate and improve our implementation process. Luckily, PlatformIO is an opensource solution, hence, if reported any bugs or missing features, the community is always available to help. Click here to find the complete PlatformIO documentation. Finally, I took the liberty to, using the Calculator class, develop a simple RESTful calculator server for the NodeMCU ESP8266-12E. Click here to get access to the PlatformIO project of this server.
About the author
Marcelo is a Software Engineer at Poatek. He has a Master Degree in Computer Science in the area of Embedded and Digital Systems, focusing on Monitoring and Control of SDRAM Memory Accesses. Despite working mainly in C++ development, Marcelo holds a strong passion for other areas such as Blockchain and IoT.