Page 1 of 1

Wireless Printing

Posted: Wed Sep 16, 2020 11:03 am
by rodders
If you're like me you kept the old Beeb that you had in the eighties but any centronics based dot-matrix printers and fan-fold paper have long gone. When I'm developing code I occasionally like to print some of it so I can scribble modifications while I'm scratching my head. I therefore decided to see if I could send print from the serial port to my wireless printer. It seemed to be a fairly straightforward project that my simple mind could cope with (I thought).
The hardware involved is an RS232 <-> TTL converter and a Wemos Di.
The first test was to see if I could send something to the printer successfully so I wrote some code for the Wemos to connect wirelessly to the printer and had some early success by wrapping sample text with HP PJL and PCL magic. The next test was to receive some text from the Beeb via the serial port and barring some wiring issues this seemed to work OK too. The problems started when I tried to combine the two. As I received characters from the Beeb I sent them on to the printer with the PJL and PCL wrappings. However, since the WiFi is interrupt driven I found that the Wemos was dropping characters, even at slow baud rates, as the cheapo TTL converter I had didn't support handshaking lines.
To cut a long story short, I bought another converter from Tronisoft with handshaking support and I'm now printing at 9600 baud without problems.
I've now enhanced the code so that it can be configured for the WiFI and printer from the Beeb.
If anyone is interested I can post more details and I'm happy to share the code.

Re: Wireless Printing

Posted: Wed Sep 16, 2020 9:19 pm
by roland
I am very interested in this project since I am working on a printer driver for the ElkWiFi board. The part to communicate with the wireless lan is already done as you can read here.

So if you already have some software to convert the plain text to PCL and send it to the printer that would save me a lot of work :lol:

Besides that, can you also post some pictures and a wiring diagram?

And can you also connect to a webserver to download a file? If so, then that will be a useful alternative for BBC and Master owners who want their computer online.

Re: Wireless Printing

Posted: Thu Sep 17, 2020 11:27 am
by rodders
Hi roland. I can certainly share my PJL/PCL code and I'll upload some pics and a circuit diagram.

Re: Wireless Printing

Posted: Thu Sep 17, 2020 11:45 am
by rodders
Here are some code fragments that should get you started (in cpp):

Code: Select all

WiFiClient client;

const char* UEL 			= "\033%-12345X";
const char* PJL_Start_Job		= "@PJL JOB NAME = \"BeebPrint Job\" DISPLAY=\"BeebPrint\"\n";
const char* PJL_Language		= "@PJL ENTER LANGUAGE = PCL\n";
const char* PJL_End_Job			= "@PJL EOJ\n";
const char* PCL_reset 			= "\033E";
const char* PCL_wrap 			= "\033&s0C";
const char* PCL_left_margin_portrait 	= "\033&a5L"; // 5 chars in
const char* PCL_right_margin_portrait	= "\033&a75M"; // 75 chars in
const char* PCL_top_margin_landscape 	= "\033&l4E"; // 4 chars down
const char* PCL_left_margin_landscape	= "\033&a0L"; // 0 chars in
const char* PCL_right_margin_landscape = "\033&a110M"; // 110 chars in
const char* PCL_underline_on 		= "\033&d0D";
const char* PCL_underline_off 		= "\033&d@";
const char* PCL_simplex 		= "\033&l0S"; // single sided
const char* PCL_duplex 			= "\033&l1S"; // two sided, long edge
const char* PCL_portrait 		= "\033&l0O";
const char* PCL_landscape 		= "\033&l1O";

bool landscape = false;
bool duplex = false;

...

sendPJLHeader(client);
sendPCLHeader(client);

// Send text

sendPCLFooter(client);
sendPJLFooter(client);

...


void sendPJLHeader(WiFiClient client) {
	client.write(UEL);
	client.write(PJL_Start_Job);
	client.write(PJL_Language);
	client.write(UEL);
}

void sendPJLFooter(WiFiClient client) {
	client.write(UEL);
	client.write(PJL_End_Job);
	client.write(UEL);
}

void sendPCLHeader(WiFiClient client) {
	client.write(PCL_reset);
	if (duplex) {
		client.write(PCL_duplex);
	}
	if (landscape) {
		client.write(PCL_landscape);
		client.write(PCL_top_margin_landscape);
		client.write(PCL_left_margin_landscape);
		client.write(PCL_right_margin_landscape);
	} else {
		client.write(PCL_left_margin_portrait);
		client.write(PCL_right_margin_portrait);
	}
	client.write(PCL_wrap);
}

void sendPCLFooter(WiFiClient client) {
	client.write(PCL_reset);
}
I haven't done any formatting of the text yet, I'm just printing what the Beeb sends. You may find these useful for PJL/PCL info if you want to format the text:
https://developers.hp.com/system/files/ ... Manual.pdf
http://www.hp.com/ctg/Manual/bpl13210.pdf

