Thursday, August 5, 2010

Controlling Woot-off Lights using the Parallel Port

Here is a cheap recipe for making woot-off lights that actually turn on and spin during a woot off using the parallel port and a small amount of Perl. Stock lights connect to the PC with a USB plug, but supply power only to both lights and motors. By default there is no control over the function of the lights, other than a small on/off switch on the front of each light. I noticed a few people doing similar projects with expensive usb controllers, but since few people use the parallel port on their PCs anymore, creating functioning woot-off lights costs less than $10 including the lights!






Ingredients:
1 Set of Woot-off lights - approx $5 on ebay (or usually $3 if you can catch them on Woot)
1 25 Pin Male Solder Cup DB25 $0.95 @ sparkfun
1 25 Pin Parallel DB25 Housing $1.95 @ sparkfun
6'+ of 3-4 conductor wire. 4 conductor round phone wire would work well. (my parallel ports are fairly weak on power, and the motor assembly. is pretty crude, so I had to use two pins for each motor. A good silicone lubricant may help things along. Your mileage may vary.)


Steps


Start by taking out the 3 screws on the base. This will pop out and allow access to the other 3 screws which hold the orange plastic lens. Since the leads on the LED don't reach all the way through, it's necessary to remove the orange lens as well to extend the leads out far enough.



Next, unsolder all of the existing wires and toss the existing cable into a box for some other project. I also removed the switch, since it's completely unnecessary at this point. It’s time to start soldering! On each end of your cable connect the wires according to the chart below. The 2nd set of wires running from pins 4 and 7 may be unnecessary if your PC provides enough power from the ports.



My pin-out is as follows.







(Viewing connector side of DB-25 Male Connector)

PIN Name Connection
2 Data Bit 0 Motor 1 -
pos. term.
3 Data Bit 0 LED 1 - Anode
4 Data Bit 0 Motor 1 -
pos. term.
5 Data Bit 0 Motor 2 - pos. term.
6 Data Bit 0 LED 2 - Anode
7 Data Bit 0 Motor 2 - pos. term.

22 Ground Motor 1 & LED Cathode 1
23 Ground Motor 2
& LED Cathode 2


Ideally, pins 2-9 will provide 5v when set high. There isn't a particular reason to not use a common ground to one or more pins, but depending on the size of your wire, it could get messy trying to jam multiple wires inside a single solder cup.

The extra screw used in the clamp was to provide enough force to hold the wires tight.



Controlling the Lights
While it isn’t necessary to use Perl (many other languages can do the same thing), basic port control can be achieved through a very small amount of code using the “Device::ParallelPort” Perl module. This example turns on the motors and leds.
#!/usr/bin/perl
use strict;
use warnings;
use Device::ParallelPort;
my $pp = Device::ParallelPort->new();
$pp->set_bit(0,1);
$pp->set_bit(1,1);
$pp->set_bit(2,1);
$pp->set_bit(3,1);
$pp->set_bit(4,1);
$pp->set_bit(5,1);
$pp->set_bit(6,0);
$pp->set_bit(7,0);

Turning off the LEDs and motors is as easy as setting the 2nd number in each “set_bit” command to 0




It’s a Woot-Off!
The following script pulls down the woot webpage and checks the page for the gold-light.gif image that appears when there is a woot-off. Set the script as a scheduled task to run every so often, and never miss a woot-off!

#!/usr/bin/perl
use strict;
use warnings;
use HTML::TokeParser::Simple; #Module to pull down the woot homepage
use Device::ParallelPort; #Module to control the parallel port
my $text;
my $pp = Device::ParallelPort->new();
my $parser = HTML::TokeParser::Simple->new(url => 'http://www.woot.com');
while ( my $token = $parser->get_token ) {
next unless ($token->is_tag('img'));
$text .= $token->as_is;
}
if ($text =~ /gold-light\.gif/) #checks for woot-off lights image reference in html and executes the correct sub.
{
allon();
}
else
{
alloff()
}
# Turns on all pins for lights and motor. (Bits 2 and 5 are used for each motor due to a weak parallel port. Your mileage may vary.
sub allon {
$pp->set_bit(0,1);
$pp->set_bit(1,1);
$pp->set_bit(2,1);
$pp->set_bit(3,1);
$pp->set_bit(4,1);
$pp->set_bit(5,1);
$pp->set_bit(6,0);
$pp->set_bit(7,0);
}
#Turns off all pins
sub alloff {
$pp->set_bit(0,0);
$pp->set_bit(1,0);
$pp->set_bit(2,0);
$pp->set_bit(3,0);
$pp->set_bit(4,0);
$pp->set_bit(5,0);
$pp->set_bit(6,0);
$pp->set_bit(7,0);
}

Conclusion

With a little code, it's easy to make them do many other things. Some examples would be to have them flash a number of times and/or spin for new emails, twitter postings, or RSS feeds, with different behaviors for each. There are tons of potential applications, and it's nice to have a visual indicator without actually checking a webpage or email for updates. CPAN.org is home to many Perl modules that can interact with most popular social and email sites, so applications are almost limitless (as limitless as a pair of motors and leds can be).

Have fun!

4 comments:

  1. Very creative work. I like it thanks.

    ReplyDelete
  2. Awesome old skool hack, but tbh the reason fewer and fewer people are using the parallel port is simple: fewer and fewer people have them anymore.

    ReplyDelete
  3. Maybe I'm missing something, but it looks like the 2 ground wires are soldered to just pin 23 and 25. Is that correct?

    ReplyDelete
  4. Thanks for clarifying. You're correct. There are only 2 grounds. I updated the table to reflect this.

    ReplyDelete