Arduino Tool That Connects Each Board to Its Own Source

You have the physical device, so why can’t it tell you where it's code lives?

Published
March 15, 2012
Reading Time
5 minutes

If you create something with Arduino and put it out into the world, there is no well-established link to the source. If you personally made the device, the source can get lost over time. If you didn’t create it, you could have a tough time tracking the source down. You have the physical device, why can’t it tell you where it’s code lives?

I made a tool for Arduino called “Upload-And-Retrieve-Source” that for the most part solves this problem.

Github page here, direct download link here

For background on the project and details on how it works click through to the full article.

Why is This a Real Problem?

Right now I’m working in IDEO’s Toy Lab.  To illustrate the problem, I opened a drawer an found a prototype:

Okay, so this looks like some sort of Barbie credit card swiper. What if we had an idea that was similar and I wanted to modify the source code for this? I could probably dig it up from our server, but is that the current version? What would it be called?

Zombie Prototypes

Back in 2008 Bjornn Hartmann gave a talk at Sketching In Hardware, he called this a “Zombie Prototype”: No smarts, stuck in its last embodiment forever.

Bjornn Hartmann’s Slides from Sketching ’08
 

Bjornn’s recommendation was to add storage to the Arduino, this interested me because we had just made a prototype IDEO Arduino that had a USB hub, so it would be possible to add Flash storage. Here are some of Bjornn’s early prototypes that inspired me:

 

Our (since abandoned) tiny Arduino with a USB hub onboard:

 

However, to edit the source, you need a computer, and computers are usually connected to the internet. Storage on the internet is practically free, while usb storage costs money. So I started thinking about how each board has it’s own USB serial number. Why not just use the serial number of the board as a link to it’s own source in the cloud?

How It Works

The code is built as a set of two tools for Arduino. Tools are basically extensions for Arduino that can run processes when Arduino is opened, or when the tool is selected from the tools menu. This functionality was originally built for Processing, of which there are a number of different tools available. If you are interested in building your own tool for Arduino, the Processing documentation is the best place to start.

Once installed, to save your source to the cloud, first make sure your board is connected, and you have a working internet connection.  Then in the tools drop-down menu select “Upload Source to GitHub”:

 

In the output window you should see:

Done!

Now, if you ever need to find the source code for that board, just plug it in and select “Retrieve Source” from the tools menu:

Your code will populate into the editor pane and you should see:

Features

-Works in OSX, Linux, and Windows
-Code Accessible Online and is Embeddable as a Github “Gist”

Because it is a gist, you can do fun stuff like embed your code in a blog, and that code will stay up to date with the source that is on the board! This also makes it a bit easier to share code with someone over the internet.

-Version Control

As a feature of gists, you get version control. This means you can track the progress of your code over time! Forget about having all those different versions floating around on your computer. Just go to the github URL you get when you upload or retrieve your source. There you will find the revisions list.

-Support for Private Accounts

After installing the tool and launching Arduino, you will find a file called “gistCredentials.txt” in the same folder as the Arduino’s “preferences.txt”. If you need help finding the folder, open Arduino’s Preferences window and select the last link:

inside this file, simply add an extra line with your personal account’s username and password in this format:

myusername=mypassword

Then, in the comments of your code you can specify which account to use like this:

-Private Gists

If you are working on something confidential, you can make the gist private. This only really makes sense if it is also on your personal account, as the general account is public. To do this you add the words “MAKE_PRIVATE_ON_GITHUB” to your comments:

-Libraries and Multiple Files:

This code supports libraries that are in the same folder as the .ino/.pde file.  (See the multiple tabs in the above example)

To Install:

In the directory where Arduino saves your sketches (in OSX it’s Documents>Arduino), create a folder called “tools” if one doesn’t exist.  Put the two folders, “GistRetriever” and “GistUploader” into the “tools” folder. That’s it! Next time you start Arduino you should see the added items in your tools menu.
Unless you are running Windows…
I couldn’t find a way to access the USB serial number from the command line without using some sort of additional tool.  The best method I found was to download and install “DevCon” from Microsoft here.  Unfortunately DevCon is not distributable so I can’t just put it in the package.  Let me know if you come up with a better solution.
EDIT: devcon.exe should be placed in the same “tools” folder as everything else.

Compatibility:

Because this code uses the USB serial number as an identifier, it only works on boards that have USB.  this means it will not work with Arduino Pro, Pro Mini, mini, etc.  It will instead connect the code to the programming board/cable, as that is what holds the serial number.

Open Source:

The software is licensed under the Apache License. Check out the github page, or download the tools directly.

 

Enjoy!