RkBlog

Thermal printers for makers and programmers

Thermal printers are used to print bills, tickets, labels, and alike in shops and various venues. They are small, cheap, and get the work done. But how do they work? What can they print and how to control them?

Thermal printer in action

Thermal printing

Thermal printers are quite simple. There is a heating element that can precisely heat small points on its elongated surface. The paper that is used is covered with chemical compounds that change color when heated (usually to black). So by precise heating and moving the paper over the element you can get letters or even simple graphics printed.

PeriPage thermal element
PeriPage thermal element

Thermal paper is cheap to make, thermal printers are also simple and cheap to make, and there won't be problems with paper stuck deep inside a printer. Printing is fast and very quiet, there is no ink to manage. There is however a disadvantage - the print is fragile to elements like light, heat, and some other chemicals. Thermal prints aren't long-lasting, they can fade and vanish or the whole surface will change color. Also, the feed mechanism is simple so there may be distortions if the paper can’t move freely. Also, there can be a lack of uniformity of quality when printing images.

Thermal print quality
Thermal prints can be of decent quality but there will be artifacts
Mom, can we have some Reddit?
Mom, can we have some Reddit?

Thermal printers

There are a lot of printers on the market. They can use USB, Bluetooth, or WiFi interfaces while using a serial connection behind them. Thermal printers often offer direct access to that serial connection too (TTL, RS232, RS485) which can be used for integration with microcontrollers or other industrial systems. They can print on standard thermal paper of one of the standardized widths. There are also specialized variants to support standardized tapes of stickers to print labels - from simple small stickers to full shipping labels.

The whole standard is called ESC/POS and if you have a thermal printer compatible with it (most of them) then any software or library supporting it can use those printers. To some extent, a thermal printer can be added as a printer under Windows or Linux.

Peripage

Peripage are printers made by Paperang company. They are intended for consumer use and not as ESC/POS printers. They come with nice mobile apps as well as a large selection of additional types of thermal paper rolls - different colors, stickers, and alike. The main marketing pitch seems to be analog blogging - making personal journals and like.

When testing the Peripage A6 printer I had no problems using it via my Android phone. It can be a bit tricky to manage text style via the mobile interface but it can be done. I could not make it work under Linux via ESC/POS library or via direct printing to a local printer device.

PeriPage Mini A6
PeriPage Mini A6
PeriPage Mini A6
PeriPage Mini A6
PeriPage app main screen
PeriPage app main screen
PeriPage app allows printing images with varying intensity
PeriPage app allows printing images with varying intensity
Different intensity prints
Different intensity prints

Welquic ESC/POS printer

This is your typical ESC/POS printer. It has USB/Bluetooth and serial interfaces and a rechargeable battery. I was ale to configure it on Windows as well as on Linux - by direct lp usage as well as through the ESC/POS printing library. The prints look quite good.

Welquic generic ESC/POS thermal printer
Welquic generic ESC/POS thermal printer

QR701 serial printer

This is a generic serial thermal printer, it looks nearly identical to the Adafruit one but there can be some electronics and firmware differences. The quality of prints from this printer is kind of worse than the other two. I was able to print via ESC/POS library as well as via Adafruit library although the printer would often not respond to serial commands sent - I had to execute the script few times before it reacted and printer what was sent.

I powered it with a lab power supply. At 8.9V it pulled up to 0.7 - 0.8A while printing which gives around 7W of power draw.

Serial connector
Serial thermal printer
Serial thermal printer QR701
Serial printer connected to a PC via UART
Serial printer connected to a PC via UART

Usages

Aside from intended POS usages printing bills and whatnot thermal printers could be used for some personal use as well as in makers projects related to electronics. Peripage printers are directed at end-consumers for analog blogging, printing ToDo lists, labels, and alike. Serial printers can be used in electronics projects with microcontrollers. The USB/Bluetooth ones would be for use with Raspberry Pi and regular PC and laptops.

Software support

PeriPage is intended to be used with mobile apps available for Android and iOS. ESC/POS printers with Bluetooth or WiFi interface can also be used with mobile devices. Just search the shop for thermal printer and you will get a lot of apps available. On Windows basic support can be achieved by adding such local printer manually (text printing, more if it has a dedicated app/driver). On Linux, you can cat text files to the device, in some cases, CUPS printing service can support them (if a driver is available and it actually works). Usually using an ESC/POS library is better than trying to use CUPS.

Thermal printer in CUPS
CUPS can configure a thermal printer but it may have problems printing with it

The most reliable way of controlling ESC/POS printers is by using a library that implements that standard. This can cover USB, serial, and network-based printers

Bluetooth printer pairing on a phone
Bluetooth printer pairing on a phone
Printing in Bluetooth Printer app
Printing in Bluetooth Printer app
Printing in Express Thermal Print app
Printing in Express Thermal Print app
Printing in RawBT app
Printing in RawBT app

