Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:16 12 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Dot-matrix printer interface for the MM

     Page 3 of 4    
Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9593
Posted: 12:36pm 19 Jun 2014
Copy link to clipboard 
Print this post

I think you are right there. I seem to recall playing with a LPT laser printer years ago, as a possible substitute for the ageing dot-matrix printers in service, and that was the exact problem.

Dot matrix printers can be made to print line-by-line, but laser printers cannot/will not. I fully expect that you would have to send FF and only print one line per page, which would not really be very efficient!

Pretty much all modern laser printers fully expect to be connected to the likes of a Windows, Linux or Apple machine, which has plenty of power and suitable driver files.

Please prove me wrong, someone!

I suppose there is nothing to stop you keeping track of how many lines you have sent to the laser printer, and once you have about a page, then send a FF and the laser printer SHOULD then print everything sent to it thus far. I guess someone would have to check that idea. Only problem is if there is a power glitch or something otherwise corrupts the printer buffer before it can be printed out - this is what I really like about dot-matrix printers for hard-copies - once it has printed the line out, power-cuts causing loss of the log are not really that much of a worry. Does depend on what you are wanting to do, though. In my case, it is just a line-by-line printout of anything happening on the system, so it is a hard-copy of the activity log. The log is also saved in the SD card, but the printout is really handy for a quick gawk for something specific quickly.Edited by Grogster 2014-06-20
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9593
Posted: 11:59pm 23 Jun 2014
Copy link to clipboard 
Print this post

Here is the new code - can anyone see anything obviously wrong here?


'===== PUT THIS AT THE START OF YOUR CODE, TO INITIALIZE THE PRINTER =====

setpin D2,9: setpin D3,9: setpin D4,9: setpin D5,9
setpin D6,9: setpin D7,9: setpin D8,9: setpin D9,9
port(D2,8)=1 pin(D10)=1: setpin D10,9

pin(D11)=1: setpin D11,9: pause 1:pulse D11,1:pause 1 ' reset printer

setpin D12,2: setpin D13,2 ' these are inputs and must be 5v tolerant


' {MAIN CODE HERE}


'=======================
'PRINTER SUBROUTINE CODE
'=======================

sub PRINTER (P$,T,CR,LF)
Y=0:TOE=0:POE=0:T=T*2:PO$=P$
If CR=1 and LF=0 then PO$=P$ + chr$(13)
If CR=0 and LF=1 then PO$=P$ + chr$(10)
If CR=1 and LF=1 then PO$=P$ + chr$(13) + chr$(10)
for X=1 to len(PO$)
do
pause 0.5
Y=Y+1
loop until pin(D12)=0 or Y=T or pin(D13)=1
If Y=T then TOE=1:exit sub 'Check TOE once the sub ends, to see if there was a TimeOut Error.
If pin(D13)=1 then POE=1:exit sub 'Check POE once the sub ends, to see if there was a PaperOut Error.
C$=mid$(PO$,X,1)
port(D2,8)=asc(C$)
pause 1:pulse D10,1
next
end sub


This code fixes the bug with the local variables - I removed the LOCAL line totally. Probably not the most efficient, but it works. If you are short of RAM, you might need to add a LOCAL line of your own.

This all seems to be working with the first printer(Panasonic) that I tried it with, but will test it with the other printers I have in the next few days.

TOE(Time-Out Error) testing has not been done yet, as the Pana printer did not have any issues with the 250 setting for T I used, but I will gradually reduce that, and see what happens....

POE(Paper-Out Error) does seem to work though, as if I position the paper right at the end, and print a few lines, the sub does return with POE=1, even though the printer has not printed anything(and has also indicated that it is out of paper)Edited by Grogster 2014-06-25
Smoke makes things work. When the smoke gets out, it stops!
 
VK2MCT
Senior Member

Joined: 30/03/2012
Location: Australia
Posts: 120
Posted: 01:54pm 24 Jun 2014
Copy link to clipboard 
Print this post

i'm confused as to the purpose of the passed variable 'T'.
It seems to get doubled 'T=T*2'.
And then gets compared to the charcount 'Y', to generate a TOE.
What have I missed.

John B.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9593
Posted: 02:43pm 24 Jun 2014
Copy link to clipboard 
Print this post

