Saturday, March 30, 2013

We Didn't Start the Fire

...but a Digispark can sure light things up! A Digispark is a small, cheap Arduino board -- I bought a couple for $8.95 each -- which allows you to leave them in a project without feeling guilty about it or worrying too much about the cost. They are not as capable as a full-blown Arduino, but for smaller (and some medium sized) projects, they are powerful enough, and won't leave you with unused pins on the board, or have you worrying about underutilization of your hardware. Digispark was originally a Kickstarter project that I learned about through my friend 'Dillo, who has a great blog over at Roadknight Labs. I missed out on the Kickstarter, but managed to pick some up after the fact. You can order them directly here.

Incidentally, there are many other really cool Kickstarter projects out there, such as the Parallela, which is a massively parallel single board computer system (can't wait to get my hands on one!), and the 3Doodler, which allows you to draw 3D objects using the same plastics and technology as 3D printers such as the MakerBot and RepRaps. Ones I also have my eye on are the APOC Mini Radiation Detector, and the PowerPot, which allows you to produce electricity while camping by cooking food or boiling water.

What I decided to build with a Digispark was.. this glowy thing.

The basic components are a translucent light cover and a a shadow box I got at a thrift store...

...a Digispark Arduino board (which is about the size of a quarter), along with the Digispark RGB LED shield (which are shown here stacked together)...

...and a couple of switches.

The switch on the left is a numeric up/down switch, which goes from 0 to 6. The wiring on it is pretty simple -- there's a common terminal, and then three others, which indicate the current selection in binary. I couldn't find a datasheet for the switch, but a little experimentation determined which was the common terminal.

The numeric switch with the leads attached.

From there, I wired up the Digispark directly to a USB cable. When it is being programmed, the device will be plugged directly into a computer, and under normal operation, it will be plugged into a 5v USB power supply.

The Digispark with a USB cable wired directly to it.
I found information for the wiring layout for USB here on Wikipedia. Wikipedia rocks!

Here is a video of the digispark, wired up to the USB cable, running the demo RGB Arduino program.

From here, I soldered up the numeric switch to the Digispark board, using pins not used by the RGB shield. I used knots to indicate which line was which. The one with no knots is the common line (note -- in the picture, it is soldered to the wrong pin. I had it soldered to +5v, but it should have been connected to ground)

From here, the power switch got soldered to the board...

Adding the wires to the switch. Shrink tubing leaves everything so much better looking when you are done!

...and since the Digispark throws off so much of its power as waste heat, I decided to wire a 1K resistor in serial to the board. It works -- the board powers up with it and is still programmable, so I kept it. Here's hoping it will be a little more efficient!

Putting it all together was fairly straightforward. One thing that needed to be considered, however, was that the Digispark board produces quite a lot of heat, and I needed to isolate it from the wood box I was mounting it on. For this, I just used a bolt and some zip ties. Holes were also cut for the two switches (and a power light), and hot glued from the back to keep them firmly in place.

From here, I decided I would rather have the base black than wood, so I used some chalkboard paint to spray paint it.

In order to not have wires dangling everywhere, I decided to close the box. For this, I repurposed a couple of coke cans...

...sealed up the seam with hot glue, and then added some rubber feet that I got at Vetco Electronics in Bellevue, WA to finish things off. (Vetco is an awesome store, by the way. Somewhat akin to Weirdstuff Warehouse in the San Francisco bay area -- both great places to go look through surplus electronics and find parts!)

And here's what we have so far, shown without the light cover:

Digisparks use a special version of the Arduino 1.x software, with addins for the board, such as the device programmer and libraries. You can download it from the wiki here, as well as find other good information about the board. One quirk I found that was, when reprogramming the board, you have to unplug the board and then plug it back in, at which point the Arduino plugin recognizes it and starts the programming process. Not a big deal, but not immediately obvious, either, and worth pointing out to anyone just getting started.

The code I wrote for it was a variation on the RGB Demo program, with other variations possible depending on the setting of the numeric switch. For instance, setting "0" is all white and as bright as it goes, "1" flickers between blue and green very rapidly, "2" is purple, and "3" is the default demo program, and so on. And the cool thing is, if I get tired of those options, it's very easy to reprogram it.

Here's the program I am currently running on it. Note that it's easily expandable using the switch() statement.