Dot matrix printer

From XPUB & Lens-Based wiki

Dot-matrix printing

What is the materiality of dot-matrix printers?

Producing graphics and layout produced with text!

BUT. Computers don’t actually work with text.
Computers are calculators that work with numbers only.

This means that any kind of input to the computer and any kind of output from the computer exists as numbers somewhere in between.

To explore the layers and complexities of these encoding and decoding processes, dot-matrix printers are great to work with.

Turning the printers on

Taking an exploratory approach...

  1. Pick one printer
  2. Print the self-tests of the machine
  3. Print the menu with the current settings

Now, let's try to talk with printer from a computer.

  1. Connect to the printer, you can follow the #Howto section below.
  2. Once you are connected, print some words or plain text files from the command line. See which command works for you:
$ echo "hello" > /dev/usb/lp1
$ echo "hello" | lp
$ lpr hello.txt

What language does the printer speak?

Let's zoom into the text we just sent to the printer...

To do so, we will switch to Python and send commands from there.

First we send a hello.

msg = "hello"

# Linux/OSX?
printer = open("/dev/usb/lp1", "w")
printer.write(msg)
printer.close()

# Windows/OSX
import os
printer = open("tmp.txt", "w")
printer.write(msg)
printer.close()
cmd = "lpr tmp.txt"
#cmd = "cat tmp.txt | lp"
os.system(cmd)

Here, we are sending hello to the printer... so the character h, e, l, l, o.

What is special about these machines, is that you can not only send letters like these, but you can also send special printer commands that change the behavior of the printer.

And in order to type these characters, like a line feed character (LF), we use an 💀encoding system💀...

One famous one... is... ASCII.

$ ascii

Asciitable.png

But the printers do not speak 100% ASCII, each of them speaks their own language.

To find their language... we need to dive into their manuals.

Dot-matrix printers @ XPUB

OKI Microline 320

Oki-microline-320.png

Test report 5 Feb 2025:

Joseph and Manetta tried to get this printer to work, we changed the settings to match the NEC printer, but this did not help.

Current intuition is that it is a hardware issue.

NEC PINWRITER P60

Screenshot from 2025-02-05 13-35-48.png

This printer has 21 pins. One is broken, you can see it.

In the back there are magnets, one for each pin, and when the electricity hits the magnet, the pin is being activated or not.

There are 2 rows of pins, one is slightly shifted (you can see it!), which makes the resolution higher. It is divided into 2 rows, because there is no mechanical space to have so many pins so narrowly next to each other in one row.

The printer works with 80 columns.

NEC PINWRITER P20

NEC-Pinwriter-P20.jpg

Running the self test: see page 5 in the manual (page 13 in the pdf)

Printing the menu with current settings: see page 17 in the manual (page 25 in the pdf) [SELECT + Power on]

Citizen Swift 90e

Citizen-swift-90-printer.jpg

The printer works, but the continuous paper feed (for the paper with holes on the sides) is a bit slippery, so you need to help the printer a bit sometimes. If you use the external paper feed adapter and work with A4, it's much smoother.

Did manage to print test pages and the menu! But did not manage to change the settings in the menu... the printer gives an error.

How to print test pages? See page 29 in the manual: Printer Self-Tests.

How to print the menu? See page 25 in the manual: Making A Print Out Of The Printer’s Default Settings.

More info on codepages? See page 32 in the manual: Codepages - International Characters.

Sending printer control commands works when you use the build-in Epson FX1170 emulation (found this in the technical sheet). See Epson FX1170 manual chapter 8 "Command Summary" for a listing of special commands.

Star SG-10

Star-SG-10.jpg

The language in the manual is funny, very conversational :).

You can switch between character sets, "modes" and character pitch (size) using the dip switches. See page 133 in the manual.

Dot-matrix printing in practice

There is a way to speak to these pins individually.

A driver translates the pixelated image into the pins of the printer. Here you can find dithering strategies to convert an image into a type of image that could be printed on the dot-matrix printer. So dithering was a technical limitation. These days, it's often an aesthetic choice, which is different.

Before was the daisy wheel printer (close to typewriter), but with the dot-matrix printers you can make your own characters. Which helped to promote it and sell it internationally. Other character cards were also distributed, with fonts etc, which you could load into your printer.

There was not one fixed character set for all dot-matrix printers.

You send a character as ASCII, and depending on which font is loaded, it is printed.

Some ASCII characters are not printable, like the bell or the esc key. To send it, you need to send it as ASCII but translate it from another encoding system on your computer, for example with Python, and send it to the print in hex.

The user manual lists all the possible special commands that can be used.

To switch to italic for instance on the NEC P60, you need to send esc and 4.

To get the esc key in hex in Python: chr(27) which returns '/x1b', etc.

There are also special commands to control the individual pins (!).

Each printer comes with a different set of special commands, different character sets and different fonts.

Howto

Printing on OSX

Using CUPS:

  1. Connect the printer with the USB cable
  2. Install the printer with CUPS, go to http://localhost:631 in your browser and select Administration → Add printer
  3. Select "Unknown" in the Local Printers section
  4. You can add a "name" and "location", mostly for yourself, so you can find the printer back later.. "connection" should say something like: usb://USB2.0-Print/
  5. For "make" (which is the manufacturer) you select "Generic" and for "model" you select "Generic Text-Only Printer", click "Add Printer"
  6. Your printer is installed!
  7. Now go to "Printers" and select your printer
  8. Now make this printer your default printer: click on "Administration" and select "Set as server default"
  9. You can now send files to the printer with: $ lpr myfile.txt or $ echo "hello" | lp

Backup option, without CUPS:

  1. Connect the printer with the USB cable.
  2. Go to System Settings → Printers → Add printer
  3. Select the USB one (the printer will start to print stuff, don't worry, you can ignore this)
  4. Choose "General PostScript printer" (even though this is not true!)
  5. Make the printer your default printer
  6. You can now send files to the printer with: $ lpr -o raw myfile.txt or $ echo "hello" | lp -o raw

Printing on Windows

Once installed, you should be able to send files to the printer with:

> lpr myfile.txt

But! This only prints files, not output of commands like echo.. But maybe there is a way.. this might work, it looks like it's worth a try:

Claudio's notes

First things first, I used the "CITIZEN Swift 90e" printer. On Windows I had multiple unexpected errors but after all Joseph helped and we did not end up using lpr but we used the Out-Printer command.

and the final commands were:

cat yourfile.txt | Out-Printer

or to write directly a string avoiding using a file:

"The text you want to print" | Out-Printer

Printing on Linux

Search for the printer by running this command with the USB cable unplugged and plugged:

$ ls /dev/usb/

Mine appears at: /dev/usb/lp2

Then send stuff to the printer by using > /dev/usb/lp2, so for instance:

$ echo "hello" > /dev/usb/lp2
$ cat hello.txt > /dev/usb/lp2

Or, if you install the printer with CUPS and make it the default printer on the system (see above at OSX section), you can use:

$ cat hello.txt | lp
$ lpr hello.txt

ASCII art

jp2a

lightweight tool to convert images into ascii, written by Christian Stigen Larsen

https://web.archive.org/web/20200517095853/https://csl.name/jp2a/

$ jp2a

Examples

Testing the PINWRITER P60 (during SI26)

linefeed = chr(10)
tab = chr(11)
italic = chr(27) + chr(4) # does not work
linespacing_big = chr(27) + chr(48)
linespacing_small = chr(27) + chr(50)
superscript = chr(27) + chr(83) + chr(0)
subscript = chr(27) + chr(83) + chr(1)
condensed = chr(27) + chr(15)
spacing_wide = chr(27) + chr(32) + chr(127) # 0 - 127
loop_start = chr(27) + chr(86) + chr(255) # 0 - 255
loop_stop = chr(27) + chr(86) + chr(0)

# printer = open("NEC_PINWRITER_P60", "w")
printer = open("/dev/usb/lp2", "w")
# printer.write("hello\n")
printer.write(loop_start + "hello " + loop_stop)
# printer.write("hello\n")
printer.close()

Pruning Station with Irmak and Aglaia (SI19)

The magic of scanner, OCR and dotmatrix printer

Pruning Station in progress

See: How_do_We_Library_That???#Pruning_Station_with_Irmak-_The_magic_of_scanner,_OCR_and_dotmatrix_printer

Python script to scan a page from a book, apply OCR (optical character recognition) and print it on the dot matrix printer.

import os
print("starting the pruning process")
scanning = "sudo scanimage --resolution 300 --mode color -o image.png"
os.system(scanning)
os.system("tesseract  image.png text.txt -l eng")
fantasyname = open("text.txt.txt" , "r")
fantasyname = fantasyname.readlines() 
for line in fantasyname: 
    line = line.split(" ")
    for l in line:
        if l!="" or l != ['\n', '\r\n']:            
            print(l)
            os.system("echo '"+l+"' > /dev/usb/lp0")

Related links