Dotmatrix Printer on an AVR

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys,

I'm trying to interface an AtMega32 with an old dotmatrix printer, but the damn thing wont budge.

Am I correct in assuming I can just put an ASCII character on the data lines, latch it in by pulling strobe low for a few ms, and the dotmatrix will print the character? Or do I need to assert other control signals ?
I figure it's as simple as sending "Hello". Right ?

Here's my quick and dirty setup :
(All signals lines have 1k resistors)

DB25	SPP
Pin	Signal	Port
--------------------
 1		Strobe	PC0
 2		D0		PD0
 3		D1		PD1
 4		D2		PD2
 5		D3		PD3
 6		D4		PD4
 7		D5		PD5
 8		D6		PD6
 9		D7		PD7
10		nAck		
11		Busy		PC1
25		GND		GND

note : nSelect (pin 17 on the DB25) is pulled low by the printer.
#include 
#include 

/* Defines */
#define PORT_DATA		PORTD
#define PORT_CTRL		PORTC

#define PIN_STROBE	  (1<<0)
#define PIN_BUSY		 (1<<1)

int main(void) 
{
	unsigned char i;

	DDRD = 0xff;
	DDRC = 0x01;

	PORT_CTRL = PIN_STROBE;

	for (;;) {

		PORT_DATA = 'A';

		PORT_CTRL = 0;
		_delay_ms(10);
		PORT_CTRL = PIN_STROBE;

		for (i=0;i<100;i++)
			_delay_ms(10);
	
	}
}

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's been a very long time, but I think some of the old printers buffered a line prior to printing anything. It may need to see a CR, LF, or CRLF before it does anything. This would especially be true on those which could do bidirectional printing.

Then (I'm almost embarrassed to mention it) some of the printers had both serial and parallel (Centronics) interfaces, selected by DIP switches. If you have both, the parallel interface is the active one, I hope.

My first question would be: are you getting the character by character ACK from the printer?

Then I'd send it one or more characters, fewer than 79, followed by a CR and LF. I'd also watch the busy line, since the printer can go busy for a second or more as it prints, and it gets grumpy if you try to talk to it during that time.

Also, plug it into your PC, select a generic text driver, and see if the thing will let Windows print to it.

I'm sure there's more to say, but my brain went to bed a couple of hours ago.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My Epson LX-800 (which is still working and attached to the Oscilloscope for printing screenshots) has DIP switches for setting or and the codepage used for ASCII characters. I know that the Star printers had them, too.

So checking the ACK signal from the printer and fiddling with the DIP switch settings (if there are any) would be my first attempts at solving this.

@Chuck: Why should you be embarrassed because the printers had serial and parallel input? Back then I´ve always longed for a printer with serial input so I could keep my hand scanner attached to the parallel port.
(you know, hand scanners are the devices that you´d pull over the page by hand and which were so narrow that you had to scan an standard sheet of paper in two rows, which never worked as it should?)

Ingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the response guys!

I just wanted to quickly test if I could make it print like this.

I must admit I have not tested the printer on a pc for some time..
Last time I used it, I know I could send data to it on the command line like this :

echo Hello>LPT1

And it would just slam those letters on the chain-paper and move one position to the right.

I will test the printer on my pc when I get home this evening. If it is working I'll take a look at what the ack signal is doing. And add some code so that it will actually send a string ending in a CRLF.

So I gather you guys agree this should work.
I don't need to assert other control signals?

Thanks,
Bob T.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You might take a look at pin 16 (nInit). Probably a red herring, but worth mentioning...
And make sure that nSelect is low. You say it's pulled low by the printer - how do you know? With what are you measuring?

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi John, thanks for the reply.

I assumed there's a pullup in the printer on pin 16, when I pull this pin low the printer reinitializes, I have tried connecting it to a high level, but no result. Maybe I should hook it up to Vcc just to be certain.

As for the Select Line, the Printer has a switch labeled "SEL", which controls the state of this signal.
I had "SEL" switched to ON, and applied Vcc to the Select Signal, what triggered the Current Limiter on my power supply.. So I gather this pin is Low..

Bob T.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Why should you be embarrassed because the printers had serial and parallel input?

It was the implication in the question that the OP might be trying the wrong interface, not that it had two. I didn't want to be insulting. :)

Here's a little more info on the interface. The main thing I notice is that the strobe is 1.5 microseconds, not the "few milliseconds" you mentioned, although my guess is the transition is all that matters.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, the printer only has a Centronics connector, a DIP switch for codepage selection and a switch controlling the Select line.

I just tried to hook it up to my pc and it is working, so first i'm going to take a look at the logic levels of the pins.

Thanks for the link Chuck, most stuff I found was focused more on the pc controlling side than on the acutal interface.

I didn't double-check sources, and found this on one webpage (http://interface.centraltreasure.com/parallelport.html):

Quote:

The program then asserts the strobe, waits a minimum of 1mS, and then de-asserts the strobe.

Must be a typo, I didn't think twice about it. Anyway, the data is latched in by the printer on the rising edge of Strobe, so I gather this timing isn't that crutial.

EDIT:
Just removed the 1k resistors from the signal lines and now it's working. I does seem to buffer data until it receives the character.

Anyway, thanks for the help guys.

Bob T.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thygate wrote:
Anyway, thanks for the help guys.
You´re welcome, Bob. Your project was the spark for another item on my own project list.

I have one of those small printers used in cash registers, but never actually found a use for it. Seems perfect for a data logging unit using an AVR. Now if I only had something that needed logging on a paper strip :D