The Source for Java Technology Collaboration
User: Password:



Kohsuke Kawaguchi

Kohsuke Kawaguchi's Blog

DIYOrb - my own "extreme feedback" device for Hudson

Posted by kohsuke on November 22, 2006 at 10:57 AM | Comments (13)

Background


Ambient Orb

One of my hobby projects is Hudson, and there I use colored balls as a metaphor of the build status — red means fatal errors, yellow means test failures, blue means OK, etc.

One day I came across the ambient orb, which I thought would be a rather cool widget as the real world representation of the Hudson ball. I commit to a large number of projects, and I often break a build, so I thought maybe I can use this orb so that I can notice whenever I break a build (or cause test regressions.)

Then I checked the price, and it was pretty expensive! It also apparently incurs monthly expense, because it fetches the data over the pager network.

Why don't I make it myself?


PIC 18F2550 with USB support
Whole computer in a chip

That's when I noticed that the company makes the schematic of AmbientOrb available along with very helpful technical notes. In my junior high school days, I was in the electronics club for about a year or so, so I do know the basics (well, a little bit of it, anyway.) So I looked at the schematic, and thought it's actually pretty simple.

The key to the simplicity is a programmable micro-controller called "PIC" chip. It's a whole computer in one chip, and best of all it's programmable, so you can put all the hard part (in this case controlling the color of LEDs) in a software. PIC then uses its I/O pins to turn on/off transistors, which in turn drives LEDs.

PIC is apparently a flagship product of Microchip, and there are a whole series of those with different capabilities. I noticed that some of them have USB support, and thought that would be just excellent — this allows me to leave the "hard part" in PC, such as checking the build status via HTTP, then PC can tell the orb higher-level instructions (like "become flashing yellow ball".) The orb will take that and actually drives the LEDs.

The other benefit of using USB is that I can draw power from USB, so I won't have to make the power circuit, which makes things simpler.

Initial Design


USB Bit Whacker
Look at how small it is!

After a bit of research like that, I started drawing the schematic on the paper. The hard part turns out to be LEDs. I wanted to do at least red, yellow, and blue, so I was looking for tri-color LEDs that has all R,G, and B in it. LEDs also needed to be fairly bright, since I have to light up an orb.

While I can easily find them in Japan, it was very difficult for me to find equivalent parts here in the U.S. Eventually, my colleague Ken (who turns out to be a real electronics geek!) told me about SparkFun, and its very bright tri-color LED offering.

While I was at it, I made a great discovery. SparkFun sells a PIC chip with all the necessary parts (like oscilator and USB connector) in a tiny board, called "USB Bit Whacker" (originally developed by Brian Schmalz.) This not only greatly simplified my orb design, but it also made it a lot cheaper. Normally, to download a program into a PIC you'd need a separate programmer device, which sells > $100 (or you can make one, but that was beyond me.) UBW comes with a "bootloader" program that is capable of flashing itself, so I won't need the external programmer.

Buying Parts


HSC Santa Clara store. Great place.

I ordered two LEDs and UBW from SparkFun, but I still needed other parts, like resistors, boards, transistors, etc. I first went to nearby parts store that I found via Google Map, but when I went in the store, it was clear that was not the place I was looking for — it was just too small, and everything was pretty expensive.

I asked anyway if they have the parts that I was looking for. They didn't, but another customer waiting behind me kindly told me that there's another place that I should go. This place, HSC electronic supply, turns out to be a great place. You can buy individual parts at a very low price (like 2 cents per resistor, 8 cents per transistor — it's a real mystery how they manage to make ends meet), and the store staff are very friendly folks who don't mind my asking dumb questions!

The other trouble I had was multi-meter. I bought one from SparkFun, but it was DOA. My colleague Dhiru have told me before that he had one, so I asked him if I could borrow his. It turns out that his was broken too, and so I had to start by fixing a multi-meter. It turns out Dhiru's multi-meter is dead just because its probe is dead, so Dhiru and I removed it and was able to make it work.

Prototyping


Nothing beats good old breadboard

Now that I have all the parts, I started putting them together on a breadboard (which I bought from Fry's.) I also found a wall-mount light fixture at HomeDepot for $5, which I decided to use as the orb.

It quickly became obvious that 2 LEDs are not bright enough. It looks OK in night, but in the daylight I can barely see the color. So I bought 6 more, making the LEDs total of 8. Also, 3 colors were not evenly bright (red is weak — datasheet says so too), so I decided to add extra red LEDs to compensate that, making total of 12 LEDs!

When you change one thing, you need to change other things to match. Each LED draws 20mA per color, so with this change, now a transistor needs to drive as much as 240mA. The transistors that I initially had can't drive that much current, so I needed different ones.

And if I change transistors, now I need to also change the resistors to match with its parameters. There's a few rounds of adjustments like that, until it became a reasonable prototype.

Software


I tried so many different resistors,
but they are $0.02/ea

I was more optimistic about the software side, because after all I'm a professional software engineer :-).

There are two pieces of the software I needed to write. One that runs on PC, and one that runs inside the PIC.

On the PC side, how do you talk to USB devices? Well, there are a few pre-defined "class" of USB devices (like mouse, keyboard, etc), and one of them is called "communication device class" (CDC). This is a fairly well supported type of devices on Windows and Linux, and from those operating systems, CDC devices will look like serial ports, so programming PC side is really easy, and you can even do that in Java.

The PIC side is bit harder, mainly because those devices are designed for getting maximum juice out of small memory and CPU power and not for ease-of-development (gotta love Java!) But there's a large community of hobbiests who share their source code, and Microchip makes IDE and C compiler freely available. So I just needed to spend a bit of time to play with this stuff. I wish Microchip had a C++ compiler, but writing this in C was not too bad.

The whole chip only has just 384 bytes that I can use for data space. It was a really big change from my day job, where my IDE could easily weigh in at 386 MB — 106 times more memory!

Eventually I decided to develop a mini language for controlling the color. It reads like this:

// yellow flash mode
repeat {
  // gradually become full yellow in 500ms
  become (255,255,  0) in 500;
  // gradually become full black in 500ms
  become (  0,  0,  0) in 500;
}

I wrote a compiler that translates this into small byte code, which is sent to PIC. PIC stores the interpreter of this byte code, and executes it. I still need to write the program to connect this to Hudson, but that should be a piece of cake.

Assembling Pieces


Assembled pieces

Now that both the hardware and the sofware are fully tested on breadboard, it's a soldering time!

I first started with a cheap-cheap $2.99 soldering iron. Unfortunately it took me no time to spend all $2.99 worth out of it. The tip quickly broke, and it was no good! It could have been the problem with my soldering skill, but I decided to blame the tool.

So I went out to buy another soldering iron. This time I chose "made in Japan" :-), and while it cost $20, I regretted not buying it from the get-go. I think it is actually the same model I used in my junior high school electronics club, because I remember the shape and the color. It's amazing that this thing sells for 15 years without any model change.

I put all the LEDs in one board, so that I can put it at the center of the orb. The PIC, transistors, and resistors went to another board. I think it took me 6 hours or so to solder them all up and wired correctly.

And Finally...

When I'm done with wiring it was pretty dark already. I briefly wondered whether I should leave it at that and call it a day, or to connect that to PC and see if it really works. I haven't done any soldering for a long time, so I thought there's a good chance I didn't get some of them right. And if there's a trouble, I'd spend more time trying to fix the issue. I'd be late, and my wife would be upset.

But I couldn't resist the temptation to try it out, so I told myself "just this once..." and plugged it in.

It was a moment of truth!

To my pleasant surprise, it actually worked!

So here's the orb in the demonstration "rainbow" mode, showing all colors:

While it's not as pretty as the ambient orb, this is cheaper, and more importantly it's way more fun! If anyone is interested in the source code / schematic, I'd be happy to make them available.

Acknowledgements


Uh-oh. Build is broken!

Thanks to Takeshi Umezawa, for his advices. He was one of my friends at the junior high school electronics club, and he knows this stuff pretty well. Thanks to Dhiru, for his multi-meter. Thanks to Ken, for his many advices and telling me about SparkFun. And thanks to Rajiv for being my 3rd arm during some tricky soldering.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • OhhhhmmyyyGooodd.... you're crazy, man! ;-) I want one too :-D

    Posted by: fabriziogiudici on November 22, 2006 at 11:10 AM

  • I'm speechless. Our QA team would love something like this :)

    Posted by: kirillcool on November 22, 2006 at 04:34 PM

  • AAAAAA!!!!!
    Now it's time to create a business and to get very rich by selling these crazy Orbs to similarly crazy people like me! I'd pay extra! :)

    Posted by: vsizikov on November 23, 2006 at 02:37 AM

  • You should definately make that a product - as someone said, great for QA teams!

    Posted by: doj on November 23, 2006 at 07:34 AM

  • I agree; this is very cool. Maybe we should brainstorm on what other applications could benefit from this device, and what other devices one could create?

    [1] Orb-as-Dashboard - Many groups routinely track the status of a number of metrics through a dashboard. This is usually represented as a matrix / spreadsheet where cells are colored based on status. We could set up several ORBs to represent information from dashboards, then have a laptop / SunRay that can be used to get more detail. Build status is just one dashboard. Others can be Downloads, Bugs-against-plan.

    [2] Orb-for-Outages - Build is one type of "outage". Something you expect to be available but has failed... you just have not yet found out. An ORB seems ideal for that. Others can be: Mail Delays, Web Sites / Wikis / CVS-News / Maven ...

    Other ideas? Kohsuke, what type of devices can you connect? What about input devices? Touch-sensitive devices?

    - eduard/o

    Posted by: pelegri on November 23, 2006 at 07:38 AM

  • WOW!!!! I want one :-) But I want a wireless one so I don't have to look around the computer all the time :-). You are amazing! -- Jeanfrancois

    Posted by: jfarcand on November 23, 2006 at 09:22 AM

  • Hi! Excelent project! Congratulations! Please make the code available both the pic and de pc version! :) I will definitively build one of those! 8-) /Luis

    Posted by: tuxetuxe on November 24, 2006 at 04:28 AM

  • Thank you Kohsuke, I've been looking for a way to control USB via java.

    Posted by: larswestergren on November 24, 2006 at 05:23 AM

  • Fantastic! I was considering Lava lamps but this is so much better. Could you please post the final schematics and the source code?

    Posted by: xmaniac on November 24, 2006 at 10:17 AM

  • Konnichiha, Kawaguchi-san. I have been interested in XFD and electronic construction too. I think USB Bit Wacker is a good choice. In my first XFD I selected a similar controller named USB-IO (http://km2net.com/usb-io/ also can controll via Java). Recently I make XFDs using Atmel AVR (a kind of microcomputer like PIC) and AVRUSB (http://www.obdev.at/products/avrusb/). It's less than $5! I will hold a workshop of XFD making, and tell the fun of XFD to many developers :-) http://www.objectclub.jp/event/2006christmas/session.html #Sorry for linking to Japanese Web site.

    Posted by: atchy on November 27, 2006 at 07:42 AM

  • This is fantastic. I can apply this to many apps. I too would be greatly interested in the source code and schematics.

    Posted by: aaronplazton on November 28, 2006 at 03:03 PM

  • Kohsuke, This is awe-inspiring. Great!

    Posted by: km on February 07, 2007 at 11:12 PM

  • All I can say is Kashuke is such a genius. I salute you man!!! This is so interesting. I found this from http://blogs.sun.com/glassfishpodcast/ .

    Posted by: mint on January 02, 2008 at 12:52 AM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds