Thursday, October 14, 2010

How to make a cheap CI traffic light

We use continuous integration (CI) testing where I work, using Hudson as our CI server. I saw this recent article on the social impacts of making the CI testing status more visible and how that encourages people to fix things that are broken. One way to improve the visibility beyond just having a monitor displaying the CI server status page is to add a large traffic light displaying the status of your CI server. This is an idea I first heard of being used at Digg and have later seen at companies like Github. Below is the Hudson status setup we have at my workplace, showing both the traffic light and the monitor displaying the build status page:

Green means everything built successfully. Yellow means a build is in progress. Red means something is broken. It's a very effective way to let everyone in the office know the status of your builds and encourage people to fix them!

Believe it or not, adding a traffic light to your CI setup is simple, relatively easy, and cheap! Also, if you're like me occasionally breaking into electronics and soldering things is fun! Here's what you'll need to build your own CI traffic light:
  • Lava Lite Traffic Light from Amazon ($19.99)
  • A computer running Linux with a parallel port
  • 4-conductor wire (one for each lamp + ground)
  • A DB-25 connector
  • Soldering supplies (soldering iron, solder, desolder braid, etc)
I bought the Lava Lite Traffic Light based on some reviews from people who used it as a Toastmasters timing light (to let people know when their time speaking is up):

By default it blinks in what the box claims is a "random" pattern but is actually a fixed pattern of red, yellow, green, red, yellow, green. But after opening up the traffic light itself, which only requires a few screws, I found out it was extremely easy to modify.

By default it's controlled by a single IC which is mounted on its own daughterboard, soldered to a small control board which contains the requisite transistors and resistors for powering the lamps and switching them on and off. The first thing you'll need to do is unscrew the control board and desolder the daughterboard from it. Desolder braid is your friend here.

The next step will be following the traces from the lamps back to where the daughterboard is mounted. This is fairly straightforward as the components involved in switching the lamps on and off are in threes. Looking at the control board you should very quickly be able to identify these components. There are three larger blue resistors which limit the current going to the lamps. Don't touch those! There are three transistors which are used to turn the lamps on and off. And finally there are three smaller brown resistors... follow the traces from these resistors to where they used to attach to the daughterboard. These are at TTL voltage, which is good, because so is a parallel port. What we'll be doing is soldering wires onto these three connectors and wiring them directly into a parallel port:

I'm afraid I don't have any fancy schematics for how exactly to do this, but it shouldn't be too hard! Here's a photo of where I soldered onto the control board. You can see the slot in the lower right corner where the daughterboard for the control IC used to be. I used a green wire for the green light, red for red, white for yellow, and black for ground. The circuits that go to ground are large and well labeled, so it should be fairly straightforward to find the points to solder onto:

If you've soldered correctly, you should be able to short any of the lamp wires (or a combination thereof) with the ground wire and they should turn on.

On the other side of your wire, you'll be wanting to solder on a DB25 connector. Wire the three wires which control the lamps to data lines 0, 1, and 2, and the ground to any of the many ground pins available on a parallel port. Here's a picture of mine:

And here's a handy dandy parallel port pinout diagram:

You'll be wanting to solder onto D0, D2, D2, and probably pin 18 (ground). I put green on D0, yellow on D1, and red on D2.

Next, you'll need some software to control the traffic light over the parallel port. To control our traffic light, I wrote a simple UDP server in C that receives 1-byte packets and writes them out to the parallel port. I originally wrote the server in Ruby but garbage collection was hanging up some fun light shows I was trying to put on, so I rewrote it in C for moar realtime. Here is the C source code to the traffic light server:

This uses the /dev/port character device on Linux, so you'll either need to run this server as root or a user specifically configured to have permissions to /dev/port. One thing I soon discovered was that the parallel port is stateful and will remain in the last state you set it to. This means you don't constantly have to write to the parallel port to keep a lamp on. Instead you can just set a state and the parallel port will remain in that state. Another thing I discovered that I still can't explain is that for some reason I needed to write the same byte twice to get the light to show the appropriate state. I don't know why, but it works!

Next, you'll need a client for your traffic light server. Here's a simple one I wrote in Ruby:

Just wait until this script gets passed around the office. Believe me from experience, everyone will go nuts for the first few days playing with the traffic light. Setting the light to an individual color is all, but for a true acid test here's a script I wrote which calls the above one and will make your traffic light rave balls!

But we didn't build this traffic light just to make it rave balls, did we? No, back to business, we need to get it to show the status of the Hudson build server. Here are some examples you can go off of which we're using now. It's a hacked together collection of scripts, to be sure, but it gets the job done:

Just set your Hudson server address (and username and password, if you protect it with HTTP basic auth like we do) and you're ready to go.

With all those scripts combined and a quick cron job to periodically poll Hudson's status, the traffic light will automatically display your build status and let everyone in your office know how diligent you've been about keeping your tests passing.

Now, get to work and build your own traffic light!


LongSteve said...

Great article, I built the same sort of thing myself using some lights from Ikea, an Arduino and some relays. My setup was a bit more complicated to build though since the bulbs run off 240V mains, hence the relays.

How do you power the bulbs on the Lava Lite lamp? Are they LEDs? I'm looking to build some more of these lights for our Cruise Control server, and the Arduino/Relay route works out fairly expensive, and this could be a cheaper way.

Tony said...

The traffic light's control board contains everything to power the LED clusters in the lamps, which primarily consists of a transistor to do the switching and resistors to limit the current. From there it's just TTL back to the parallel port.

If you wanted to BYO traffic light you could do the same thing or use a MOSFET.

Jeff Bennett said...

Very helpful. The traffic light was a Christmas gift to my son. I had no interest in interfacing to a computer but these instructions made installing switches for manual control of the lights s straightforward task. Three holes in the case, three switches from Radio Shack, some soldering and desoldering and voila! A delighted six-year old. Thanks for posting.

jeroen94704 said...

"By default it blinks in what the box claims is a "random" pattern but is actually a fixed pattern of red, yellow, green, red, yellow, green"

That reminded me of this Dilbert cartoon

Anyway, nice article, I'm going to make one of these myself.

Mark Thomas said...

You mention they are LED clusters, but the comments on Amazon says they are night-light bulbs. Are there two different versions?

Roy Tapia said...

Great idea but wat I want to do with this is use it as a traffic signal at McDonald's drive thru to prevent customers from passing our cashier at first window any ideas guys how we can modify this item?

Christopher F said...

This is neat, though I have a question....

Where did you get your replacement bulbs from? I can't find them anywhere?

Hamsite said...

شرکت هم سايت ارائه دهنده خدمات طراحي سايت و خدمات بهينه سازي و سئو و خدمات بازاريابي و تبليغات اينترنتي است.
شما مي توانيد طراحي سايت براي مشاوره طراحي سايت و مشاوره بهينه سازي و سئو سايت و مشاوره بازاريابي اينترنتي مشورت کنيد و با بازديد از مقاله هم سايت و شناختن از واژه ياب همسايت و از مقالات هم سايت بيستر آشنا بشويد.
واژه ياب هم سايت و گروه و تيم همسايت با داشتن گنجينه هم سايت ارائه دهنده سفارشي ها هم سايت و بهينه سازي و سئو و

Hamsite said...

بازاريابي و تبليغات اينترنتي است.
درباره هم سايت را در دفتر تماس با همسايت هم سايت با خدمات تبليغات و خدمات طراحي و خدمات سئو را با قيمت طراحي سايت و قيمت بهينه سازي و سئو سايت و قيمت بازاريابي و تبليغات سايت ببينيد.
آيا طراحي وب سايت را مي شناسيد.
براي شناخت از بازاريابي بايد از شرکت طراحي سايت آشنا بشويد
طراحي وب
بهينه سازي و سئو سايت
بازاريابي و تبليغات اينترنتي هم سايت

Hamsite said...

سئو حرفه اي بهترين را براي مشاوره سئو
يا سئو و بهينه سازي سايتيا بازاريابي و تبليغات اينترنتي و آنلاين به شما مي دهد.
بهينه سازي سايت و يا تبليغات و يا افزايش بازديد سايت را با سئو سايت را ببينيد.و مقالات ديجيتال مارکتينگ و

