The “Do My Job” Button

a.k.a. The USB Easy Button

It’s A Fundamental Truth of Requirements Gathering that the longer you talk to someone about custom software, the more their answer boils down to two requirements:

  • Make me a button called “Do My Job.”
  • Make it do my job.

Then they get thoughtful for a moment and add a third requirement:

Just… build me one of these

  • Make sure only I can press the button.

Some of them will even joke “You know, like an Easy Button.”

Those Easy Buttons from Staples are awesome, but they have one small flaw: they don’t actually do anything useful. It’s my aim to change that.

Let’s Make a Button!

What we need is an Easy Button Hack, so I’m going to build a USB Easy Button. I found most everything I needed from jro’s project on instructibles and a flickr photoset by tommybear. Plus, I’ve been dying to try one of these U-HIDs.

What you’ll need:

 

  • An Easy Button (or Botón Fácil if it suits you better) $4.99
  • A U-HID Nano and USB Cable (with shipping) $42.00
  • A Modular Harness for the U-HID (optional) $9.00
  • Soldering iron & solder
  • Wire (if you didn’t buy the wiring harness)
  • Dremel or a chisel
  • Hot glue or silicone
  • Small phillips screwdriver
  • PC running Windows XP

Step 1: Program your U-HID Nano

Plug the USB cable and wiring harness (if you’re using it) into the U-HID Nano. If you’re going to have the button send a single command like me, just leave the black (ground) wire and the gray (pin 10) wire long enough to reach the PCB. We won’t be using the other 7. If you want to use the button to close more than one switch at a time (for example, to send “Ctrl + Alt + Del”), leave one wire per button, plus the ground wire.

That's a U-HID Nano

That’s a U-HID Nano

I hooked the wires up to a temporary switch at this point for programming the thing. You could go ahead and hook it up to the Easy Button. Just scan down a little to see which contacts to use.

You program the U-HID Nano with U-Config, a software package available from the manufacturer. It’s a pretty easy process, and the Technical Manual was easy to read.

I’m not going to go into the details here except to note that a driver install and firmware update were required to get it working on my machine. Both of those processes are clearly documented on their site. I set it up so that when pin 10 goes to ground, it will send the macro “L Alt, F8”. It seems to send the scancodes fast enough that my machine counts it as a combination keypress.

Step 2: Take the Easy Button Apart

Turn the button over, and you’ll see four black pads on the bottom. Pull them off to expose the screws. Be sure to save the pads so you can stick them back on. Go ahead and take the batteries out while you’re there.

IMG_0690

Desolder Everything

Remove all 4 screws to release the silver ring and red button from the assembly. You’ll be left with just the guts of the machine. Inside, you should see a white button. That is the heart of the Easy Button and the only part of the original electronics we’re actually going to make use of.

All of these things have to go, so desolder and discard them:

  • The black capacitor
  • The resistor closest to the button
  • The red speaker wires
  • The black & white power wires

If you don’t know what those things are, don’t sweat it. Take a look tommybear’s photos on flickr. He’s better at this than I am.

Remove the 2 screws, and take the PCB off of the assembly. Set the metal spring aside. We want to keep that because it gives us a satisfying CLICK when the button is pushed.

Remove the 4 screws that hold the little mezzanine level on. You may have to pry it up just a bit if the hot glue below is sticking it down. Take the metal slugs out and discard them. They’re just stuck in there with a little hot glue and you can pick them out without ruining anything. I guess you could leave them if you have the room & like the heft. Remove the speaker too.

Use your dremel or a chisel to take out any little plastic bits that are in your way. Just remember that you have to leave the 4 posts that hold the mezzanine level up.

Step 3: Put the U-HID in the Easy Button

Fit it like this

Fit it like this

Solder it like this

Solder it like this (the gray wire goes on the side of the gap closest to the button)

Find a way that the whole U-HID assembly will fit inside the button, then use some hot glue or silicone to stick it in place.

Replace the mezzanine, metal spring, and PCB. Now comes the soldering. The U-HID Nano is going to just sit there and wait for pin 10 to touch the ground pin. We’re going to use the normally-open momentary switch inside the Easy Button to interrupt that connection, so the circuit is only closed while the Easy Button is depressed. Solder the gray and black wires as shown.

