Simple circuit and program to show how to use PC parallel port output capabilities Copyright Tomi Engdahl 1996-2000 PC parallel port can be very useful I/O channel for connecting your own circuits to PC. The port is very easy to use when you first understand some basic tricks. This document tries to show those tricks in easy to understand way. WARNING: PC parallel port can be damaged quite easily if you make mistakes in the circuits you connect to it. If the parallel port is integrated to the motherboard (like in many new computers) repairing damaged parallel port may be expensive (in many cases it it is cheaper to replace the whole motherborard than repair that port). Safest bet is to buy an inexpensive I/O card which has an extra parallel port and use it for your experiment. If you manage to damage the parallel port on that card, replacing it is easy and inexpensive. DISCLAIMER: Every reasonable care has been taken in producing this information. However, the author can accept no responsibility for any effect that this information has on your equipment or any results of the use of this information. It is the responsibly of the end user to determine fitness for use for any particular purpose. The circuits and software shown here are for non commercial use without consent from the author. ----- How to connect circuits to parallel port ----- PC parallel port is 25 pin D-shaped female connector in the back of the computer. It is normally used for connecting computer to printer, but many other types of hardware for that port is available today. Not all 25 are needed always. Usually you can easily do with only 8 output pins (data lines) and signal ground. I have presented those pins in the table below. Those output pins are adequate for many purposes. pin function 2 D0 3 D1 4 D2 5 D3 6 D4 7 D5 8 D6 9 D7 Pins 18,19,20,21,22,23,24 and 25 are all ground pins. Those datapins are TTL level output pins. This means that they put out ideally 0V when they are in low logic level (0) and +5V when they are in high logic level (1). In real world the voltages can be something different from ideal when the circuit is loaded. The output current capacity of the parallel port is limited to only few milliamperes. Dn Out ------+ |+ Sourcing Load (up to 2.6 mA @ 2.4 v) |- Ground ------+ ----- Simple LED driving circuits ----- You can make simple circuit for driving a small led through PC parallel port. The only components needed are one LED and one 470 ohm resistors. You simply connect the diode and resistor in series. The resistors is needed to limit the current taken from parallel port to a value which light up acceptably normal LEDs and is still safe value (not overloading the parallel port chip). In practical case the output current will be few milliampres for the LED, which will cause a typical LED to somewhat light up visibly, but not get the full brigtness. Then you connect the circuit to the parallel port so that one end of the circuit goes to one data pin (that one you with to use for controlling that LED) and another one goes to any of the ground pins. Be sure to fit the circuit so that the LED positive lead (the longer one) goes to the datapin. If you put the led in the wrong way, it will not light in any condition. You can connect one circuit to each of the parallel port data pins. In this way you get eight software controllable LEDs. The software controlling is easy. When you send out 1 to the datapin where the LED is connected, that LED will light. When you send 0 to that same pin, the LED will no longer light. ----- How to use the program ----- parashell is a very easy to use program. The program takes two parameters, the Parallel port to send the data to and the data value to send. That value must be integer in decimal format (for example 255). Hexadecimal numbers can also be used, but they must be preceded by 0x (for example 0xFF). The program uses very little error checking to keep it simple. Example how to use parashell. parashell 0x378 0 Set all datapins to low level. parashell 0x378 255 Set all datapins to high level. parashell 0x378 1 Set datapin D0 to high level and all other datapins to low level. ----- Using pin (Parallel input) ----- pin works much like parashell except the you only give it the port address (ie., 0x378) and pin will return the current value. There are 9 input pins on the parallel port allowing you to utilize 9 different triggers. Example how to use pin. pin 0x378 Get the value of the DATA pins pin 0x379 Get the value of the STATUS pins pin 0x37a Get the value of the CONTROL pins ----- How to calculate your own values to send to program ----- You have to think the value you give to the program as a binary number. Every bit of the binary number control one output bit. The following table describes the relation of the bits, parallel port output pins and the value of those bits. Pin 2 3 4 5 6 7 8 9 Bit D0 D1 D2 D3 D4 D5 D6 D7 Value 1 2 4 8 16 32 64 128 For example if you want to set pins 2 and 3 to logic 1 (led on) then you have to output value 1+2=3. If you want to turn on pins 3,5 and 6 then you need to output value 2+8+16=26. In this way you can calculate the value for any bit combination you want to output. The user has to have the previledges to have access to the ports for the program to run, so you have to be root to be able to run parashell without access problems. If you want to make a program which can be run by anybody then you have to first set the owner of the program to be root (for example do compilation when you are root), give the users rights to execute the program and then set the program to be always executed with owner (root) rights instead of the right of the user who runs it. You can set the program to be run on owner rights by using the following command: chmod +s parashell ----- Controlling some real life electronics ----- The idea of the interface shown above can be expanded to control some external electronics by simply adding a buffer circuit to the parallel port. The programming can be done in exactly the same way as told in my examples. Building your own relay controlling circuit The following circuit is the simples interface you can use to control relay from parallel port: Vcc | +------+ | __|__ Relay /^\ Diode 1N4002 Coil /---\ | | +------+ | Diode | / 1N4148 4.7K B |/ C parallel >-|>|-+--\/\/\/--| NPN Transistor: BC547A or 2N2222A port data | |\ E pin +-|<|-+ | V 1N4148 | | parallel >-----------+------+ port ground | Ground Adding even more safety idea: Replace the 1N4148 diode connected to ground with 5.1V zener diode. That diode will then protect against overvoltage spikes and negative voltage at the same time. The circuit can handle relays which take currents up to 100 mA and operate at 24V or less. The circuit need external power supply which has the output voltage which is right for controlling the relay (5..24V depending on relay). The transistor does the switching of current and the diode prevent spikes from the relay coil form damaging your computer (if you leave the diode out, then the transistor and your computer can be damaged). Since coils (solenoids and relay coils) have a large amount of inductance, when they are released (when the current is cut off) they generate a very large voltage spike. Most designs have a diode or crowbar circuit designed to block that voltage spike from hitting the rest of the circuit. If that diode is bad, then the voltage spike might be destroying your "sink" transistor or even your I/O card over a period of time. The mode of failure for the sink transistor might be short circuit, and consequently you would have the solenoid tap shorted to ground indefinitely. The circuit can be also used for controlling other small loads like powerful LEDS, lamps and small DC motors. Keep in mind that those devices you plan to control directly from the transistor must take less than 100 mA current. WARNING: Check and double check the circuit before connecting it to your PC. Using wrong type or damaged components can cause your paralllel port to get damaged. Mistakes in making the circuit can result in damage to your parallel port and you will need to buy a new multi-io card. ----- Other Documents you may want to check out ----- http://www.beyondlogic.org/spp/parallel.htm http://et.nmsu.edu/~etti/fall96/computer/printer/printer.html http://www.2xtreme.net/dage/parport.html