Thermal receipt printer

The mini thermal printer (CSN-A2): 58 mm paper, a 384-dot head and a TTL serial port for text and commands. Aliases: receipt printer, CSN-A2.

Text goes into a line buffer as it arrives and is printed when a line feed comes, or when the line is full; commands in between change how the next text looks.

Pins

Pin What it does
VH The print head's supply, 5 V to 9 V. Not from a board's 5 V pin.
GND Ground, shared with the board.
RX Into the printer: the board's transmit pin.
TX Out of the printer: answers status requests. Optional.
DTR Flow control. Not used here.

Properties

baud is the serial speed, 19200 by default. paper starts it with paper loaded.

While it runs

The paper shows the last lines printed, styled as they were. The P button takes the paper out and puts it back.

What the model gets right

Lines. Text prints on a line feed; a carriage return is ignored; a line is 32 characters, 16 in double width, and a longer one wraps.

Styles. Bold, double height and double width (the print mode), the size command, inverse, underline, and left, center or right justification.

Feeding, barcodes and bitmaps. Feeding lines or dots, a barcode printed with its digits, and a bitmap's data taken in full (it shows as a placeholder with its size).

Status. The status request answers on TX, with bit 2 set when the paper is out, which is how the library's hasPaper() knows.

What it does not model

The time a line takes to print, how dark the heat settings make the print, the character sets, the bitmap's picture itself, and DTR flow control.

Libraries

Adafruit Thermal Printer Library (Adafruit_Thermal.h): SoftwareSerial mySerial(5, 6); Adafruit_Thermal printer(&mySerial);, then mySerial.begin(19200); printer.begin(); printer.println("Hello");.

Common mistakes

Powering it from the board. The head pulls more current than a board's 5 V pin gives; use its own 5 V to 9 V supply and join the grounds.

Swapping RX and TX: the printer's RX takes the board's transmit pin.

See it in action

Fortune printer prints a fortune with a lucky number at the press of a button. Open it at /templates.