It would be a good idea to test it at this point to make sure it works before you put everything back together. Use a little hot glue to make sure the wires do not interfere with the holes in the PCB. Those are what keep the button aligned properly, and if they’re blocked, you can’t push the button.

Step 4: Let The Wire Out

Cut a slot for the wire

Cut a slot for the wire

Cut a slot in the silver ring that’s just big enough for the wire to get out of the enclosure. I made mine a left-handed Easy Button (made to sit in the left side of the computer). You could hook yours up backward or cut a channel through the battery compartment and have it come straight out the “front.”

Step 5: Replace the Ring and Button

It should only go back together one way: with the battery compartment farthest away from you, the “easy” label should be right-side up and the Staples logo on the ring will be directly toward you. Replace all 4 screws in the bottom of the case and use a little hot glue to stick the rubber pads back on. You’re done with the hardware: you’ve built an Easy Button that actually does something.

Step 6: Write the Software that Actually Does Your Job

If you’re able to buy software that does your job, you could use that too. Implementation of a security system so that only you can push your button is left as an exercise to the reader. For extra style points, make sure your software ends up playing a “That was easy” sound effect when the job is done.

Step 7: Assign a Hotkey to Your Software

If you are having the button send a key combination that is recognized by the system already (like Ctrl + Alt + Del), you can skip this step.

Create a folder in your Start Menu called “Easy Button” and create one shortcut inside the folder called “thatwaseasy.lnk”. Right-click the shortcut and select Properties. Click the “Shortcut key” field and press the hotkey combination you told the Easy Button to send (in my case, Alt + F8). This shortcut has to be in your start menu or on your desktop. You can set the shortcut property of any shortcut, but it only works if the shortcut is in the right place.

TA DA!

A Finished USB Easy Button

A Finished USB Easy Button

For about $50 you could have one just like this. If you pay close attention to jro’s project, you could use a recycled keyboard instead and do this for about $5. Now get out there and build your own.


Win32::AmbientOrb

This page describes a Perl module I wrote to support a serial-port controlled Ambient Orb. See the Original Post for details.

If you just want to get the package, you can download it directly or grab a PPD.

Manipulate an Ambient Orb through a serial port

NAME

Win32::AmbientOrb – Manipulate an Ambient Orb through a serial port

SYNOPSIS

  use Win32::AmbientOrb;

EXAMPLE

  use Win32::AmbientOrb qw(:ALL);

  my $port = "COM1:";
  Win32::AmbientOrb::Port($port); #set port to COM1
  InitializePort();               #set serial port settings
  PagerIgnore(1);                 #don't listen to the pager network

  # go straight to red
  my @red = (176, 0, 0);
  DirectColor(\@red);

  # quick transition from blue to red
  my @blue = (0, 0, 176);
  TransitionColor(\@blue, \@red, 20, 5);

  # slow transition from red to blue
  TransitionColor(\@red, \@blue, 50, 100);

  # clean up
  CloseOrb();

DESCRIPTION

The Win32::AmbientOrb module lets you manipulate an Ambient Orb connected to a Win32 machine through a serial port.

It uses Win32::SerialPort for serial port communication.

EXPORTED HASHES

Two hashes are exported by default, %OrbColor and %OrbRGB.

%OrbColor
Maps from color names to Color IDs useful for ColorAnim( ). Available color names are:

 • Red          => 0
 • LightRed     => 1
 • DarkOrange   => 2
 • Orange       => 3
 • LightOrange  => 4
 • DarkYellow   => 5
 • Yellow       => 6
 • LimeGreen    => 7
 • PaleGreen    => 8
 • GreenMinus3  => 9
 • GreenMinus2  => 10
 • GreenMinus1  => 11
 • Green        => 12
 • GreenPlus1   => 13
 • GreenPlus2   => 14
 • PaleAqua     => 15
 • Aqua         => 16
 • DarkAqua     => 17
 • Cyan         => 18
 • DarkCyan     => 19
 • LightBlue    => 20
 • SkyBlue      => 21
 • BlueMinus2   => 22
 • BlueMinus1   => 23
 • Blue         => 24
 • DeepBlue     => 25
 • VeryDeepBlue => 26
 • Violet       => 27
 • Purple       => 28
 • LightPurple  => 29
 • Magenta      => 30
 • MagentaPlus1 => 31
 • MagentaPlus2 => 32
 • MagentaPlus3 => 33
 • MagentaPlus4 => 34
 • MagentaPlus5 => 35
 • White        => 36
