Programming a parallel port as digital I/O

I'm trying to use a parallel port from a computer as a form of cheap digital output to do various things (control motors, light LEDs, read limit switches, ect).

I want to know how to control the 8 data pins on a parallel port using C++, however there's a catch. Since I'm using a modern computer with a modern OS, this presents a few problems.

First of all, modern windows OS's don't allow direct access to parallel port pins, I must go through a driver. I have been pointed to using Inpout32 to do this, however the sample program compiled and ran properly but my attached hardware didn't respond. Another person has pointed me to using Windows API. I have searched the MSDN and found only mentions of the appropriate function but without some sample code, I'm lost (maybe I'm searching in the wrong places).

The second problem is that my new computer doesn't have any parallel ports. I must use USB to parallel ports instead (cheap and direct from China, $5 each, shipping and taxes all included). The ports are recognized by the computer as IEEE-1284 controllers and the appropriate drivers were automatically installed and the computer reports the device as "working properly". From what i have seen online, there seems to be a wide variety of opinions on the usefulness of these USB to parallel port connectors. One person says it works perfectly fine like any regular parallel port soldered to the motherboard, another says it will work with some hardware hacks, one says it can write but not read, and finally another says it won't work at all because they are not designed to work the same way as "real" parallel ports. I have already done a great deal of research before coming here (sort of as a last resort I guess, StackOverflow didn't yield any answers even after applying a bounty). Pretty much all the information I found on programming parallel ports is outdated and assumes that you have either a parallel port on your motherboard, a pre-Windows-NT OS, or both. If anyone has any idea how to do this, would you please share it with me? Thanks, -Faken Note: I'm running Windows 7 x64 OS on a Core i7 860. I'm programming in C++ on Visual Studio 2008 pro. The USB to parallel port connectors are connected via USB 2.0 ports. • As you are using an x64 version Windows, make sure that you're using the x64 version of inpout32 (highrez.co.uk/Downloads/InpOut32/default.htm). – timrorr Jul 13 '10 at 13:45 • This is a really late response, but I can give you exactly what you need if you're willing to switch to a unix based OS. Just a couple months ago I wrote C code which controlled individual data pins on the LPT1 port. It was written so that I could program an SPI memory module from the computer since my microcontroller didn't have nearly enough memory to do the batch programming that I wanted. – NickHalden Jun 14 '11 at 12:40 7 Answers Parallel port is dead, and USB microcontrollers are really the future IMO. If you use the HID or CDC profile you don't even need any driver on your PC. Eg the Teensy for$18, you get 25 I/O, of which all can be used as digital I/O, or up to 12 of them as analog inputs and 7 of them PWM channels. The Teensy is more general purpose, if you want something specifically to provide communication between your PC and electronics, there are other devices targeted more towards that, like the Bus Pirate. Or, if you don't need too many I/O's, you could use the standard, fairly simple FT232R USB chip in 'bit-bang' mode, and get 8 digitial I/O out of it.

If you absolutely refuse to listen to reason, then what you need is a PCI card which adds a parallel port, like this one. You'll need a PCI slot (not PCI-Express), most motherboards still have one these days, but they are starting to get phased out.

USB to Parallel adaptors will have all sorts of problems. The main one is latency...standard parallel port latency is measured in microseconds, whereas USB latency is measured in milliseconds. The other is that many USB to Parallel adaptors are designed only for printers, and lack the extra circuitry needed to individually control the address lines in the way you want.

• USB latency is more like hundreds of microseconds, not milliseconds. Hi-Speed USB microframes are 125 us each. – ajs410 Jul 14 '10 at 4:31
• Ok, not as bad as I thought, but the point still stands. What happens if you try to use USB the way you would a parallel port, and send one byte at a time? 1 byte * (1 second / 125 microseconds) = 8000 bytes per second. And it gets even worse if you're say trying to do SPI, bit by bit, instead of something that can handle a whole byte at once. To use USB effectively you need some logic on the other end that can handle sending blocks of data at once, and your logic on the PC side should be designed to not need a response after every byte (or bit). – davr Jul 14 '10 at 18:20
• So I can control up to 8 I/O pins directly from software from the CPU? Would I be able to interface more than 1 of these chips from the same program as well, effectively expanding the number of I/O pins available? – Faken Jul 16 '10 at 22:45
• Another thing to consider with regard to USB is that the latency is not fixed. – Connor Wolf Nov 6 '10 at 3:10

With current technology, if you want to operate on a number of discrete I/O signals, your best bet is to tinker with a dedicated USB microcontroller, or a standard microcontroller coupled with an FTDI USB-to-232 interface.

Old school parallel ports came in a variety of flavors, and not all could do input, since the port was primarily designed to send data to a printer. There were only a couple of handshaking lines that were actually dedicated to input. If you really want to use a USB parallel port, you should look for the EPP or ECP variants, as these were the bi-directional kind.

The fact that you're trying to do this on Windows further complicates the matter. Direct interaction with hardware, while not impossible, is seriously complicated by the HAL. I have done this under Linux using the parapin library, but that was on an older machine with a real parallel port on the motherboard.

Looking at the notes for pyParallel under windows, it seems to require the giveio driver, which rules out the use of a USB -> Parallel adapter.

I'm going to have to agree with Jeff and Joby above. Go get an Arduino or some other microcontroller and tackle the problem that way.

• Just saw this post[1] on the SparkFun blog about using an FT232R for bit-band I/O. This is probably the cheapest way to go for something that will interface via USB. [1] sparkfun.com/commerce//news.php?id=386 – ducksauz Jul 17 '10 at 15:08

You might be better off with an Arduino. Then, you can communicate with your PC application over the RS232 link.

It's not much more expensive than a USB parallel port adapter.

I would like to add that all of the usb to parallel port adapters I have come across do not emulate a parallel port, they emulate a printer over USB and hence cannot be used for their individual IO pins. Perhaps there are some that do this the way you want but surely you would be better off with a USB IO solution with many more IOs such as an IO-Warrior or an Arduino.

Are you sure you hooked your device up to the parallel port correctly? Did you get a pinout, hook up to the right ground, etc? I would get an oscope or a DMM, then toggle all 8 data bits when you press a key on the keyboard, and try to see at least that happen.

Are you using the right address? The default address for motherboard-soldered parallel ports (0x378, I believe) is probably not going to work. You should go through Device Manager's Ports (COM and LPT) node, find your USB->parallel adapter, Resources tab, and find the base address for your adapter.

USB devices have no base address, they are not part of the address space of the CPU, much like a server on the internet is not part of your address space.

And everything about USB to parallel adapters has been said in this tread already, they usually do not work for anything but printing.