0
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ Those resistor values are entirely ballparked. If you see resistors whose values seem to make no sense, they probably make no sense indeed. \$\endgroup\$ – Dzarda Sep 22 '14 at 11:12
  • \$\begingroup\$ @Dzarda - those resistor values do make sense. Atmel recommend consuming less than 20mA from any output pin. (Absolute maximum is bigger, but we don't use absolute maximums normally), Hence any resistor over 250Ω (5V/0.02A) will protect an Arduino OUTPUT pin from a direct short, or another output connected to the same signal being driven in the opposite direction. \$\endgroup\$ – gbulmer Sep 22 '14 at 14:19
  • \$\begingroup\$ @gbulmer Yes, you're right. I tried to emphasize, that sometimes the choice of particular values is rather the designer's artistic sense, rather than the result of precise calculations. \$\endgroup\$ – Dzarda Sep 22 '14 at 14:23
  • \$\begingroup\$ Op clarified in the answer comments they want to replace/emulate a printer, not sniff/mitm. \$\endgroup\$ – Passerby Sep 22 '14 at 16:31
3
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ I think I am a bit confused as to the definitions of sink and source - Yes some of the Arduino pins are inputs, but some are also outputs. In the case of inputs will the parallel port not be sourcing current, if so how do I calculate the necessary resistor? In the case of outputs am I right in thinking I have the option on the Arduino of either sinking or sourcing current? The parallel port TTL pins can also sink or source, so does it matter which I choose? What resistors should I use in each case? \$\endgroup\$ – baseten Sep 22 '14 at 10:49
  • \$\begingroup\$ @blask - I think I agree, there seems to be a confusion. Why are you writing about Arduino pins sourcing and sinking current? Your question says "I'm looking to capture the output of a parallel port to the digital pins of an Arduino, so when printing to LPT1 (...) this can be captured on the Arduino." Hence, ALL of the Arduino's digital pins connected to the printer port will be INPUT mode. Exclude +5V and GND, which are power supply, and nothing to do with listening to the printer port. I think I've covered the case of Arduino pins in INPUT mode in my answer. Is there more you need to do? \$\endgroup\$ – gbulmer Sep 22 '14 at 11:12
  • \$\begingroup\$ In order for the computer to send data down pins 2 - 9 (data pins) of the parallel port at a minimum it needs to receive charges on pin 10 (acknowledge), pin 11 (busy), pin 13 (online) and pin 15 (error). These pins must therefore be in OUTPUT mode and should either sink or source current correct? Pins 10, 13 and 15 should maintain a constant HIGH and drop to LOW for a signal. Pin 11 should be set HIGH after receiving the strobe signal from the computer on Pin 1. See the how stuff works link and the centronics handshake on the retired.beyondlogic link. \$\endgroup\$ – baseten Sep 22 '14 at 11:41
  • \$\begingroup\$ Ah! I had interpreted your question as meaning you wanted to 'snoop' lines connected to a printer! Okay, I can answer that. \$\endgroup\$ – gbulmer Sep 22 '14 at 11:47
  • 1
    \$\begingroup\$ Ah, no - we're looking to entirely replace the printer (and therefore all the necessary signals + handshakes) with an Arduino :) \$\endgroup\$ – baseten Sep 22 '14 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.