%OrbRGB
Contains the mapping of color ids to RGB arrays useful for DirectColor( ).

METHODS

Port( [$port] )
Sets or returns the port that the Ambient Orb is connected to. Default is COM1:

InitializePort( )
Initializes the serial port for communication with the Ambient Orb. Settings are:

 • BAUD: 19200
 • PARITY: N
 • DATA: 8
 • STOP: 1
ClosePort( )
Cleans up the port object.

ColorAnim( [$color], [$animation] )
Changes the color of the Orb using the default color and animation settings. Colors are listed above in %OrbColor Animations are 0-9

        ANIMATION
 • 0 almost imperceptibly slow
        ...
 • 7 very fast
 • 8 crescendo effect
 • 9 heartbeat effect
DirectColor( \@rgb )
Sets the orb instantly to the color specified in the 3-element array @rgb. Red, green and blue values should be between 0 and 176.

TransitionColor( \@rgb0, \@rgb1, $steps, $wait )
Performs a slow transition from the color in @rgb0 to the one in @rgb1. Sets the orb instantly to the color specified in the 3-element array @rgb0, then sends $steps updates, one update every $wait milliseconds until it reaches the color specified in @rgb1. Red, green and blue values should be between 0 and 176.

PagerIgnore( $ignore )
Instructs the orb not to listen to the pager network. If you don’t call this, the orb will keep changing its color to reflect whatever channel it was listening to before you plugged in the serial port.

AUTHOR

Andy Allen


Orb Walkthrough

This page goes through how to set up your serial-controlled orb. The sections are:

What You Will Need
Connecting the Hardware
Installing Perl and Required Packages
Creating a Color Script
Installing the Service
Web-Connected Orbs
Other Uses For the Orb

You Will Need:

HARDWARE

SOFTWARE

Connecting the Hardware

  • Plug the serial exension cable (if you’re using one) into your serial port.
  • Plug the HDK into the serial extension cable
  • Plug the Orb into the HDK.
  • Plug the Power adapter (supplied with the Orb) into the HDK.

The orb will go through its regular power-up routine, then start displaying the DJIA channel (or whatever it was most recently tracking).

Installing Perl and Packages

Install Perl and get all of the packages above installed in the order listed. If you use the ppm commands provided, it will link the modules’ documentation right into your html documentation so you can see how to use everything. You will only be using Win32::AmbientOrb directly. It depends on Win32::SerialPort (which depends on Win32::API), and we will need Win32::Daemon to get it up and running as a service.

Creating a color script

The service will need a script to tell it what color to turn the orb. A color script can be written in just about any language, it just has to print an integer to the console representing the correct color. Possible colors are:

0 Red 24 Blue
3 Orange 27 Violet
6 Yellow 30 Magenta
12 Green 35 Red-Magenta
18 Cyan 36 White

You can use any integer between 0 and 36. The ones I didn’t list work out about like you’d expect (i.e. 9 is yellowish-green). My color script is in Perl and is available below. A blue orb means all builds are successful, a red orb means at least one build is failed, and a yellow orb means the CruiseControl server was unreachable.

Here is an example of a (very simple) batch file color script:

    @echo 24

It’s not very interesting, because it just returns the code for “blue.” The default script looks like this:

 1   #!perl
 2   use strict;
 3   use LWP::Simple;
 4
 5   my $color = getColor();
 6   print $color;
 7
 8   sub getColor {
 9       my $color = 6;
 10      for (my $retry = 0; $retry < 3; $retry++) {
 11          if ($color == 6) {
 12              sleep 1 if ($retry > 0);
 13              $color = getColorRequest();
 14          }
 15      }
 16      return $color;
 17  }
 18
 19  sub getColorRequest  {
 20      my $color;
 21      my $dashboard = get('http://cchost/ccnet');
 22      if ($dashboard) {
 23          if ($dashboard =~ />Fail/) { $color = 0; }
 24          else { $color = 24; }
 25      }
 26      else {
 27          $color = 6;
 28      }
 29      return $color;
 30  }

It is a little more interesting: it makes a request to a server named cchost and searches the response for the word “Fail.” If it finds it, at least one build is failed and the orb should be red. If no builds are failed, the orb should be blue. In the event that the server is unavailable, it will retry the request twice more, but if it still can’t reach cchost it will turn the orb yellow.

Installing the Service

Now that the orb is hooked up and you’ve got your color script written, here’s how to install the service to make it go.

Put the files in place

Create a folder named C:\Program Files\AmbientOrb and copy everything in this .zip into it: AmbientOrbService.zip. Put your color script in the same folder.

Install the Service

You will need the script installOrbService.pl (or one like it) to install the AmbientBuild Windows Service on your host.

 1   #!perl
 2   ###########################
 3   # installOrbService.pl
 4   ###########################
 5   use Win32::Daemon;
 6   my $svcName = 'AmbientBuild';
 7   %Hash = (
 8       name    =>  $svcName,
 9       display =>  $svcName,
 10      description => 'Ambient Build Monitor',
 11      path    =>  'c:\\perl\\bin\\perl.exe',
 12      user    =>  '',
 13      pwd     =>  '',
 14      parameters =>'c:\\Progra~1\\AmbientOrb\\orbService.pl',
 15  );
 16
 17  my $action = $ARGV[0];
 18  if (lc($action) eq '-i') {
 19      if( Win32::Daemon::CreateService( \%Hash ) ) {
 20          print "Successfully added.\n";
 21      }
 22      else {
 23          print "Failed to add service: ",
 24           Win32::FormatMessage(Win32::Daemon::GetLastError()),
 25           "\n";
 26      }
 27  }
 28  elsif (lc($action) eq '-u') {
 29      if( Win32::Daemon::DeleteService( "", $svcName ) ) {
 30          print "Successfully removed.\n";
 31      }
 32      else {
 33          print "Failed to remove service: ",
 34           Win32::FormatMessage(Win32::Daemon::GetLastError()),
 35           "\n";
 36      }
 37  }
 38  else {
 39      print "Unknown action ",
 40      "(use -i for install, -u for uninstall).\n";
 41  }

You only need to run this script once to install the service. It takes one argument: -i for install or -u for uninstall, then prints a short status message indicating whether the action was successful.

Line 14 points to the script that will be started when the Windows Service starts. That’s our orbService.pl script. If you write your own Windows Service, you would put its pathname here, using the short pathname (with no spaces). If you fill out a username and password in lines 1213, the script will run as that account. If you leave it blank, it will run as System.

Note that line 14 should contain the orbService.pl script as written, not your color script.

Configure the Service

The service looks for a file named orbService.config, which can have any of the following values. If a value is not specified, it will use the default listed.

KEY Default Value Description
colorScript C:\Program Files\AmbientOrb\ccnetWeb.pl prints orb color code to STDOUT
webOrbs [n/a] serial #s of other orbs,
comma-separated, no trailing comma
port COM1 serial port to use
logFile C:\Program Files\AmbientOrb\orb.log
verbosity 1 0 = silent, …, 3 = garrulous
maxLogLines 10000 maximum lines to leave in log file
pollingInterval 30000 wait between updating the orb (ms)
sleepTime 2000 between processing service messages (ms)
waitForStop 20000 how long to expect service stop to take (ms)
errorColor 0 color to use on colorScript error (0-36)
errorAnim 5 animation on colorScript error (0-9)

While the service is running, changes to this configuration file will be automatically loaded the next time the script checks its messages (within 2 seconds by default). If you leave the service configured as shown, it will run the ccnetWeb.pl script every 30 seconds.

Web Orbs

In my environment, we have three orbs and only two HDKs. The service is installed on both hosts with HDKs attached, but that leaves one orb out of the loop. To update it, one of the servers is also configured to update the orb using its webOrbs configuration parameter. This orb is updated using Ambient’s Web Developer API.

Other uses

This service was written to make it easy to monitor anything using an Ambient Orb. With a different color script and polling interval, you could make it monitor just about anything. During testing I had it monitor hockey scores, crude oil prices, and network traffic (not all at the same time). If you do something like that, I’d like to hear about it, so please let me know.


Design a site like this with WordPress.com
Get started