T is the timeout variable - used to allow the sub to not get stuck in there forever if the printer gets held up for some reason. Suggested by Rob, and I thought it was a good idea, so put it in there.

T is doubled, as in the loop, I check the if the printer is busy, out of paper or ready for the next byte every 500uS. The idea being to minimize the loop delays.

Y is just the loop counter, and if this then equals the T timeout figure as passed to the sub, then the sub will exit with a TOE flag set to 1.

I still need to check this with a couple of other printers - hope to do this soon.
Smoke makes things work. When the smoke gets out, it stops!
 
Herry

Senior Member

Joined: 31/05/2014
Location: Australia
Posts: 261
Posted: 02:49pm 24 Jun 2014
Copy link to clipboard 
Print this post

I shudder to think of the number of dot matrix printers I have thrown away! I see at one of our on-line computer parts companies that a new one is over $500. Well over a laser printer cost!
Senior?!  Whatever it says, I'm a complete and utter beginner...
 
VK2MCT
Senior Member

Joined: 30/03/2012
Location: Australia
Posts: 120
Posted: 03:03pm 24 Jun 2014
Copy link to clipboard 
Print this post

So,
If T is set to say 20.
Second line doubles that to 40.
Then when char count gets to 40 (Y=T) - main loop finishes.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9593
Posted: 03:07pm 24 Jun 2014
Copy link to clipboard 
Print this post

Yeah, this is where eBay or your local 2nd hand shop can be really handy. Local computer repair shops can also help you track 2nd hand printers down. Most of the printers I have stacked up here, I just grabbed when they were on offer, and I only paid $20 or so for them.

I am thinking about the laser-printer idea, but have not written anything yet.
As most laser-printers print page-by-page, you'd have to buffer a page of text, then send that. This should not be impossible using the SD card for the page buffer, and then when you have a page of lines, the MM could feed that to the printer, but I would expect that this would be time-consuming(clocking a page of text to the printer), and so probably not practical. Food for thought, anyway...
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9593
Posted: 03:13pm 24 Jun 2014
Copy link to clipboard 
Print this post

  VK2MCT said   So,
If T is set to say 20.
Second line doubles that to 40.
Then when char count gets to 40 (Y=T) - main loop finishes.


Correct - IF the printer is being held up. Every time the code loops, Y is reset to zero again. It is only done like that, cos I am checking those things TWICE for every ms of T, so in order to keep the T variable as full ms figures, I double T in the sub.

Technically, you don't need that - you could remove the T=T*2, and just submit 40(using your example). This is just the way I did it - which is not necessarily the way others may do it!

EDIT: Actually, there is a small bug there - Y=0 probably should be at the end of the code before the next, as at the moment, this busy code will only work for the first time through the loop, then Y will be greater then T(cos I have not reset it), so the code WON'T exit.

Something to fix.

ANOTHER EDIT: "Then when char count gets to 40 (Y=T) - main loop finishes." - No. It's not so much about counting the characters sent to the printer, as the amount of time that the printer signals that it is still busy.

For example: The printer may have accepted 35 characters, then something holds it up. The loop is designed to pick up on that, and auto-exit from the sub with the timeout flag set, so that the sub does not get stuck forever in this code, IF the printer gets bothered about something.

All that BUSY stuff was Rob's(robert.rozee) idea, and was very good advise. Edited by Grogster 2014-06-26
Smoke makes things work. When the smoke gets out, it stops!
 
Herry

Senior Member

Joined: 31/05/2014
Location: Australia
Posts: 261
Posted: 03:23pm 24 Jun 2014
Copy link to clipboard 
Print this post

... time-consuming(clocking a page of text to the printer), and so probably not practical. Food for thought, anyway...


What time are we talking about? Up to 5 seconds per page I would say is quite reasonable. Perhaps a little longer. And would that be for each page? If for the print job I reckon much longer would be OK if you gave the user an informative message, perhaps a count down clock or a progress bar.
Senior?!  Whatever it says, I'm a complete and utter beginner...
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9593
Posted: 03:28pm 24 Jun 2014
Copy link to clipboard 
Print this post

If I had a laser printer with a LPT interface, it would be something I would like to play with.

Next laser printer I buy, I will look for an LPT port!

As for time - I have no idea really, till you tested it.

Buffering to the SD card would work fine, but there would be a delay while the data was sent to the printer on a page-by-page basis.

