No ARM Printer Driver? Just Write Your Own

When you think of the small machines that print the sticky labels on packages, you might not expect to find a complex printer with its own programming language (ZPL). However, [Dan Pastusek] was looking around online and found a small label printer on everyone’s favorite online warehouse for a great price that suggested it supported ZPL. Unfortunately, [Dan] had big dreams for creating a Raspberry Pi-based print station and found the drivers packaged for this particular printer were not ARM compatible. Not quite content to leave it there, he began to chip away at the layers until he had a working driver.

ZPL, at its core, is just a language describing ASCII commands transmitted over a serial connection. So while the printer showed up as an endpoint, it wasn’t working as the filters (the part of the driver that knows how to convert from a PNG to ZPL) was x86 only. On Linux, printer drivers also have a PPD file that describes what a printer can handle in paper size and other settings. The PPD file for the little printer gave the first clue. In the ShortNickName field, it identifies itself as HPRT N41, which is a popular HP printer. So this little printer must be a clone of a printer in that family. Notably, they don’t support ZPL. Instead, the HPRT series support TSPL, another printer language developed by TSC.

This presented a problem as the shipping service that provided the labels that [Dan] was using offered labels in three formats: PNG, PDF, and ZPL. Currently, it does seem like there’s a TSPL to ZPL converter out there for use, so rather than write his own, he took a shortcut and wrote a rasterizer instead. Initially, he tried to use some sample code that he found, and while he got something to come out of the printer, it was blank. So the next test was to save the raw TSPL output from a filer and cat directly to the serial port. This worked amazingly. Next, he wrote a converter to take a PNG and convert them into the bitmap format the TSPL has. The converter is in Javascript as it runs as part of the webserver that manages the print station. Could it be faster in a different language? Sure. But a different language wouldn’t make the printer any faster.

With the addition of a wireless barcode scanner, it’s satisfying to see the print station up and running. Here at Hackaday, we’re no stranger to seeing folks take apart printers to peel back the software and physical layers that make them up.

16 thoughts on “No ARM Printer Driver? Just Write Your Own

    1. I use to write a web page that directly sends commands to label printer, not so hard to use ZPL (Zebra) or SBPL (SATO) just really sending commands: move position, rotate, put same string, barcode, maybe the image part is hardest as you have to extend/truncate image to match size that can dived with 8.

  1. Interestingly, I recently dug into CUPS rasterizing and it should be fairly simple to modify the CUPS “rastertolabel” filter to support TSPL.

    As for his dream of a print server, it could probably be pulled off using a ESP32.

  2. This is really funny, today I start working on module to print customs declaration directly to a ZPL printer, and found this article :)
    I am currently working on making a shipping appliance in python, with modules to deal with ebay, prestashop and other market places. Currently, in my business, it helps me a lot: I only need 1 minute to print the shipping label, the receipt, take a picture of the packet, and send an email to the customer.

      1. Yes, I managed to make some labels already using ZPL. The problem is to find a way to generate a preview prior to print the label (the appliance I’ve built has a GUI with big buttons for my big fingers :).
        Every piece of code I have found to do so is based on a call to a web site (http://labelary.com). If you know how I could render a ZPL into something else (may it be an image, a PDF, or anything viewable), I’ll be interested :)

        1. Either render as emulating printer, or try to save printer memory and cancel print. (Second option cannot produce preview without working printer)
          ZPL has command like this:
          ^IS – Image Save

          1. and

            ^HY – Upload Graphics
            The ^HY command is an extension of the ^HG command. ^HY is used to upload graphic objects from
            the printer in any supported format.

  3. ZPL is a well documentes language for Zebra Technologies printers. If you simply send the code to the printer (on serial/parallel/or on the network port 6101 , it will interpret and print. The images are binary data… but it know many barcode styles also.
    Anyway, nice work!

  4. The most common control language for printers is Epson Standard Code for Printers or ESC/P, or more precisely for receipt printers it is ESC/POS.[1][2] POS stands for Point-Of-Sale. Coincidentally the commands begin with the ASCII escape character (ESC) 0x1B hex.[3]

    1. ESC/P – Variants

    https://en.wikipedia.org/wiki/ESC%2FP#Variants

    2. FAQ about ESC/POS – Epson Seiko 2002-12 [pdf]

    https://web.archive.org/web/20200110095204/http://content.epson.de/fileadmin/content/files/RSD/downloads/escpos.pdf

    3. Escape Character, ASCII

    https://en.wikipedia.org/wiki/Escape_character#ASCII_escape_character

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.