Friday, October 22, 2010

Parallel Port Flasher

How to turn that old computer in to a robot.

Today, I decided to resurrect an old Toshiba laptop that was sitting in my drawer, the processor is an ancient Pentium III 450mhz, 320mb of RAM, and a 4.9Gb hard drive, even phones put this laptop to shame.  The good thing with these kinds of systems is that you don't mind messing them up.  It took a little more than an hour to get this all working.




Materials:
  • Old computer with parallel port you don't mind playing with.
  • DSL Live CD
  • Parapin
  • An LED
  • Wires
  • Alligator Clips
  • 2 Paperclips


Procedure:
The Software Part:
  1. Start up your computer with the DSL Live CD.
  2. I installed DSL, because this system was built for Windows 98, and DSL works much better anyhow.
  3. Open the MyDSL Browser and under System install gcc1-with-libs.  Finding this made me incredibly happy as it contained all of the stuff I needed.
  4. Download and extract the Parapin source. (I used 1.5.1-beta1)  The folder may not show up unless you right click in the file browser window and press update.
  5. Open that directory and run setup-2.4.sh, being that DSL runs a 2.4 series kernel.
  6. Build the library using make .
  7. Create the file pptest.c in the parapin directory with the following contents:
  8. #include "parapin.h"
    #include "unistd.h"

    int main()
    {
    /*Init the first parallel port, change to LPT2 to
    use the second */
    pin_init_user(LPT1);

    /*These pins can either be inputs or outputs*/
    pin_output_mode(LP_PIN02);

    while( 1 )
    {
    set_pin(LP_PIN02); /*Turn on the pin*/
    sleep(2);
    clear_pin(LP_PIN02); /*Turn off the pin*/
    sleep(2);
    }

    return 0;
    }
  9. Now run gcc pptest.c parapin.c this compiles the program.
The Hardware Part
  1. Unfold two small paperclips so they look like 6's, this should take one bend.
  2. Place their tips in hole 2, and 25 of the parallel port.  The larger row has 13 pinholes, this will be the top, they are numbered from 1-13 sequentially from the right to the left.  The smaller row (bottom) is numbered 14-25 right to left.
  3. Connect the anode of the LED (long side) to the paperclip in hole 2, and the cathode to the paperclip in hole 25.  I did this with four alligator clips and some wire.
Final Steps

Within the directory you compiled the software should be an executable named "a.out".  You need to execute this as sudo, if you are working in the directory you compiled in just enter "sudo ./a.out".  Sudo is needed because this program accesses hardware.  Your LED should begin to turn on and off every two seconds.

In an early test I connected a battery tester to the leads and watched needle jump rather funnily between on and off states, this can't be seen using the LED.

Conclusion

While it would take (me) days to do anything useful in c with the parallel port I/O, parapin looks like it has Python and Java libraries, so with a few relays, lights, and switches you could make a robot from that old computer.

DSL also provides some nice daemons like SSH, and HTTP, if you got wireless working on your machine, you could create an ad-hoc network and control your robot over the air!

One rather curious thing I noticed was that if the program was quit while the LED was in an on state, the light continued to glow.  Perhaps this is in the actual parallel port specification, or an artifact of the library or OS.  There also seemed to be a slight discharge when I shut the system down, probably from some capacitor finally being allowed to discharge.

    No comments:

    Post a Comment