Integration of PlatformIO library manager to Arduino and Energia IDEs

Integrate PlatformIO library manager to Arduino and Energia IDEs

PlatformIO is a cross-platform code builder and the missing library manager for Arduino, MSP430, ARM”

PlatformIO Library Manager allows you to organise external embedded libraries. You can search for new libraries via Command Line or WebSite interfaces. You don’t need to bother for finding the latest version of library. Due to platformio lib update command you will have up-to-date external libraries.

So, today I’m going to talk about integration of PlatformIO Library Manager with popular embedded IDEs, like Arduino and Energia.

Why PlatformIO?

Arduino and Energia IDEs have built-in lite library manager from a box. If you have already downloaded library archive, you can install it via nice GUI (in the Arduino/Energia IDE, navigate to Sketch > Import Library. At the top of the drop down list, select the option “Add Library“). But this is only the one operation which they can do 🙁

I collected the most popular library operations and put it to the comparison table:

Install Uninstall Search Update Own libraries
per project
PlatfomIO Yes Yes Yes (CLI + WEB) Yes Yes
Arduino IDE Yes No No No No
Energia IDE No No No No No

Integration

The main advantage of PlatformIO is Project Configuration File named as platformio.ini . You can define different options per project with it. In our case we are interested in one option named as lib_dir  from [platformio]  section. It allows us to redefine a library directory where PlatformIO Library Manager will save the future libraries.

First of all, you should install PlatformIO. For more detailed information please visit Installation page from documentation.

After this, let’s create two virtual PlatformIO-based projects named as piolib-arduino  and piolib-energia . Indeed, we need only platformio.ini  from these projects to override lib_dir  option. Please run these commands in your OS Terminal application ( cmd.exe  under Windows OS):

You should see platformio.ini  after these commands in each project’s directory.

platformio.ini

Finally, just replace the content of each platformio.ini with this:

Arduino IDE Energia IDE
Mac ~/Documents/Arduino/Libraries ~/Documents/Energia/Libraries
Windows ~\Documents\Arduino\libraries ~\My Documents\Energia\libraries
Linux ~/Arduino/Libraries ~/sketchbook/libraries

Using

Each time when you want to manage your libraries you should change directory to specific project that is created above and run $ platformio lib  command from it. So, let’s test our virtual projects in action. For that, I’m going to use my favourite Mac OS and Arduino IDE.

Firstly, let’s check current state of Arduino’s 3rd party libraries:

Arduino IDE Libraries without PlatformIO Library Manager

Arduino IDE Libraries without PlatformIO Library Manager

Next, open again your Terminal application. For testing, I’m going to install DallasTemperature library:

As we can see, PlatformIO Library Manager has just installed DallasTemperature library and its dependent OneWire library.

Finally, please restart Arduino / Energia IDEs to see the changes:

Arduino IDE Libraries: After

Arduino IDE Libraries: After

P.S: You can reproduce all these steps for Energia IDE. In this case, just use virtual project named piolib-energia  and setup lib_dir  in platformio.ini  accordingly with your OS.

Energia IDE Libraries with integrated PlatformIO Library Manager

Energia IDE Libraries with integrated PlatformIO Library Manager

Conclusion

PlatformIO Library Manager makes it extremely simple to find, install and keep libraries up-to-date.

What is more, PlatformIO is an awesome and smart cross-platform code builder. You have no need to install any IDE or compile any tool chains. PlatformIO has pre-built different development platforms including: compiler, debugger, uploader (for embedded) and many other useful tools. If you are interested in it I recommend to look into a few Project Examples.