Re: Wireless Printing

Posted: Thu Sep 17, 2020 12:29 pm
by roland
Thanks, this looks quite simple. Once I establish a TCP connection with the printer I only need to send some control codes and the text. Just like on my good old Seikosha SP180-AI dot matrix printer BITD :lol:

Re: Wireless Printing

Posted: Thu Sep 17, 2020 1:54 pm
by rodders
Here are some pics:
IMG_20200917_133811081.jpg
IMG_20200917_133640724.jpg
IMG_20200917_133421972.jpg
IMG_20200917_133309397.jpg

Re: Wireless Printing

Posted: Thu Sep 17, 2020 2:38 pm
by rodders
and here is a circuit diagram:
BeebPrint.png
the labelling of the connections on RS232<->TTL modules can be inconsistent so it may be necessary to swap TX/RX and CTS/RTS.

Re: Wireless Printing

Posted: Thu Sep 17, 2020 9:27 pm
by roland
Well that's really simple hardware compared to my ElkWiFi board. But the Elk has no serial port so I had to make it complicated :lol:

Can you also download files from the internet with this interface? Assuming you write the correct software for it. How do you give instructions to the D1, like connect to a WiFi network, establish a connection with the printer and so on?

Re: Wireless Printing

Posted: Fri Sep 18, 2020 8:27 am
by rodders
I guess you could download files but I haven't written the code for that. The D1 can be programmed like an Arduino and there are libraries for connecting to Wifi etc. I could attach the complete code if you're interested.

Re: Wireless Printing

Posted: Fri Sep 18, 2020 9:50 pm
by roland
You are really a great help for me. Thanks to you I did some experiments and it seems that printing via the network is just as simple as on a good old matrix printer from BITD.

On my Mac I did a telnet to port 9100 of my printer and it responded:

Code: Select all

MacDevelop:~ roland$ telnet 169.254.141.196 9100
Trying 169.254.141.196...
Connected to 169.254.141.196.
Escape character is '^]'.
Then I pasted just a small piece of text to the open telnet session and .... it came out of the printer. Just plain ascii in courier format. This is really great, I never thought that printing could be sooooooo easy 8)

So, the next thing I am going to try is to connect from my Elk to the printer and just start dumping data. The ESP8266 has a pass-through mode which is great for this purpose. Thank you for starting this topic :-D

Re: Wireless Printing

Posted: Sat Sep 19, 2020 8:50 am
by Alan00
On my BBC I set my wifi modem to my laser printer using commstar

ATDT10.1.1.251:9100

Back in basic
*FX5,2
*FX8,7
*FX6,0

Control B to start sending data to printer
Control C to stop sending data.

I had to press GO on the printer to start printing.

Re: Wireless Printing

Posted: Sat Sep 19, 2020 11:39 am
by roland
Does vdu 12 or Ctrl- L start the print job just before ctrl-c?

Re: Wireless Printing

Posted: Sat Sep 19, 2020 12:36 pm
by Alan00
Yes, CTRL - L does start the print job

Re: Wireless Printing

Posted: Sat Sep 19, 2020 11:23 pm
by roland
On the Electron it's also starting, for more information look here.

Re: Wireless Printing

Posted: Sun Sep 20, 2020 9:25 am
by jgharston
roland wrote:
Sat Sep 19, 2020 11:39 am
Does vdu 12 or Ctrl- L start the print job just before ctrl-c?
Yes, on a page printer you need to tell the printer that you've finished sending the data for that page, by sending Page Eject (ie, Form Feed).

Whereas on a line printer you need to tell the printer you've finished sending the data for that line by sending a Line Feed (or causing an automatic line feed with a Carriage Return).

Otherwise, how does the printer know you've finished sending the data for the print unless you tell it you've finished sending the data for the print?

Re: Wireless Printing

Posted: Sun Sep 20, 2020 11:27 am
by roland
I asked him if CTRL+L did start the print job just because of what you said :lol:

However, yesterday I noticed that my OKI laser printer also starts to print after the data communication (over the network) has timed out. But I don't think we can compare that with a dot matrix line printer.

Re: Wireless Printing

Posted: Mon Sep 28, 2020 10:45 am
by Alan00
I have built a prototype Arduino interface for the printer port, so that when data is sent to the printer port, it sends data out at 9600 baud.
Connected to the Arduino is an ESP8266 which I have programmed to connect to my printer via WiFi.

The prototype is small enough to fit under the BBC and takes power from the user port.
I'm using a Brother laser printer, CTRL+L starts printing or just wait a few minutes and the printer starts.