{"id":10918,"date":"2014-08-02T11:58:00","date_gmt":"2014-08-02T15:58:00","guid":{"rendered":"http:\/\/scruss.com\/blog\/?p=10918"},"modified":"2024-12-14T14:09:53","modified_gmt":"2024-12-14T19:09:53","slug":"notes-on-mini-printers-and-linux","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2014\/08\/02\/notes-on-mini-printers-and-linux\/","title":{"rendered":"Notes on mini-printers and Linux"},"content":{"rendered":"<p><a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/08\/miniprinter.pdf\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10919\" src=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/08\/miniprinter.jpg\" alt=\"miniprinter gallery\" width=\"334\" height=\"471\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/08\/miniprinter.jpg 334w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/08\/miniprinter-113x160.jpg 113w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/08\/miniprinter-226x320.jpg 226w\" sizes=\"auto, (max-width: 334px) 100vw, 334px\" \/><\/a>Over the last few weeks, I&#8217;ve been playing with a few small thermal printers. Meant as POS or information booth printers, they make a diverting project for the lo-fi printing enthusiast. While they all have common features \u2014 58 mm\/2\u00bc&#8221; paper width, 8 pixel\/mm resolution, 48 mm print width, serial connection \u2014 they all have their quirks. You may have seen these sold as the Adafruit <a href=\"https:\/\/www.adafruit.com\/products\/597\">Mini Thermal Receipt Printer<\/a> or Sparkfun&#8217;s <a href=\"https:\/\/www.sparkfun.com\/products\/10438\">Thermal Printer<\/a>, but there are many others. I&#8217;m going to write more on interfacing these directly to Raspberry Pi, Arduino, and (if I can navigate the documentation) a CUPS driver.<\/p>\n<p><strong>Update, July 2015<\/strong>: Here&#8217;s a CUPS driver: <a href=\"https:\/\/github.com\/klirichek\/zj-58\">klirichek\/zj-58<\/a>, and my writeup on installing it on a Raspberry Pi \u2014 <a href=\"http:\/\/scruss.com\/blog\/2015\/07\/12\/thermal-printer-driver-for-cups-linux-and-raspberry-pi-zj-58\/\">Thermal Printer driver for CUPS, Linux, and Raspberry Pi: zj-58<\/a><\/p>\n<p>For now, I&#8217;m just leaving you a list of things I&#8217;ve found helpful for the DP-EH600 and 701 printers. Note that the similar-looking BTHT-v6 printer uses a completely different command set.<\/p>\n<ul>\n<li>Replacement paper is sold as 2\u00bc&#8221; \u2014 30&#8242;. Staples have a box of 30 rolls for under $25 (item 279096, not on their website). Longer rolls don&#8217;t fit.<\/li>\n<li>You&#8217;ll need a USB\u2192TTL Serial adapter, preferably one with DTR control. I use one from <a href=\"http:\/\/www.dx.com\/p\/jy-mcu-usb-serial-port-adapter-download-line-arduino-104322\">JY-MCU<\/a>. In a pinch, you can use a simpler\u00a0 <a href=\"https:\/\/www.adafruit.com\/products\/954\">Debug \/ Console Cable for Raspberry Pi<\/a>, but you risk serial overruns and dodgy results. Remember that <em>RX<\/em> on the adapter goes to <em>TX<\/em> on the printer, and vice versa.<\/li>\n<li>A good solid power supply is needed; these printers draw ~8 W when printing. Some printers only support 5 V (for which a 3 amp adapter would be ideal), others 5-9 V. The higher voltage makes text printing faster. You can&#8217;t drive these directly from your Raspberry Pi\/Arduino power supply.<\/li>\n<li>Linux serial ports are set to some defaults which may have been historically useful, but now corrupt 8-bit data. A trick I picked up <a href=\"http:\/\/nst.sourceforge.net\/nst\/docs\/user\/ch10s02.html\">here<\/a> is to first issue the command<br \/>\n<tt>stty -F \/dev\/ttyUSB1 0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0<\/tt><br \/>\nwhich clears all settings, then set the device up as you need it:<br \/>\n<tt>stty -F \/dev\/ttyUSB1 speed 9600 raw cs8<\/tt><br \/>\n(Most of these printers default to 9600 baud. Your device may be called something different to ttyUSB1.)<\/li>\n<li>I&#8217;ve written a couple of Python driver stubs which take an image and produce the relevant binary output:\n<ul>\n<li><a href=\"https:\/\/gist.github.com\/scruss\/36c31a9b653779b2b7d1\">scruss \/ esc-pos-image.py<\/a> &#8211; prints an image as a single command. May not work on the SparkFun printer. Does not work on the BTHT-v6.<\/li>\n<li><a href=\"https:\/\/gist.github.com\/scruss\/95c61c9a1501ada2a6c5\">scruss \/ esc-pos-image-star.py<\/a> &#8211; prints the image in 24 pixel deep bands. Can sometimes cause visible gaps in the printout, but will work on almost all printers, except the BTHT-v6.<\/li>\n<\/ul>\n<\/li>\n<li>These Python libraries also work, as long as you address the printer properly (right device, right speed):\n<ul>\n<li><a href=\"https:\/\/code.google.com\/p\/python-escpos\/\">python-escpos<\/a> &#8211; image support limited to 255 pixels high, for some reason.<\/li>\n<li><a href=\"https:\/\/github.com\/adafruit\/Python-Thermal-Printer\">adafruit\/Python-Thermal-Printer<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><em><strong>Notes\/Credits<\/strong><\/em><\/p>\n<ol>\n<li><em>Reed Zhao (of <a href=\"http:\/\/store.tangramsoft.com\/\">Tangram Software<\/a>) lent me a couple of different printers for testing after I bought a different one from him. He&#8217;s put <a href=\"http:\/\/reed-printer.blogspot.ca\/\">a lot of work<\/a> into sourcing these printers direct from the manufacturers. Thanks, Reed!<br \/>\n<\/em><strong>NB<\/strong>: Reed doesn&#8217;t sell printers any more. Try eBay.<em><br \/>\n<\/em><\/li>\n<li><em>Image credits for print samples:<\/em>\n<ul>\n<li><em>Stephen Notley, <a href=\"http:\/\/www.angryflower.com\/\">Bob the Angry Flower<\/a>: excerpts from <a href=\"http:\/\/www.angryflower.com\/488.html\">I Have Absolutely No Idea What I&#8217;m Doing!<\/a> and <a href=\"http:\/\/www.angryflower.com\/56.html\">Achilles&#8217; Heel<\/a><\/em><\/li>\n<li><em>Kate Beaton, <a href=\"http:\/\/www.harkavagrant.com\/\">Hark, a vagrant<\/a>: <a href=\"https:\/\/twitter.com\/beatonna\/status\/493183699543154688\/photo\/1\">even more about arses<\/a><\/em><\/li>\n<li><em>True Image of J. R. \u201cBob\u201d\u009d Dobbs, a trademark of <a href=\"http:\/\/www.subgenius.com\/\">The SubGenius\u2122 Foundation, Inc<\/a><\/em><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><em><strong>Manuals\/Docs<\/strong><\/em><\/p>\n<p>Posted more for historical reference:<\/p>\n<ul>\n<li><a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/08\/BTHT-V6-V3.2.pdf\">BTHT-V6 manual<\/a> (Chinese) \u2014 probably just enough info to follow the wiring and some of the basic control codes. Looks like the one I had was 5V only, so needs a 5V 3A power supply.<\/li>\n<li><a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/08\/701-pin-layout.pdf\">&#8220;701 Printer&#8221; data\/power pinout<\/a><\/li>\n<li><a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/08\/701print-driver-board.pdf\">&#8220;701 Printer&#8221; driver\/control codes<\/a> \u2014 most likely applies to the DP-EH600 too.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Over the last few weeks, I&#8217;ve been playing with a few small thermal printers. Meant as POS or information booth printers, they make a diverting project for the lo-fi printing enthusiast. While they all have common features \u2014 58 mm\/2\u00bc&#8221; paper width, 8 pixel\/mm resolution, 48 mm print width, serial connection \u2014 they all have [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[270,922,2540,2542,2826,2825,2824,2823,229],"class_list":["post-10918","post","type-post","status-publish","format-standard","hentry","category-computers-suck","tag-linux","tag-printer","tag-python","tag-serial","tag-shanzhai","tag-stty","tag-thermal","tag-ttl","tag-usb"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-2Q6","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/10918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=10918"}],"version-history":[{"count":9,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/10918\/revisions"}],"predecessor-version":[{"id":17685,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/10918\/revisions\/17685"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=10918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=10918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=10918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}