I think it would be do-able though, using a laser printer with an LPT port on it - some experiments would need to be made etc...

If it takes an average of 188ms or so per line on dot-matrix, then assuming an 80-line page, it would therefore be 15,040ms, or 15 seconds on average, to send the data to the laser printer on an LPT port, on a page-by-page basis.

You could get crafty, I suppose, and make the printer routine an interrupt, and it will send one byte at a time, then loop back to the main program, and keep doing that till it had emptied the page buffer file on the SD card, but that would require some work.

Anything is possible if you want it badly enough!!!!
Smoke makes things work. When the smoke gets out, it stops!
 
halldave

Senior Member

Joined: 04/05/2014
Location: Australia
Posts: 121
Posted: 06:03pm 24 Jun 2014
Copy link to clipboard 
Print this post

Have you thought about an MMBasic PCL Driver, I used to have to do this out of a HP3000 CPE based beast in COBOL. Connected serially to the LaserJet. Once you have it setup pretty easy to do most things, and some limited graphics"

for example




pcl_NumberofCopies$ = chr$(27)+"&l"+ trim$(str$(numberofcopies)+"X"
pcl_Simplex$= chr$(27)+"&&l0S"
pcl_PaperType$=chr$(27) + "&l26A" ' Set Paper type to A4
pcl_Portrait$ = chr$(27) + "&l0O"
pcl_Landscape$ = chr$(27) + "&l1O"
pcl_ProportionalSpacing$= chr$(27)+"(s0P"
pcl_PrimaryStyleItalic$=chr$(27)+"(s1S"
pcl_PrimaryStyleCondensed$=chr$(27)+"(s4S"
pcl_PrimaryStyleExpanded$=chr$(27)+"(s24S"
pcl_PrimaryStyleOutline$=chr$(27)+"(s32S"
pcl_FontTimesNewRoman$=chr$(27)+"(s16901T"

..
.. There are heaps of commands the above was just a couple my poor memory still had in it, only in COBOL I had to send them to the printer in Octal






Open Your Com port as #1

Print #1, pcl_portrait$
..
...
...




you will really need to play as was around 20 years ago I last did this stuffr
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6269
Posted: 07:16pm 24 Jun 2014
Copy link to clipboard 
Print this post

I have the PCL laser printer (HP1015) but it is parallel (and USB), not serial.
It is my main printer and can I can talk to it from DOS and Windows from 3.11 to 8.1

I like PCL language and I have an old customer who's business still uses W3.11 so I need the HP as a spare for him. Old canon inkjets also use a PCL-like language.
I have to support him because no one else remembers W3.11!


The A0 plotter in the shed does have serial so it would be easier to play with.

If you want to get serious, I would dedicate a micromite (with serial memory if required) as a serial to parallel converter and leave the main maximite to do the other stuff.

Jim
VK7JH
MMedit
 
halldave

Senior Member

Joined: 04/05/2014
Location: Australia
Posts: 121
Posted: 07:41pm 24 Jun 2014
Copy link to clipboard 
Print this post

If your HP Laserjet has USB then is there a cheap adapter from RS232 to USB
or can you convert the Paralell using a IEEE 1284 to RS232 adapter?? Others more ofay with the hardware maybe able to comment as I'm an old Software engineer

What brand A0 is it... I used to send strings to a HP 7585A plotters i remember PenUp PenDown, From to Coordinates, Change pen and text.... sadly I did this in late 1980's in COBOL yet again and my brain refuses to recall the info.

regards

David
 
halldave

Senior Member

Joined: 04/05/2014
Location: Australia
Posts: 121
Posted: 07:54pm 24 Jun 2014
Copy link to clipboard 
Print this post

Could you develop a Paralell printer driver

From an earlier post

  Quote  

MMBasic isolates the user from the physical details of the chip (eg, PORTC, PORTA, etc) so you do not have to worry about what ports the chip has.

To do parallel I/O you can use the PORT command. For example on the 44 pin chip you could use the following to output 8 bits in parallel:
PORT(8, 8) = EIGHT_BIT_DATA

or
PORT(8, 8, 19, 8) = SIXTEEN_BIT_DATA

to output 16 bits of data in parallel.

The last example uses an extension of the PORT command that crept in with the Micromite version of MMBasic.

Geoff
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6269
Posted: 08:02pm 24 Jun 2014
Copy link to clipboard 
Print this post

I haven't found any RS232 to USB adapters. Plenty that go the other way but none that work with RS232 on the PC and USB on the printer. I think a Raspery Pi or similar would do the job.
Serial to parallel adapters are available but expensive (compared to a micromite).

The HP plotter was purchased for $10 at an auction and came with a box of new pens and ink. I don't remember the model and too cold to go down there now.

The laser I wold like to get next will have Ethernet built in like my HP2500 A3 printer. Another $10 auction item.
It is easy to get RS232 to Ethernet for the maximite (but not cheap).

B...dy money and the lack of it gets in the way again.

Jim
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9593
Posted: 08:08pm 24 Jun 2014
Copy link to clipboard 
Print this post

The main problem with USB printers, as I understand it, is that you can't talk to them just by adding a RS232-USB adaptor - it's not that simple with the USB printers. The driver software does all the interpretation between the PC and the printer itself(via the USB port), so unlike the nice simple LPT printer, where all you need to do is send the ASCII letter bytes then a LF or CR or both, USB printers would totally ignore you if you tried to do that on their USB connector, even with an RS232 adaptor.

Please prove me wrong, but that is my understanding of things.

@ TassyJim - you are right about the dedicated uM chip as a serial-parallel interface chip and buffer memory - that is a great idea, and is probably the best way to do it, actually. My SD buffer idea was cos I was still thinking in full-size MM terms...
Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:49pm 24 Jun 2014
Copy link to clipboard 
Print this post

Very often pages are also fully rendered in the PC to save on resources needed in a printer, making the printer cheaper and your PC slower. These kind of printers are impossible to use without the accompanying driver software.

Microblocks. Build with logic.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9593
Posted: 09:32pm 24 Jun 2014
Copy link to clipboard 
Print this post

@ TZA - yes, indeed. That is another point....

Here are a couple of photos.





The third line on the printer says: "Thanks to CircuitGizmos for this idea" - the printer ribbon on this printer is getting a little dry.....

EDIT: No matter what size I make this photo, the forums are re-sizing it, so you probably can't read the other two lines either, which say: "Test message." and "Hello Back-Shed people!!!"

Edited by Grogster 2014-06-26
Smoke makes things work. When the smoke gets out, it stops!
 
halldave

Senior Member

Joined: 04/05/2014
Location: Australia
Posts: 121
Posted: 09:40pm 24 Jun 2014
Copy link to clipboard 
Print this post

You can pick up 5 of these 16Pin 8-Bit Serial-in To Parallel-out Shift Register IC DIP-16 PIN 74HC595N for $3.00 AUD delivered


Symbol Pin Description
Q1 1 parallel data output 1
Q2 2 parallel data output 2
Q3 3 parallel data output 3
Q4 4 parallel data output 4
Q5 5 parallel data output 5
Q6 6 parallel data output 6
Q7 7 parallel data output 7
GND 8 ground (0 V)
Q7S 9 serial data output
MR 10 master reset (active LOW)
SHCP 11 shift register clock input
STCP 12 storage register clock input
OE 13 output enable input (active LOW)
DS 14 serial data input
Q0 15 parallel data output 0
VCC 16 supply voltage

The 74HC595N shift register features 16 pins, 8–bit, with a storage register and 3-states output. The input of shift register is compatible with standard CMOS output, it is compatible with LSTTL output.

Description:

Gated serial data inputs, parallel–outputs
Applied to serial to pararrel data conversion
Model No.: 74HC595N
Storage register with 3-states output
Shift register with direct clear
100MHz shift out frequency
Outputs directly interface to CMOS, NMOS, and TTL
Total Size: Approx. 18 x 7 x 7mm
Package: DIP16


http://www.nxp.com/documents/data_sheet/74HC_HCT595.pdf
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 01:29am 25 Jun 2014
Copy link to clipboard 
Print this post

I've had one of the USB to parallel (Centronics) cables for a few years now - bought it to run my old multi-function fax/printer from the Notebook (in the early XP days) and it works fine. Can't remember what it cost but it uses a Prolific PL-2305F chip - 48 pin SSOP. The USB driver was supplied with it on a mini CDROM.

As Tassy says though, it's the wrong way round. We need the USB plug on the printer end.

Greg
 
     Page 3 of 4    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025