Tuesday, May 5, 2015

Thermal printer perl library

Adafruit thermal printer perl library


Last month I've created a web GUI for my raspberry Pi thermal printer. After spending some time with testing, I was still unable to do several basic operations like print text with diacritics or create my own characters etc. So I decided to create my own library. I found out that there are plenty of them in python or C, but only few in Perl (with missing methods that I expected).

What I did

I've created a Perl library for Adafruit thermal printer. I read the original printer documentation and wrote a method for almost every command mentioned. The library consist of all default methods for altering font, barcode and image methods. I also did a few more custom methods:
  • printing images with gradient effect
  • aligning image (if image is more narrower than printing paper)
  • registering custom font from bitmap image


During the testing I gathered some facts that might be interesting:
  • The printer buffer is limited (exact size unknown), but if you sent longer text than buffer is, you will overwrite the buffer. The printed result was that the printer skipped some text. So you have to give the printer some time for printing.
  • If you print longer than 30 seconds without break, the printed text/image gets blurred. I think the hardware is not designed for such use. Anyway printed paper has only 40m.
  • The custom printing method with gradient effect is a little slow. This is because the printing head has to set the right heat value otherwise you won't get the desired effect.
  • This printer is unable to print gray scale images. The problem is that the printer automatically moves to a new line after printing the first one. I failed to find a workaround, but I'm sure it is possible to overwrite the right place in firmware but I didn't find it on the internet.

you can find the library here: