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.

  • Nicolas Colomer

    Hi Ivan, thanks for this post! You mentioned Arduino IDE and Energia but what about Eclipse CDT? Is it possible to import / make visible these libraries inside Eclipse?

  • Peter Willard

    The latest IDE versions have added the library manager feature.

    • Does it have support for library dependencies? Automatic updates?

      • Peter Willard

        Automated? No. But it will inform you that you CAN upgrade if you manually review libraries using the library manager.

        • Thanks for the info. And how about library dependencies?

  • Zsolt

    Hi Ivan, Thank you for this post. You describe here how to make available Platformio managed libraries to the Arduino IDE, if I understand correctly. But I am interested in using the existing Arduino libraries, already on my disk in Platformio. Is this possible? How? Also, there is a ‘libraries’ custom folder where I developed my libraries for Arduino. Can I use these in a Platformio project?

    • Are going to use Arduino IDE?

      • Zsolt

        I used the Arduino IDE so far and I am trying to switch to Eclipse + PlatformIO, which is very appealing.
        However, I don’t know how to use the Arduino libraries, e.g. RobotIRremote. I’ve seen them listed under ~/.platformio/packages/framework-arduinoavr/libraries, but how to use them? I’d like to do sg like #include , what works in the Arduino IDE.

        The same for my custom libraries…

        • However, I don’t know how to use the Arduino libraries, e.g.

          Use these libs like you use them in Arduino IDE. PlatformIO will find and compile them automatically.

          The same for my custom libraries…

          Should these custom libs be shared between projects? If yes, the place them to http://docs.platformio.org/en/latest/projectconf.html#lib-dir , otherwise to project’s lib directory which will be created using http://docs.platformio.org/en/latest/userguide/cmd_init.html

          • Zsolt

            Thanks, good info. Unfortunately I get a lot of errors, like
            .pioenvs/megaatmega2560/FrameworkArduino/Printable.h:25:1: error: unknown type name ‘class’

            Update: that was gone after I renamed my file from main.c to main.cpp, and was bale to compile the project even after renaming to main.ino (had to add *.ino to C++ file types in Eclipse). Sweet! 🙂

            Does the main file have to be called main.* ?

            • Please open an issue here with project example https://github.com/platformio/platformio/issues

              • Zsolt

                Issue for what? For not ompiling the *.c file?

                • You are going to use C++ within *.c file. Please decide what do you want to do. Remove C++ code from this file or change extension of the file to *.cpp.

                  • Zsolt

                    I only included a header file, what is C compliant. It happened that the header file contained C++ code – what is quite common in AVR systems. Maybe the IDE should be instructed to treat *.c files like cpp – I hope this is not a stupid idea 😉 (nevertheless, this is not so important now. I used main.c because I copied your example.)

                    • Zsolt

                      I am quite fine now with Eclipse+PlatformIO, just experiencing a very annoying detail: the Serial is not recognized by the IDE and underlined as error. Do you know maybe where is this symbol defined? In the original Arduino libraries I guess it is in HardwareSerial.h, but there is no such file in framework-arduinoavr. How can I make the IDE content?

                    • It should work from the box. Which version of PlatformIO/Eclipse do you use? Try to re-init your project platformio init --ide eclipse -b ***

                    • Zsolt

                      PlatformIO, version 2.6.3 and Eclipse CDT Version: Luna Service Release 2 (4.4.2)
                      Build id: 20150219-0600. The init command did not help.

                    • Zsolt

                      My board is a megaatmega2560.

                    • Zsolt

                      Thank you for sorting this out. (It was an Eclipse cache problem, cleared by rebuilding the C/C++ index.)

                    • Thanks, I’ve just updated an article and changed *.c to *.cpp to avoid similar issue.

  • Martin

    Please fix path in Windows for non.english version:

    %userprofile%documentsArduinoLibraries