Developing for Arduino with Docker and Johnny-Five on OS X

I love prototyping IoT projects with Arduino. With Johnny-Five, it is so easy to write simple Node.js apps that can take full advantage of everything the Arduino offers!

I also love using Docker. The reproducible environments and builds makes sharing code dead simple. Many complicated projects are already packaged in Docker containers, so using them with your Johnny-Five project becomes much easier!

Unfortunately, getting them to play nice on OS X or Windows can be a bit of a pain. Because of the extra VM layer, you need to do a few extra steps.

First, if you are running Docker Machine on the cloud, stop right there. It won’t work, because the Cloud VM doesn’t have access to your local USB devices. You need to use boot2docker or Docker Machine with a VirtualBox host. I am using Docker Machine.

Step 1:

Install Docker Machine

Install VirtualBox

Step 2:

Create your local docker-machine VM

$ docker-machine create local -d virtualbox

Step 3:

Stop your Docker VM

$ docker-machine stop local

Now, open VirtualBox

Go to settings and mount your Arduino

Now start your Docker Machine VM

$ docker-machine start local
$ eval "$(docker-machine env local)"

Step 4:

At this point, you should be able to use your Arduino with Johnny-Five and Docker

$ docker run -ti --privileged node /bin/bash
# mkdir test && cd test
# npm install johnny-five
# apt-get update && apt-get install -y vim
# vim test.js

And now for the code, the standard Johnny-Five hello world

var five = require(“johnny-five”);
var board = new five.Board();
board.on(“ready”, function() {
var led = new five.Led(13);

Run the code

# node test.js

If everything worked, you should see a blinking light!

Awesome! Now go and hack!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.