Hamsite said...
This comment has been removed by the author.
Hamsite said...

براي اين کار يا يا که طراحي سايت در تهران و بهينه سازي وب سايت مي توان بهينه سازي و مشاوره بهينه سازي و سئو را تا مشاوره بازاريابي آنلاين و سئو براي دو افزايش رنک گوگل و افزايش بازديد و همچنين شبکه تبليغاتي را دارا مي باشد و در افزايش پيج رنک گوگل دارد شرکت تبليغاتي و کانون تبليغاتي و معرفي سايت به گوگل و طراحي سايت تخصصي و طراحي وب سايت تخصصي است و در ادامه مي توان گفت واژه ياب همچنان واژه ياب فارسي و واژه هاي تخصصي و واژه تخصصي پزشکي و واژه تخصصي مهندسي هستند و همه چي درباره بازاريابي اینترنتی و همه چي درباره بازاريابي آنلاين و درباره بازاريابي اينترنتي و درباره بازاريابي آنلاين مي باشند که بهينه سازي و سئو و آموزش بهينه سازي و سئو و آموزش سئو و مقالات بهينه سازي و سئو و مقالات سئو و سئو چيست و آموزش کامل سئو و آموزش کامل بهينه سازي و سئو که هستند و بازاريابي ايميلي و ايميل مارکتينگ و آموزش بازاريابي ايميلي و آموزش ايميل مارکتينگ و مقالات بازاريابي ايميلي و مقالات ايميل مارکتينگ مي باشند و بازاريابي اينترنتي و آموزش بازاريابي اينترنتي و آموزش بازاريابي آنلاين و مقالات بازاريابي اينترنتي و مقالات بازاريابي آنلاين و بازاريابي آنلاين هستند اما

Hamsite said...

با همراه کارشناسان طراحي سايت و بهينه سازي و بازاريابي که همچنان و بازاريابي و تبليغات اينترنتي است.و را در را با مي توان همچنين طراحي سايت حرفه اي و طراحي وب سايت حرفه اي مي توان از طراحي سايت شرکتي و طراحي وب سايت شرکتي در ادامه اين طراحي سايت تجاري و طراحي وب سايت تجاري و يکي از همين طراحي سايت اختصاصي و ديجيتال مارکتينگ چيست و بازاريابي الکترونيک و تجارت الکترونيک و آموزش تجارت الکترونيکمي باشد.و طراحي سايت صنعتي و طراحي وب سايت صنعتي که بهترين طراحي رو براي طراحي سايت املاک و طراحي وب سايت املاک که مي توان طراحي سايت رستورانديجيتال مارکتينگ و آموزش ديجيتال مارکتينگ و بازاریابی اینترنتی و بازاریابی آنلاین

Hamsite said...

و.همچنان با و کسب و کار اینترنتی و کسب و کار آنلاین . اما طراحي وب سايت اختصاصي مي توان با طراحي سايت سازماني ، طراحي پرتال سازماني که اين همان طراحي سايت کارخانه و طراحي سايت کافي شاپ که اين يک طراحي سايت معماري و طراحي سايت دکوراسيون داخلي است.طراحي سايت خبري و طراحي وب سايت خبري و ديگر طراحي سايت خودرو و همچينين طراحي سايت دانشگاه و طراحي وب سايت دانشگاه همچنان

Hamsite said...

طراحي سايت پزشکي و طراحي وب سايت پزشکي و طراحي سايت بيمارستان در ادامه مي توان نشان داد که طراحي سايت دندانپزشکي ، طراحي سايت هتل و طراحي وب سايت هتل همواره سايت هايي چون طراحي سايت آژانس مسافرتي و طراحي وب سايت آژانس مسافرتي و طراحي سايت آژانس هواپيمايي مي توان يکي از طراحي فروشگاه اينترنتي ، طراحي سايت فروشگاه اينترنتي ، طراحي وب سايت فروشگاه اينترنتي ، طراحي سايت فروشگاه ، طراحي وب سايت فروشگاه ، طراحي وب سايت فروشگاهي و در يکي از