Connecting a parallel port to an Arduino

arduinoohms-lawparallel portresistors

This is my first Arduino project and while I remember a (tiny) bit of electronics from school I'm struggling to get this working – in fact I've just fried a parallel port PCI card!

I'm looking to communicate via a PC's parallel port to an Arduino, so when printing to LPT1 (as plain text + ESC/P) this can be captured on the Arduino. I've read up on the parallel port and pinouts and I think I have everything wired up correctly, but I'm a bit unsure on the resistors to use. Some of my references so far have been:

http://retired.beyondlogic.org/spp/parallel.pdf
http://nemesis.lonestar.org/reference/computers/interfaces/centronics.html
http://computer.howstuffworks.com/parallel-port1.htm
http://arduino.cc/en/Hacking/ParallelProgrammer

The ParallelProgrammer example uses 220 ohm and 470 ohm resistors, but without explaining why and this I believe is also interfacing with the Arduino serial port not the digital pins. This isn't helped by the fact that there appears to be significant variation in the specs for parallel port sink and source currents (explained in the retired.beyondlogic link).

Firstly, am I right in thinking that I will be sourcing current from all computer -> arduino pins and sinking current to all arduino -> computer pins?

If this is the case, is the use of a 470 ohm resistor on source pins to limit the current to 12mA @ 5V? Why the use of the 220 ohm resistor? I've seen other specs here (http://www.ahmetozkurt.net/comporg/ekonomi/hw2006/selen2/howtoconnect.htm) which also suggest that parallel ports source 2.6mA @ 2.4V but can sink 24mA @ 4.2V.

Assuming I can get to the bottom of the source / sink current and voltage, do I need a resistor for each pin except ground?

Best Answer

To 'replace' a printer on a Parallel Printer Port (PPP) with an Arduino, the Arduino will need to 'listen' to some PPP signals, and drive other PPP's signals.

When 'listening' to the printer port output, the Arduino pins will be INPUTs. They will not source or sink any current. The printer port will be supplying all current to the Arduino's INPUT pins.

Arduino pins in digital INPUT mode consume tiny amounts of current (1 microamp), and so the current source and sink capability of the printer port will be completely adequate.

One thing that does matter is the voltage of the printer port pins. As it is 'TTL', it is 5V and so should be safe.

I can not find any specification for the current that the printer ports input pins will consume. PPP output pins are specified as providing at least a few milliamps, hence it seems reasonable to assume inputs use less, i.e. less than a few milliamps. Otherwise the spec should say something more specific about input pins because it is reasonable to expect that an output pin meeting the spec can drive an input pin in unless the spec gives more information.

The terms source and sink only apply to output pins (and this is normal). To source current effectively means drive an output signal HIGH (5V). To sink current effectively means drive an output signal low (Ground). An output pin may need to do both, though that is not always the case.

An Arduino OUTPUT pin can drive at least 12mA when it is sourcing or sinking current. It has 'symmetrical' drive capability; it can 'source' or 'sink' the same amount of current whether it is pulling a signal high (sourcing) or low (sinking). So OUTPUT pins can be connected to the PPP input signals. (NB: some other manufacturers microcontroller's output pins can sink more than they can source.)

The electronics of an Arduino (Atmel AVR MCU) pin in pinMode OUTPUT is able to source and sink current. The software only needs to set the pin's output register high or low, and the pin's electronics takes care of the rest 'automatically'. The software isn't concerned with how that happens because the electronics is designed to take care of that itself.

However, there is always a chance of something getting shorted, or, more likely, software containing a mistake. A software mistake which could damage an Arduino pin would be setting a pinMode to OUTPUT instead of INPUT, while the pin is connected to a PPP output signal. The damage could happen quite quickly. It is possible that the PPP signal goes high while the Arduino pin tries to go low. At least one of them may be permanently damaged.

We often protect an Arduino pin from this using a resistor of a few hundred ohms (e.g. 250-500 ohm). That is probably why you see resistors on signals. You could do a similar thing to protect the Arduino and printer port. It is not essential, it will work without resistors. However, the extra protection is safer, and might enable you to fee more confident. (Resistors may also reduce the amount of electrical noise generated by very fast signals, but I don't think that is an issue here.)

It may also make some sense to protect Arduino output pins from an accidental short, using a resistor on the lower edge of safety. For example 220Ω allows 22mA to flow, which the ATmega should comfortably supply for a single pin short.

Summary: the interface should not need any resistors.

However, including resistors in the signals to protect input and output pins is reasonable.

Protecting input pins from the software mistake of accidentally setting pinMode to OUTPUT is very reasonable, especially while writing software. Similar protection for an Arduino OUTPUT makes sense too. However without a spec for the printer ports input, it may be better to use a lower-end value for protection (220Ω is the minimum which keeps a single pin mistake, and other pins active, within the ATmega specification).

Also consider measuring the voltage applied to the printer port by an Arduino output pin with an oscilloscope if things don't work, or seem unstable. I would not expect a problem on the printers input pins, but it's good to keep an open mind.

NB: the word 'software' is used to mean both software and firmware.

Side note:
The Arduino Parallel Port Programmer is driving the Arduino's SPI port, not its serial port. That is one way the ATmega can be programmed.