thermal printers/Beyond text/09. Pictures take time
Beyond text · 09 of 11

Pictures take time

A barcode is a string the printer draws. A picture is every dot travelling down the serial wire as a bit, and at 9600 baud a logo is a measurable wait rather than an instant.

Every dot is a bit

The picture arrives one bit at a time
384 × 120 dots · 9600 baud
Printer
Image height (dots)120
Image width (dots)384
Bytes to send
5,760
Time on the wire
6.0 s
Time on paper
300 ms
The printer is waiting for you, not the other way round. At 9600 baud these 5,760 bytes take 6.0 s to cross the wire, and the head could have printed them in 300 ms. Nothing in the sketch is stuck. Send a narrower or shorter image, or use the faster printer.

There is no compression and no shortcut. A raster image is sent as one bit per dot, packed eight to a byte, row after row — so a full-width image is 48 bytes per row, and the height multiplies it.

On the receipt printer at 9600 baud that arithmetic matters. Serial framing is ten bits per byte, not eight, because each byte carries a start and a stop bit as well. A 384 × 200 logo is 9,600 bytes, which is 96,000 bits, which is ten seconds of wire.

The paper, meanwhile, could have printed those 200 rows in half a second. The wire is the bottleneck, by a factor of twenty.

Which is why the label printer's baud rate matters

115200 is twelve times faster than 9600, and it turns the same image from a ten-second wait into under a second. That is the practical difference the two stickers on the backs of the machines are describing, and it is invisible until you print something bigger than a line of text.

Keep images small, or do not send them

Three things make an image cheap:

  • Narrow. Width is a direct multiplier. A 200-dot-wide logo costs half of a full-width one.
  • Short. So is height.
  • Line art. The printer has no greys, so a photograph has to be dithered to black and white before it means anything, and dithered photographs use far more ink and far more paper than the logo somebody actually wanted.

If the thing you want on the receipt is text, send it as text. The printer's own font costs one byte per character instead of a column of bits per character, and it is sharper.

Send rows with a pause between them

Both printers can be given raster data faster than they can move it into the head, and the symptom is a row shifted sideways or an image that leans. The library shipped with the label kit puts a short delay between rows — about 10 ms on an Arduino using SoftwareSerial, 3 ms on a hardware UART — and hand-written raster code needs the same.

When it does not work

The sketch appears to hang while printing an image

It is almost certainly not hung. A full-width 200-row image is 9,600 bytes, and at 9600 baud with start and stop bits that is ten seconds of wire time before the paper has finished moving. Work out the number before you assume a crash.

The image comes out skewed or with rows shifted sideways

Rows are arriving faster than the printer can absorb them. The kit's library inserts a short delay between rows for exactly this reason — 10 ms on an Arduino with SoftwareSerial, 3 ms on a hardware UART. If you are sending raster data yourself, add the same.

My photograph prints as a black rectangle

The printer has two states per dot, on and off, and no greys. A photograph converted by thresholding turns mostly black. Convert with dithering, or use line art — logos, icons and text-as-image are what this mechanism is for.

The image is half the width I expected

Image width goes in as bytes per row in some commands and as dots in others. Eight dots to the byte: a full-width image is 384 dots or 48 bytes, and passing 384 where bytes were wanted asks for an image eight times too wide.

Where this goes next

The printer will tell you when it has run out, in three bytes — and the first byte is not one of them.

Asking the printer about paper

Edit this page — content/books/thermal-printer/pictures-take-time.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

This page covers several products. Choose yours to see the right discussions.

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum