Continuous testing for Arduino libraries using PlatformIO and Travis CI

Posted by Ryan on 13 March 2017
Tags: arduino

At Pololu we maintain around thirty open-source Arduino libraries, and we keep adding new ones whenever we make a new carrier board or Arduino shield. People typically use these libraries with Arduino-compatible boards, such as our A-Star programmable controllers or Arduinos. We also have Arduino libraries for our user-programmable robot kits like the Romi 32U4 robot, Balboa 32U4 robot and Zumo 32U4 robot.

Sometimes we need to make changes to a lot of libraries at once, like when we wanted to add all of our libraries to the Arduino Library Manager. For us, library manager compatibility requires changing the directory layout, but doesn’t require changing the library or example code. With this many libraries to change, there is a risk of potentially breaking a working library by misspelling or moving a file incorrectly. Fortunately, customer Walt Sorensen introduced us to PlatformIO and Travis CI, which let us test compiling Arduino libraries every time they are pushed to GitHub.

Setting this up is easy enough that we encourage you to do it on your Arduino libraries! First, sign up for Travis CI (a testing service, free for open-source projects) and enable it for the GitHub repository you want to test. Now, every time you push new code to your repository, Travis CI will try to see if there is a .travis.yml file in the top level with instructions for running tests.

If your project has the structure of an Arduino Library Manager project and you have at least one example sketch, our short .travis.yml file should work. This file instructs Travis CI to compile the library and its examples against all the supported Arduino boards (specified in the “env” list of the .travis.yml file). The results can be seen on Travis CI’s website (for example, here is Pololu’s Travis CI page). The Arduino compiler is provided by PlatformIO, an open source ecosystem for internet-of-things development, which supports a long list of Arduino-compatible boards.

You can share your Travis CI build status by embedding a badge into your GitHub readme page:

Of course, for most library changes, we still have to test on actual hardware, but now every time we update our libraries (or a contributor submits a pull request), we can be sure they will at least compile on every supported board.


Continuous Integration sure revolutionized the industry when it came into widespread use! I'm glad you're seeing the value, too.
The next step up is Continuous Testing. One could say that "it links cleanly" is a kind of smoke test, I guess?
I've found it worthwhile for my longer projects to go further, and build a "dummy" software version of my hardware devices, and build and link against a library that implements a simulated device.
I can do this on a full host (Windows or Linux) and then run a full-software simulation, against which I can then write acceptance tests.
It's actually pretty easy to write a fake "Wiring.h" library and provide fake serial port objects and such. I highly recommend it as a next step!
Hey Jon W., I generally like that approach. For some of our proprietary firmware, we like to run the firmware in a simulator and run automated tests against the simulation. When testing 8-bit PIC firmware, we use a tool we made called RPicSim so that we can write our tests in Ruby.

Post a comment

Using your Pololu account allows you to customize your avatar and manage your comments; you can also post anonymously.

New Products

Wall Power Adapter: 12VDC, 1A, 5.5×2.1mm Barrel Jack, Center-Positive
Addressable RGB 60-LED Strip, 5V, 1m (SK9822)
Addressable RGB 30-LED Strip, 5V, 1m (SK9822)
Addressable RGB 8x32-LED Flexible Panel, 5V, 10mm Grid (SK9822)
XT60 Connector Male-Female Pair, Black
Sanyo Pancake Stepper Motor with Encoder: Bipolar, 200 Steps/Rev, 42×31.5mm, 5.4V, 1 A/Phase, 4000 CPR
Free Circuit Cellar magazine May 2017
Free Circuit Cellar magazine April 2017
Addressable RGB 60-LED Strip, 5V, 2m (SK9822)
Addressable RGB 16x16-LED Flexible Panel, 5V, 10mm Grid (SK9822)
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors