Shopping Cart Shopping Cart
 
   
   
Projects
Cordless Drill To Corded
Homemade Actuator
Rewound Microwave Transformer
Microwave Parts
Homemade Welder
Toaster Foam Cutter
Fix Dead Batteries
Products
< Homemade Welder Info Basic Homemade Actuator >

Parallel Port Controlled LEDs

Bookmark and Share

Recently I started a test project to make a simple circuit for interfacing with the parallel port on a computer. The parallel port is the wide 25-pin, two row plug that was normally used to control printers. This port is fairly simple to work with and this project was a great starting point to get started in computer controlled circuits.


The pins in a parallel port are numbered from 1 to 25 from right to left starting with the top row.
To see a very good diagram of the pins on a parallel port, check out the following link:

Parallel Port Diagram.

What I wanted to accomplish with this is to create a bank of eight LEDs where each one is hooked up to one of the eight DATA output pins on the parallel port. Once the curcuit was built, I wanted to find or write a simple program that allowed me to turn each of the LEDs on and off.

To make assembly of the circuit easier I used a solderless breadboard. This way I could simply plug components into it and I didn't have to try to solder each peice in place. At this point I did not have much experience soldering so I wanted to stick to solderless breadboards until I took time to practice soldering.

The solderless breadboard for this project is available from my WebStore. For the hookup to the parallel port, I removed the parallel port from an old motherboard. Since I do not yet have a desoldering tool, I used my bench grinder to grind the connections loose from the back of the motherboard. This seemed like the best way to get a parallel port for the project. There are a lot of old computers available for nothing and the pins on the port fit perfectly into the breadboard.


The next task was to find eight LEDs and install them in the breadboard as well. I have quite a large stock of old computers and other electronics that I have saved from the trash over the years. After digging through these, I was able to salvage the eight LEDs. I installed the LEDs and the parallel port into the breadboard with plenty of space between them. I made sure to put all of the positive leads on the same side to simplify the wiring. LEDs will only work one way. If they are wired backwords, they will not illuminate and they will not allow current to pass.

The following is a picture of the curcuit with the LEDs installed.



The final step of building the curcuit was to wire it. This too, was fairly simple. I ran one wire from each of the eight DATA pins to the positive side of each of their respective LEDs. I then ran one wire from one of the ground pins to the negative row of the breadboard. This allowed me to simply hook each of the negative leads of the LEDs to the negative row. Here is a wiring diagram that shows how it was wired:



Here are a couple pictures of what the circuit looked like once it was completed.





After doing some reasearch, I found that the parallel port can be controlled quite easily on Windows using a dll called inpout32.dll. This dll ( including source code ) can be found at: http://www.logix4u.net/inpout32.htm.

The function that this dll offers that I was interested in for this project was called Out32. I created a simple wrapper unit that interfaces with this dll and calls the output function. The code for interfacing with the parallel port is very simple.

unit ParallelPortUnt;

interface

function Out32(wAddr:word;bOut:byte):byte; stdcall; external 'inpout32.dll';
function SendByteToParallelPort( Value: Integer;
AParallelPortAddress: Integer = $379 ): Boolean;

implementation

function SendByteToParallelPort( Value: Integer;
AParallelPortAddress: Integer = $379 ): Boolean;
begin
Out32( $378, Value );
Result := True;
end;

end.


The function that I created to call the Out32 function is called SendByteToParallelPort. The parallel port has 8 DATA pins, which are the eight pins that I hooked my eight LEDs up to. The intended use for these 8 pins was to be able to send one byte of information via the parallel port at one time. Each of the 8 pins represents one bit. So, the function that we have here, SendByteToParallelPort, accepts an integer value. This value has to be between 0 and 255, because that is the biggest number that can be stored in one byte ( eight bits ).

For my uses, I am most interested in not the ability to send bytes of information through the port, but more the ability to control electronics with electrical signals. In order to turn particular pins on and off, you simply need to send the correct value to the port.

For example, if I wanted to turn on the first and last pins, I would need to send the binary value of 10000001. Since one byte is 8 bits, I can send one byte of information with bits 1 and 8 turned on ( one ) and the other bits turned off ( zero ). In Delphi one cannot send a binary value to this function, so I first need to convert that value to decimal or hexidecimal form. The code that my program uses to determine a decimal value is the following:

FAsciiByteToSend := 0;
for i := High( FBinaryByteToSend ) downto Low( FBinaryByteToSend ) do
if FBinaryByteToSend[i] then
FAsciiByteToSend := FAsciiByteToSend + ( 1 shl ( i - 1 ) );


In the above code example, I have an array of 8 boolean values that I am converting to a decimal value ( FAsciiByteToSend ). I loop through the boolean values, and for each one, if it is a true value use the shl function to set that bit to a 1.

In the above example of wanting to set the first and last LEDs, I had a binary value of 10000001. That value translated to decimal is: 129. So in order to turn on the first and last LEDs I call SendByteToParallelPort and pass the value of 129.

The second parameter to SendByteToParallelPort is the address. This is the memory address of the parallel port. On most computers the address is 378. In order to send data to the DATA port you have to send to one more than that address. So on most computers the address you will want to send to is 379 ( $379 in hex ).

If that address doesn't work, the address of your parallel port can be found by going into your computer's Device Manager. To get to the device manager on Windows 2000, go Start->Settings->Control Panel->System. On the hardware tab, click Device Manager. Under Ports, you should have an entry for LPT1 ( your parallel port ). Right-click properties and go to the Resources tab. This tab will show the address of your parallel port.



Once I had the ability to turn on and off the eight LEDs, it was easy to build a simple application that would allow me to control the LEDs in a variety of ways. The following is a screenshot of the program I wrote.



This program allows the user to send a charactor or ascii code to the parallel port, toggle individual pins on and off and supports a random feature that will keep changing the combination of LEDs that are lit to create a neat effect.


Here are a couple pictures of the curcuit in action:





The program I created to run the curcuit is available for download. You can download both the Windows executable and the source code by clicking here.

I have included the Inpout32.dll as well. This dll was created by Logix4u, so check with them for the latest version. They offer this dll and source code for free for use in both commercial and non-commerical applications.

All of the parts needed to build this project are available in my online store.

Parts List
Windows Program Download
LEDs Purchase
Solderless breadboard Purchase
Jumper Wires Purchase

Bookmark and Share


Created 1/20/2009 - CleghornElectronicsKits.com


Google