“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):

# create an empty directory for “piolib-arduino” project $ mkdir piolib-arduino # change current directory to “piolib-arduino” $ cd piolib-arduino # initialise PlatformIO-based project $ platformio init # go up $ cd .. # now, repeat it for “piolib-energia” $ mkdir piolib-energia $ cd piolib-energia $ platformio init 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # create an empty directory for “piolib-arduino” project $ mkdir piolib - arduino # change current directory to “piolib-arduino” $ cd piolib - arduino # initialise PlatformIO-based project $ platformio init # go up $ cd . . # now, repeat it for “piolib-energia” $ mkdir piolib - energia $ cd piolib - energia $ platformio init

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:

[platformio] lib_dir = %PATH_TO_LIBRARIES_DIRECTORY_SEE_TABLE_BELOW% ; ; Examples ; ; Mac OS / "piolib-arduino" project ; [platformio] ; lib_dir = ~/Documents/Arduino/Libraries ; Windows OS / "piolib-arduino" project ; [platformio] ; lib_dir = ~\Documents\Arduino\libraries ; Linux OS / "piolib-energia" project ; [platformio] ; lib_dir = ~/sketchbook/libraries 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [platformio] lib_dir = % PATH_TO_LIBRARIES_DIRECTORY_SEE_TABLE_BELOW % ; ; Examples ; ; Mac OS / "piolib-arduino" project ; [platformio] ; lib_dir = ~/Documents/Arduino/Libraries ; Windows OS / "piolib-arduino" project ; [platformio] ; lib_dir = ~\Documents\Arduino\libraries ; Linux OS / "piolib-energia" project ; [platformio] ; lib_dir = ~/sketchbook/libraries

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:

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

$ cd piolib-arduino # print "platformio.ini" content (works only for UNIX) $ cat platformio.ini # [platformio] # lib_dir = ~/Documents/Arduino/libraries $ platformio lib search "dallas temperature" # Found 2 libraries: # # [ ID ] Name Compatibility "Authors": Description # ------------------------------------------------------------------------------------- # [ 54 ] DallasTemperature arduino, atmelavr "Miles Burton, Tim Newsome, Guil Barros, Rob Tillaart": Arduino Library for Dallas Temperature ICs (DS18B20, DS18S20, DS1822, DS1820) # [ 1 ] OneWire arduino, atmelavr "Paul Stoffregen, Jim Studt, Jason Dangel, Derek Yerger, Tom Pollard, Robin James": Control devices (from Dallas Semiconductor) that use the One Wire protocol (DS18S20, DS18B20, DS2408 and etc) # Install "DallasTemperature" library $ platformio lib install 54 # Installing library [ 54 ]: # Downloading [####################################] 100% # Unpacking [####################################] 100% # The library #54 'DallasTemperature' has been successfully installed! # Installing dependencies: # Installing library [ 1 ]: # Downloading [####################################] 100% # Unpacking [####################################] 100% # The library #1 'OneWire' has been successfully installed! # List installed libraries $ platformio lib list # [ ID ] Name Compatibility "Authors": Description # ------------------------------------------------------------------------------------- # [ 54 ] DallasTemperature arduino, atmelavr "Miles Burton, Tim Newsome, Guil Barros, Rob Tillaart": Arduino Library for Dallas Temperature ICs (DS18B20, DS18S20, DS1822, DS1820) # [ 1 ] OneWire arduino, atmelavr "Paul Stoffregen, Jim Studt, Jason Dangel, Derek Yerger, Tom Pollard, Robin James": Control devices (from Dallas Semiconductor) that use the One Wire protocol (DS18S20, DS18B20, DS2408 and etc) # Try to update them $ platformio lib update # Updating [ 54 ] DallasTemperature library: # Versions: Current=8f3d462d45, Latest=8f3d462d45 [Up-to-date] # Updating [ 1 ] OneWire library: # Versions: Current=2.2, Latest=2.2 [Up-to-date] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 $ cd piolib - arduino # print "platformio.ini" content (works only for UNIX) $ cat platformio .ini # [platformio] # lib_dir = ~/Documents/Arduino/libraries $ platformio lib search "dallas temperature" # Found 2 libraries: # # [ ID ] Name Compatibility "Authors": Description # ------------------------------------------------------------------------------------- # [ 54 ] DallasTemperature arduino, atmelavr "Miles Burton, Tim Newsome, Guil Barros, Rob Tillaart": Arduino Library for Dallas Temperature ICs (DS18B20, DS18S20, DS1822, DS1820) # [ 1 ] OneWire arduino, atmelavr "Paul Stoffregen, Jim Studt, Jason Dangel, Derek Yerger, Tom Pollard, Robin James": Control devices (from Dallas Semiconductor) that use the One Wire protocol (DS18S20, DS18B20, DS2408 and etc) # Install "DallasTemperature" library $ platformio lib install 54 # Installing library [ 54 ]: # Downloading [####################################] 100% # Unpacking [####################################] 100% # The library #54 'DallasTemperature' has been successfully installed! # Installing dependencies: # Installing library [ 1 ]: # Downloading [####################################] 100% # Unpacking [####################################] 100% # The library #1 'OneWire' has been successfully installed! # List installed libraries $ platformio lib list # [ ID ] Name Compatibility "Authors": Description # ------------------------------------------------------------------------------------- # [ 54 ] DallasTemperature arduino, atmelavr "Miles Burton, Tim Newsome, Guil Barros, Rob Tillaart": Arduino Library for Dallas Temperature ICs (DS18B20, DS18S20, DS1822, DS1820) # [ 1 ] OneWire arduino, atmelavr "Paul Stoffregen, Jim Studt, Jason Dangel, Derek Yerger, Tom Pollard, Robin James": Control devices (from Dallas Semiconductor) that use the One Wire protocol (DS18S20, DS18B20, DS2408 and etc) # Try to update them $ platformio lib update # Updating [ 54 ] DallasTemperature library: # Versions: Current=8f3d462d45, Latest=8f3d462d45 [Up-to-date] # Updating [ 1 ] OneWire library: # Versions: Current=2.2, Latest=2.2 [Up-to-date]

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:

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.

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.