Windows

Connect the printer via USB and if not possible use the Bluetooth or WiFi interfaces. Go to printer settings and try to add one. Windows likely won't find anything and you will have to add it manually. Select at which interface the printer is located - when it's a USB then such an option will appear on the list. Pick the generic printer type and it should be done. In a lucky case vendor/model will be on the list to pick or there can be a custom driver provided by the manufacturer.

Now you should be able to print simple text from a Notepad.

Thermal printer Windows configuration
Thermal printer Windows configuration
You should be able to configure a thermal printer under Windows by selecting it port and type manually
Thermal printer as a Windows printer allows for simple prints
Thermal printer as a Windows printer allows for simple prints

Linux

For a USB printer check if it appears as printer in /dev/usb/ (lp* device)

ls /dev/usb/

Try cat-ing a small text file to it (by default it will likely require root):

cat file.txt > /dev/usb/lp4

This should make the printer print the contents of the file. Some printers may not support it.

Permission to devices on Linux

To not be forced to use the root account to run ESC/POS code the printer has to have an udev rule and the user has to be added to a selected group like for example dialout.

Run lsusb before connecting the device after which connect and turn the device on. Run lsusb again and see which entry was added - that's the printer (or check dmesg logs). We need the vendor and device IDs:

Bus 003 Device 010: ID 0416:5011 Winbond Electronics Corp. Virtual Com Port

In this example vendor ID is 0416 and device ID is 5011.

Now we have to add an udev rule for it so that non-root can use it. Create/edit a file named like /etc/udev/rules.d/99-escpos.rules:

sudo nano /etc/udev/rules.d/99-escpos.rules
SUBSYSTEM=="usb", ATTRS{idVendor}=="0416", ATTRS{idProduct}=="5011", MODE="0664", GROUP="dialout"

Change the idVendor and idProduct to those of your device. Also, add the selected Linux user (user account you use) to the dialout group.

Restart udev or reboot the system to get all changes active.

dmesg and lsusb will list USB device IDs needed to use it under Linux
dmesg and lsusb will list USB device IDs needed to use it under Linux

Python

python-escpos

python-escpos is one of the libraries that implement ESC/POS standards and allows printing text, images, barcodes, and QR codes on compatible thermal printers.

pip install python-escpos

To use a USB thermal printer with this library we will have to get some data about the device. The initialization looks like so:

printer.Usb(0xVENDOR_ID, 0xUSER_ID, in_ep=IN_ENDPOINT, out_ep=OUT_ENDPOINT)

We already have both IDs, the IN_ENDPOINT is usually 0x81 while OUT_ENDPOINT can be found with this command:

lsusb -vvv -d VENDOR_ID:DEVICE_ID | grep bEndpointAddress | grep OUT

You can skip the greps if you want to see the full info on the device. With all the data we can use the printer:

from escpos import printer


p = printer.Usb(0x0416, 0x5011, in_ep=0x81, out_ep=0x03)
p.text("Hello World!\n")
p.text("Stay at home!\n")
p.image("your_image_file.jpg")
p.cut()

The image should be small, starting with like 380 pixels of width or alike. Big files will be cut (not printed fully). And you have to have that file in a given path. You can find more about what this library can print in the documentation.

Serial (UART) printers can be initialized by specifying the device name, for example:

p = printer.Serial("/dev/ttyUSB0", timeout=6000)

For PeriPage there are dedicated Python packages, check Github for one of them.

Adafruit CircuitPython

Adafruit has a serial thermal printer in their product catalog and they do support Arduino and CircuiPython. Serial printers can be used with a microcontroller as well as with PCs.

There are also generic thermal printers that look exactly like the Adafruit printer but they may differ slightly with the electronics and firmware - they can work with Adafruit libraries but it's not guaranteed. The one that I have isn't the best quality but seems to work with the Adafruit library (although it does print some trash characters from time to time.

You will find all the code and wiring in the Adafruit tutorial. In my case, I had to connect UART and the power supply ground for it to work.

Other programming languages

There are libraries for ESC/POS printers in other languages too. I've seen a PHP one as well as some raw serial command tutorials. The serial Adafruit printer is supported by Arduino and likely by other microcontroller platforms that are compatible with Arduino stack (like ESP chips). You should be able to find such libraries on Github or via Google.

Summary

I hope this article was fun to read. Thermal printers can be used in some fun maker projects as well as in some practical applications like label printing. You should be able to find thermal printers and thermal paper locally, via general stores like Amazon, and eBay, electronics stores like Adafruit, and also China - Aliexpress and alike. Just check what length of thermal paper the given printer uses, what interfaces it has (USB, Bluetooth handy), and if it's something custom or just ESC/POS standard printer.

Comment article