PlatformIO: compile source code for different platforms

Platformium

There are more and more tools and resources available for programmers. Some stand out, such as Google Colaboratory , which is generating a lot of buzz. Another platform worth paying attention to is PlatformIO , a site where you can find extraordinary resources for those who create source code for various platforms.

In this tutorial you will learn what PlatformIO is, what it is used for, how you can access it, and much more about this fantastic programming tool.

What is PlatformIO?

PlatformIO is an IDE (Integrated Development Environment) with a professional code editor and compiler for compiling source code for multiple platforms. It also includes a debugger and a range of other useful programming tools and features (unit tester, serial monitor, code analyzer, code completion, library manager, etc.). It's free, open-source, and its capabilities can be extended with plugins or extensions. It even allows for remote development and integrates with GitHub and GitLab code repositories.

On the other hand, its environment is very user-friendly and easy to use, with a modern, powerful, fast, and lightweight interface. It's a highly versatile platform that already boasts thousands of users and is available for GNU/Linux, Apple macOS, and Microsoft Windows. You can even install it on certain single-board computers (SBCs) like the Raspberry Pi.

More information about PlatformIO – See official website

More about the community and source code – See the site on GitHub

Platforms supported by Platformio

Platformio has a truly impressive list of supported platforms . Some of the architectures supported by its compiler include:

  • ARM
  • atemel avr
  • ARC32
  • NXP LPC
  • PIC32 microchip
  • RISC-V
  • etc.

How do you install?

Installing PlatformIO Core on Windows or macOS is really simple. However, if you have GNU/Linux, the steps will be a bit more complicated (although there is a script to make things easier), or if you decide to install it from source by compiling it yourself.

Remember that you need to satisfy a number of dependencies before installing, such as having Python installed, etc.

The steps to follow are:

  • Download the Platformio package:
wget -q https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py

  • Install Platformio Core
sudo PLATFORMIO_CORE_DIR=/opt/platformio python3 get-platformio.py

  • Now you need to create a symbolic link to the pio command in the / usr / local / bin / directory:
sudo ln -s /opt/platformio/penv/bin/pio /usr/local/bin/pio 
  • Now pio can be used as a system command for all users. By default, the root user and users with sudo privileges will be able to read and write to the serial port. The following is to add the user to the corresponding group:
sudo usermod -a -G dialout $USER
  • Remember that to make changes and for them to take effect, you should restart the computer or log out and log back in. Now try:
pio --version
  • Finally, you can now delete the installation script and the cache that was generated during the installation, since they are not necessary:
rm -rf get-platformio.py
sudo find /root/.cache -iname "*platformio*" -delete

Densinstall Platformio Core

If you would like to uninstall Platformio, it will be as simple as following these other steps in Linux:
</div>
<div>sudo rm -rf /opt/platformio
sudo rm -rf /usr/local/bin/pio
rm -rf ~/.platformio</div>
</div>
<div>

Questions and more information – Official documentation

Install Platformio IDE

Installing Platformio IDE is as simple as following these steps:

  1. Download and install the official version of the Atom text editor from this link.
  2. Once installed, open the Atom package manager.
  3. Go to Menu> Edit> Preferences> Install.
  4. Look there for official platformio-ide.
  5. Then install the package.
Remember that it is necessary to install Python in any case ...

In this case, Atom was chosen for Platformio, but it's also possible to integrate it with Visual Studio Code , which is available for Windows and GNU/Linux. Installation is easy, as it's available in DEB and RPM packages at this link . On Windows, installation is equally simple using the .exe file.

If you're wondering about the steps to install the extension in VS Code , they're similar to those for Atom:

  1. Open VS Code.
  2. Select the extensions icon that appears on the left side in the form of cubes.
  3. Type PlatformIO and select the first option that appears.
  4. Press Install to install.
  5. Wait for it to complete and you're done.

Other environments in which to integrate Platformio

There are other environments in which to integrate Platformio besides Atom and VS Code, such as:

  • Netbeans
  • Sublime Text
  • codeblocks
  • Eclipse

The IDE working environment

Platform IDE

If this is the first time you see the Platformio interface, you will see that it is not complicated, and that it is divided into several sections. The first thing you'll see is a welcome screen when you open the editor, and sections like:

  • Welcome: first screen of the extension, with the installed version, functions to create, import and open projects, see examples, etc.
  • Projects: on the left you can also find a list with all the projects created that you can edit.
  • Inspect (Inspector): In this section you can inspect your projects for memory usage statistics.
  • Libraries: This section corresponds to the library manager, to help you include global and private libraries.
  • Plates (Board): here you can find and install drivers for the different boards that you use in your development. There are more than 1000 available.
  • Platforms- Platforms used so far are listed.
  • Devices: list with the boards connected to your PC that you currently have. It is generated automatically when connecting to the port.

Steps to create the first project

If you want to start creating your first project , you can use the Wizard to create it more easily and quickly:

  1. Go to Platformio Extension Welcome (PIO HOME).
  2. Click Create project.
  3. Choose a name for your new project.
  4. Select a plate in the plates tab. You can enter the first letters of the name of the plate and the list will be reduced with the matches.
  5. Now you will see that the Framework option (a series of criteria, concepts and good practices to facilitate development) is automatically marked, although you could modify it.
  6. You can modify where to save the project in the Location box, otherwise it would store it in the default directory.
  7. Once you are done, you can press the Finish button and it will start.

From here, the way of proceeding will change depending on the type of code or project you want to develop, and the chosen board or platform, since there will be slight differences.


Add as preferred source in Google