The computer parallel port is the easiest way to control devices outside the PC, like LEDs, lights and even home appliances. In this tutorial we will teach you how to use the computer parallel port to control circuits outside your computer.
The greatest thing about printers nowadays is that they use USB connection. Thus, on the majority of modern PCs the parallel is not used, so it is available for us to use it to control circuits outside the computer box.
In fact the idea behind parallel port is really simple. It is an 8-bit parallel interface, so you have eight bits available there. Simple put, since each data bit can be set as either “0” (“turned off”) or “1” (“turned on”), we can directly turn on or off up to eight devices, like LEDs, lights and even home appliances. You can connect LEDs direclty to the parallel port and play with them – actually that is exactly what we are going to do in this tutorial, since this is the best way to learn how to use the parallel port. But for “heavier” circuits like lights and home appliances, you will need to build a power circuit, because the computer parallel port is not capable of driving enough current to deal with such devices. We’ll explain how to build this kind of circuit as well.
[nextpage title=”Understanding The Parallel Port”]
On the PC the parallel port uses a 25-pin connector (called DB-25, 25-pin D-sub or 25-pin D-shell), as you can see in Figure 2. On printers, however, a different kind of connector is used, called Centronics, which has 36 pins.
Besides the eight data bits, there are more signals available on the parallel port. In the table below we list all the basic parallel port signals and their function, as well as their location on both standard 25-pin and Centronics connector. The I/O column indicates if the signal is input (I) or output (O). Input means that the signal must come from the device to the parallel port (i.e., the signal must be provided by your prototype); output means that the signal comes from the parallel port.
|Signal||Name||Pin (25-pin standard connector)||Pin (36-pin Centronics Connector)||I/O||Description|
|/STROBE||Strobe||01||01||O||Indicates if data is ready or not to be transmitted.(0 = Data ready to be transmitted, 1 = Data not ready to be transmitted)|
|/ACK||Acknowledge||10||10||I||Indicates that the printer is ready to receive data.|
|BUSY||Busy||11||11||I||Indicates that the printer is not ready to receive data.|
|PE||Paper Empty||12||12||I||Indicates that the printer has no paper to print on.|
|SELECT||Select||13||13||I||Indicates that the printer is on its “on line” state, ready to get information.|
|/AUTO FD XT||Auto Feed||14||14||O||The printer moves the paper to the beginning of the next line.|
|/ERROR||Error||15||32||I||Some error occured (printer disabled, paper empty).|
|/INIT||Init||16||31||O||Resets the printer and clears its printing buffer.|
|/SELECT INPUT||Select Input||17||36||O||Data can only be transferred to the printer when this line is set to “0”.|
|D0 through D7||D0 through D7||2 through 9||2 through 9||O||Data bits.|
|GND||Ground||18 through 25||19 through 30||O||Ground.|
The parallel port uses three I/O addresses: data (378h), status (379h) and control (37Ah). If you want to send data to the parallel port and get this data outside the computer, just write this data to the parallel port data address. For example, if we want to turn on all our LEDs, all we need to do is to send the value 255 (which is the decimal equivalent for 11111111, i.e., all data bits set to “on”) on the address 378h. Of course we will explain more about this and also the role of the status and control addresses.
[nextpage title=”Building Basic Prototypes”]
If you never built any parallel port prototype before, we suggest you to start with the most basic one: a set of eight LEDs, one connected to each data bit pin from the parallel port. With this very basic prototype you will be able to learn a lot how the parallel port works.
When a data pin is set to “0”, you will find 0 V on it. When it is set to “1”, you will find 5 V on it. This is enough to turn on LEDs, but not enough to turn on lights and home appliances; we will explain later how to drive “heavier” devices.
So, all you need to do is to connect each data pin from the parallel port (pins 2 through 9) to a LED (to its anode terminal, a.k.a. “positive terminal”) and get one ground pin (any one from 18 through 25) to connect to the cathode terminal (a.k.a. “negative terminal”) from all LEDs. You can see the schematics in Figure 3.
Since LEDs have polarity, you should pay attention to correctly locate its anode (positive) and cathode (negative) terminals. If you pay close attention, LEDs are not completely rounded: the cathode side is a little bit flat, as you can check in Figure 4.
As for building circuits, we recommend you to use a breadboard unit. Breadboard units allow you to assemble prototypes without needing to solder anything.
[nextpage title=”Building Basic Prototypes (Cont’d)”]
Also, the easiest way to build the cable to connect the parallel port to your prototype on the breadboard is getting a standard parallel printer cable and cutting the Centronics connector from it. After that, you will need to find out where each wire is connected. With a multitester on resistance (or continuity) scale, put one of the probes on the wire you are trying to find out its function and test the other probe on each pin of the 25-pin connector of the cable. When the resistance goes to zero (or the multitester beeps, if you are using its continuity scale), you found which pin on the 25-pin connector that particular wire is connected to. Label that wire with the pin function (so you won’t need to go all through this process again) and go to the next wire, until you have found the function for every wire on the cable.
Regarding the pin numbering, pay close attention to the 25-pin plug and you will see that each pin is numbered, see Figure 7.
After you assembled your circuit, it is time to put it to work.
Back in the old days of DOS programming for the parallel port was pretty easy: it was just a matter of sending to the parallel port I/O address (378h) the value you wanted to be there. On modern versions of Windows, however, this is not possible, because the operating system doesn’t allow direct calls to the PC hardware, including the parallel port.
So, the easiest way to send data to the parallel port is to download a finished program, like Relaistimer. This program is really simple but will allow you to explore all the basic parallel port capabilities.
On this program you can turn each bit on or off by pressing keys F1 through F8, if you want to turn all on just click on “X”, if you want to turn all off just click on “O”. You can also turn on or off individual LEDs by click with the mouse on correspondent LED on the LED diagram on the top of the program.
You can also program when each LED will be turned on or off, allowing you to create lighting patterns or use the program as a timer, since it allows you to turn a LED or a group of LEDs on or off at a specific time of the day. Imagine that instead of a LED you have a light or a home appliance: you will be able to make your computer turn it on or off at a specific time even if you are not home. Really awesome, isn’t it?
If you are a programmer and want to write more advanced programs than RelaisTimer, you should go to https://www.logix4u.net/inpout32.htm and read how to allow your favorite programming language (C, Pascal, VB, etc) to write directly to the parallel port.
[nextpage title=”Power Interface”]
If you need to control other devices than LEDs, you will need to project and build a power interface. The basic idea is to connect a transistor acting as a switch at each data output, and this transistor switching on or off the device you want to control. If you want to control AC circuits – standard light bulbs and home appliances, for example – you will need use a relay. Relay is a switch that turns on whenever current flows through it.
You can see a basic power interface in Figure 9. You will need to repeat this circuit for every bit you want to use, i.e., if you want to use the eight bits provided by the parallel port in order to control up to eight AC circuits you will need to repeat this circuit eight times, one for each data bit.
You will need an external power supply with the same voltage as your relay. So, if you use a 12 V relay, you will need to have a 12 V power supply connected to +Vcc and ground. “AC Power” is the power cord to be connected to an AC outlet on your wall and “AC Outlet” is an AC outlet in your circuit were the light bulbs or home appliances will be connected to.
The diodes work as protections and even though we recommend 1N4148 any other general-purpose diode will work just fine. The same goes to the transistor, we recommend BC547 but any general-purpose transistor will work fine as well.
[nextpage title=”Advanced Features”]
So far we only talked about sending data out the parallel port. Actually you can read data using the parallel port. The standard parallel port, also known as SPP, uses two extra addresses for status (379h) and control (37Ah). If you read the contents of I/O address 379h you will be able to read the status of Busy, Acknowledge, Paper Empty, Select and Error pins found on the parallel port. This can be very useful if you’d like to build a circuit to send data to the computer. For example, if you have some kind of sensor and want your program to turn on an alarm if this sensor is triggered, this is one way to accomplish that.
As mentioned above, reading I/O address 379h you can read the status of Busy, Acknowledge, Paper Empty, Select and Error pins. You get an 8-bit value with the following format:
|bit 7||bit 6||bit 5||bit 4||bit 3||bit 2||bit 1||bit 0|
Writing data to this I/O address (37Ah) you can use the other control lines available at the parallel port. So in fact you have more output bits on the parallel port that the standard eight data bits, but these extra bits are accessed on a different address. Also, the bit number 4 of the control address masks IRQ7. With this bit set to “1” IRQ7 can occur.
|bit 7||bit 6||bit 5||bit 4||bit 3||bit 2||bit 1||bit 0|
|X||X||X||IRQ 7||/SELECT INPUT||INIT||/AUTO FD XT||/STROBE|
If you mastered the basics, you can go ahead and study two different modes the parallel port can work: EPP (Enhanced Parallel Port) and ECP (Enhanced Capabilities Port). These two modes are generically known as “bi-directional modes”, because under these modes the data pins can be used for both input and output, contrary to the standard parallel port mode, SPP, where the port can only send data, not receive (this statement is not completely true, since you can use the status bits to receive data – this technique is called nibble mode).
Using EPP and ECP modes, however, is not so easy as it is to use the standard mode. For full details on these modes as well as far more information on building prototypes using the parallel port, we recommend the book Parallel Port Complete, by Jan Axelson.