{"id":345,"date":"2016-04-17T19:05:13","date_gmt":"2016-04-17T17:05:13","guid":{"rendered":"http:\/\/andreberger.eu\/?p=345"},"modified":"2016-05-04T07:17:57","modified_gmt":"2016-05-04T05:17:57","slug":"the-art-of-printing","status":"publish","type":"post","link":"https:\/\/andreberger.eu\/?p=345","title":{"rendered":"The Art of Printing"},"content":{"rendered":"<p>Wouldn&#8217;t it be great to have a printer that was connected to the mains just when needed, and disconnected\u00a0when not? With a wireless connection? And\u00a0AirPrint? Well, here&#8217;s how to turn virtually any printer into such a device, with the help of a Raspberry Pi.\u00a0<!--more--><\/p>\n<p><strong>DISCLAIMER: Use at your own risk, no warranty whatsoever. Be extra careful,\u00a0<em>electricity could kill you.<\/em><\/strong><\/p>\n<p>Revision: 2016-04-21<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Audience<\/strong><\/p>\n<p>The following instructions are targeted at experienced users. You may\u00a0always\u00a0feed a search engine with terms like &#8220;Raspberry Pi\u00a0<em>topic<\/em>&#8221; (Raspberry Pi\u00a0<em>WLAN client<\/em>, for example) in order\u00a0to\u00a0complete each step.<\/p>\n<p><strong>Objective<\/strong><\/p>\n<p>Learn how to turn the single-board computer Raspberry Pi\u00a0into a always-on low-power networked print server. The special feature is, <strong>your printer will be automatically <em>connected to and disconnected from the mains<\/em>\u00a0as needed.<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-405\" src=\"http:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/idling-600x450.jpg\" alt=\"idling\" width=\"600\" height=\"450\" srcset=\"https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/idling-600x450.jpg 600w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/idling-150x113.jpg 150w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/idling.jpg 1200w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/idling-100x75.jpg 100w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/idling-467x350.jpg 467w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Prerequisites<\/strong><\/p>\n<p>You need:<\/p>\n<p><strong>1. Some printer&#8230;<\/strong><\/p>\n<ul>\n<li>supported by CUPS (the Common Unix Printing System)<\/li>\n<li>preferably with built-in PCL or PostScript capabilities<\/li>\n<li>preferably a laser printer, their toner wouldn&#8217;t dry out<\/li>\n<\/ul>\n<p><strong>2. LAN or WLAN<\/strong><\/p>\n<ul>\n<li>so your devices can connect to each other<\/li>\n<li>and\u00a0hand over print jobs<\/li>\n<\/ul>\n<p><strong>3. Raspberry Pi<\/strong>\u00a0with&#8230;<\/p>\n<ul>\n<li>WLAN (Wireless LAN, Wi-Fi) adapter or LAN cable, to connect to your (W)LAN<\/li>\n<li>a USB or a Ethernet cable, to connect the Raspberry Pi physically to your printer<\/li>\n<li>a <a href=\"http:\/\/projectraspi.blogspot.de\/2014\/05\/raspberry-pi-driving-relay-using-gpio.html\" target=\"_blank\">relay<\/a>, so you can switch deadly electricity on\/off without killing yourself or your devices<\/li>\n<li>a computer power chord to cut open and connect to the relay<\/li>\n<li>a small breadboard and a few Dupont female\/male cables (or soldered cables)<\/li>\n<li>a \u00a0sensor button and a resistor, for manual operation of the relay<\/li>\n<li>a LED and a resistor, so the Pi won&#8217;t fry it, to indicate the state of system<\/li>\n<li>a RTC (Real Time Clock), so the time is always accurate, as is good practice for all servers<\/li>\n<li>a Linux OS such as Raspbian jessie, as used here for all the instructions<\/li>\n<li>a few scripts to control the operations<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-402\" src=\"http:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/wlan_and_relaiscables-450x600.jpg\" alt=\"wlan_and_relaiscables\" width=\"450\" height=\"600\" srcset=\"https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/wlan_and_relaiscables-450x600.jpg 450w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/wlan_and_relaiscables-113x150.jpg 113w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/wlan_and_relaiscables.jpg 900w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/wlan_and_relaiscables-75x100.jpg 75w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/wlan_and_relaiscables-263x350.jpg 263w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Setup Instructions<\/strong><\/p>\n<p>These instructions cover a Raspi WLAN client system, serving\u00a0a printer named\u00a0<em>standard<\/em>\u00a0to your LAN.<\/p>\n<p><strong>General Setup<\/strong><\/p>\n<ol>\n<li>Boot your Raspi into Raspbian\u00a0jessie.<\/li>\n<li>Log on<\/li>\n<li>Become root permanently:<br \/>\n<em>sudo -s<\/em><\/li>\n<li>Connect your printer to Raspi\u00a0via USB or LAN cable, and turn it on.<\/li>\n<li>Connect the WLAN adapter, then connect to your router in the client role. The IP address of the Raspberry Pi will hence be referred to as\u00a0<em>$RASPI_IP<\/em>.<\/li>\n<\/ol>\n<p><strong>CUPS Setup: The Server and a Printer Named\u00a0<em>standard<\/em><\/strong><\/p>\n<ol>\n<li>Install CUPS (print server) and Avahi (MDNS\/ZeroConf\/Bonjour) with all the depencies (thanks, Debian!):<em><br \/>\napt-get install cups cups-bsd avahi-utils<\/em><\/li>\n<li>Note: You can download\u00a0<a href=\"http:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/2016\/04\/etc_cups_cupsd.conf_.tar.gz\">etc_cups_cupsd.conf.tar.gz<\/a>\u00a0(md5sum\u00a0671bb1dadff6183a24c227ab509ff8f3; install with\u00a0<em>tar -C \/ -xvzf <a href=\"http:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/2016\/04\/etc_cups_cupsd.conf_.tar.gz\">etc_cups_cupsd.conf.tar.gz<\/a><\/em>), which contains the changes described below.<br \/>\nEdit\u00a0the\u00a0<strong>upper part<\/strong>\u00a0of\u00a0<em>\/etc\/cups\/cupsd.conf<\/em>\u00a0to:<br \/>\n<em>LogLevel warn\u00a0<\/em><br \/>\n<em>MaxLogSize 0<\/em><br \/>\n<em>Port 631<\/em><br \/>\n<em>ServerAlias *<\/em><br \/>\n<em>Listen \/var\/run\/cups\/cups.sock<\/em><br \/>\n<em>Browsing On<\/em><br \/>\n<em>BrowseLocalProtocols CUPS dnssd<\/em><br \/>\n<em>BrowseOrder allow,deny<\/em><br \/>\n<em>BrowseAllow all<\/em><br \/>\n<em>BrowseRemoteProtocols CUPS dnssd<\/em><br \/>\n<em>BrowseAddress @LOCAL<\/em><br \/>\n<em>BrowseLocalProtocols CUPS dnssd<\/em><br \/>\n<em>DefaultAuthType Basic<\/em><br \/>\n<em>WebInterface Yes<\/em><br \/>\n<em>&lt;Location \/&gt;<\/em><br \/>\n<em>\u00a0 Order allow,deny<\/em><br \/>\n<em>\u00a0 Allow @LOCAL<\/em><br \/>\n<em>&lt;\/Location&gt;<\/em><br \/>\n<em>&lt;Location \/admin&gt;<\/em><br \/>\n<em>\u00a0 Order allow,deny<\/em><br \/>\n<em>\u00a0\u00a0<strong># comment out the line below once your printer is set up, for SECURITY reasons!<\/strong><\/em><br \/>\n<em>\u00a0 Allow @LOCAL<\/em><br \/>\n<em>&lt;\/Location&gt;<\/em><br \/>\n<em>&lt;Location \/admin\/conf&gt;<\/em><br \/>\n<strong>Leave the rest of the file unchanged!<\/strong><\/li>\n<li>Restart the CUPS server:<br \/>\n<em>killall -HUP cupsd<\/em><\/li>\n<li>Browse\u00a0<em><strong>https:\/\/<\/strong>$RASPI_IP<strong>:631<\/strong><\/em>\u00a0to set up and configure\u00a0a printer. Call\u00a0it\u00a0<em><strong>standard<\/strong><\/em>, this name will be used throughout here. Remember: PCL or PostScript printers make\u00a0the least painful setup.<\/li>\n<li>Edit\u00a0<em>\/etc\/cups\/printers.conf<\/em>\u00a0and change:\n<ul>\n<li><em>&lt;Printer standard&gt;<\/em>\u00a0to\u00a0<strong>&lt;<em>DefaultPrinter standard&gt;<\/em><\/strong><\/li>\n<li><em>Shared No\u00a0<\/em>to<em><strong>\u00a0Shared Yes<\/strong><\/em><\/li>\n<li><em>ErrorPolicy stop<\/em>\u00a0to<strong><em>\u00a0ErrorPolicy retry-job<\/em><\/strong><\/li>\n<\/ul>\n<\/li>\n<li>Disallow administrative access to the CUPS web-interface, as detailed in the comment to\u00a0<em>\/etc\/cups\/cupsd.conf<\/em>\u00a0above.<\/li>\n<li>Restart\u00a0the CUPS server:<br \/>\n<em>killall -HUP cupsd<\/em><\/li>\n<\/ol>\n<p>If you wonder about AirPrint now: it&#8217;s built-in.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-404\" src=\"http:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/printing_with_led-600x450.jpg\" alt=\"printing_with_led\" width=\"600\" height=\"450\" srcset=\"https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/printing_with_led-600x450.jpg 600w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/printing_with_led-150x113.jpg 150w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/printing_with_led.jpg 1200w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/printing_with_led-100x75.jpg 100w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/printing_with_led-467x350.jpg 467w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><strong>Control Software Setup<\/strong><\/p>\n<ol>\n<li>Add to\u00a0<em>\/etc\/rc.local<\/em>\u00a0<strong>above<\/strong>\u00a0the last line (i. e., above the\u00a0<em>exit 0<\/em>\u00a0statement):<br \/>\n<em>\/opt\/local\/bin\/pinsoff-printer.py &amp;<br \/>\n\/opt\/local\/bin\/printer.py &amp;<\/em><\/li>\n<li>Add to <em>\/etc\/crontab<\/em>:<br \/>\n<em>*\/1 * * * * root\u00a0 \/opt\/local\/bin\/relais2-printer.sh &gt;\/dev\/null 2&gt;&amp;1<\/em><\/li>\n<li>Download\u00a0<a href=\"http:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/theartofprinting.tar.gz\">theartofprinting.tar.gz<\/a>\u00a0(md5sum\u00a03f51434e12639e815000aceeffbe5b30), which contains the scripts detailed below.<\/li>\n<li>Install the scripts:<br \/>\n<em>tar -C \/ -xvzf\u00a0theartofprinting.tar.gz<\/em><\/li>\n<li>The scripts and what they do:\n<ul>\n<li><em style=\"font-size: 1em;\">\/opt\/local\/bin\/pinsoff-printer.py<br \/>\n<\/em>Run from\u00a0<em>\/etc\/rc.local<\/em>, it makes sure all used GPIO pins start in a defined state. A more elegant solution would use\u00a0<em>\/boot\/config.txt<\/em>\u00a0for the purpose<\/li>\n<li><em>\/opt\/local\/bin\/printer.py<\/em><br \/>\nRun from\u00a0<em>\/etc\/rc.local:<\/em><\/p>\n<ul>\n<li>GPIO control of the relay<\/li>\n<li>GPIO control of the sensor button, for manual operation<\/li>\n<li>GPIO control\u00a0of the\u00a0LED<\/li>\n<\/ul>\n<\/li>\n<li><em>\/opt\/local\/bin\/relais2-printer.sh<br \/>\n<\/em>Run\u00a0from\u00a0<em>\/etc\/crontab<\/em>\u00a0every minute:<\/p>\n<ul>\n<li>checks the print queue for print jobs<\/li>\n<li>provides\u00a0a user-configurable timer, controlling how long turning off is delayed after the print job was received by\u00a0the printer (default: 10 mins.). If a new print job is received during this period, the timer is reset. If the user wants to override this and turn the printer on or\u00a0off manually, it&#8217;s done.<\/li>\n<li>switches\u00a0the printer on or off<\/li>\n<\/ul>\n<\/li>\n<li><em>\/opt\/local\/bin\/relais2-off.py<\/em>\u00a0and\u00a0<em>\/opt\/local\/bin\/relais2-on.py<\/em>\n<ul>\n<li>Switch the relay (relay 2 here) off or on, respectively<\/li>\n<\/ul>\n<\/li>\n<li><em>\/opt\/local\/bin\/relais2-status.py<\/em>\n<ul>\n<li>Shows the state relay 2 is in<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-403\" src=\"http:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/wlan_led_and_touchsensor_detail-600x450.jpg\" alt=\"wlan_led_and_touchsensor_detail\" width=\"600\" height=\"450\" srcset=\"https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/wlan_led_and_touchsensor_detail-600x450.jpg 600w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/wlan_led_and_touchsensor_detail-150x113.jpg 150w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/wlan_led_and_touchsensor_detail.jpg 1200w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/wlan_led_and_touchsensor_detail-100x75.jpg 100w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/wlan_led_and_touchsensor_detail-467x350.jpg 467w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><strong>Hardware Setup<\/strong><\/p>\n<p>Turn the Raspi off, remove\u00a0<strong>all<\/strong>\u00a0the cables!<\/p>\n<p><strong>Wiring the Relay, the Touch Sensor, and the LED<\/strong><\/p>\n<p>The scripts here use relay 2, as this is the local setup. YMMV. The following\u00a0<a href=\"http:\/\/pinout.xyz\" target=\"_blank\"><em>GPIO.BCM<\/em>\u00a0configuration<\/a>\u00a0is used in the scripts:<\/p>\n<ul>\n<li>GPIO.BCM 19 # the touch sensor<\/li>\n<li>GPIO.BCM 20 #\u00a0<em>the<\/em>\u00a0relay<\/li>\n<li>GPIO.BCM 26 # the LED<\/li>\n<\/ul>\n<p><em>Do Not Forget<\/em><\/p>\n<ul>\n<li>The relay will likely need to be connected to 5 V Power.<\/li>\n<li>The appropriate resistors for all the pins used, as 5 V (not 3.3 V) are\u00a0used, so\u00a0Raspi may be damaged otherwise.<\/li>\n<\/ul>\n<p><strong>Wiring the RTC (optional)<\/strong><\/p>\n<ul>\n<li>3.3 V<\/li>\n<li>GPIO.BCM 2 (SDA)<\/li>\n<li>GPIO.BCM 3 (SCL)<\/li>\n<li>Ground<\/li>\n<\/ul>\n<p><em>Do Not Forget<\/em><\/p>\n<ul>\n<li><em>hwclock -w<\/em><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-401\" src=\"http:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/raspi-rtc-600x450.jpg\" alt=\"raspi-rtc\" width=\"600\" height=\"450\" srcset=\"https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/raspi-rtc-600x450.jpg 600w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/raspi-rtc-150x113.jpg 150w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/raspi-rtc.jpg 1200w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/raspi-rtc-100x75.jpg 100w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/raspi-rtc-467x350.jpg 467w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><strong>Connecting the Relay to the Mains<\/strong><\/p>\n<p><strong>Be extra careful,\u00a0<em>electricity could kill you.<\/em><\/strong><\/p>\n<ul>\n<li><strong>Remove the\u00a0computer power chord from the mains\u00a0for real.<\/strong><\/li>\n<li>Cut through the outer insulation of the computer power chord, about 10\u201315 cm (4\u20135 in.) long.<\/li>\n<li><strong>Make sure you haven&#8217;t damaged the inner cables.<\/strong><\/li>\n<li>Cut the inner blue cable in two, remove some of the insulation at\u00a0its\u00a0ends.<\/li>\n<li>Connect both\u00a0ends of the blue cable to the relay<\/li>\n<li>Plug the cord into the mains.<\/li>\n<\/ul>\n<p><em>Alternative\u00a0Power Strip\u00a0Setup<\/em><\/p>\n<p>Instead of a power cord, you can use a power strip and thus control several devices at once. For example, plugging a small Wi-Fi router into that power strip, configuring it as a bridge, and connecting it to a network (LAN) MFP, would make it a fine WLAN MFP. You may even scan over WLAN (tested with Samsung Mobile Print on iOS and Samsung CLX-6220FX).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-400\" src=\"http:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/printer-2-450x600.jpg\" alt=\"printer\" width=\"450\" height=\"600\" srcset=\"https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/printer-2-450x600.jpg 450w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/printer-2-113x150.jpg 113w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/printer-2.jpg 900w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/printer-2-75x100.jpg 75w, https:\/\/andreberger.eu\/automatiq\/wp-content\/uploads\/printer-2-263x350.jpg 263w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/p>\n<p><strong>Finally&#8230;<\/strong><\/p>\n<p><strong>&#8230; enjoy!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wouldn&#8217;t it be great to have a printer that was connected to the mains just<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/andreberger.eu\/?p=345\">Read the post<span class=\"screen-reader-text\">The Art of Printing<\/span><\/a><\/div>\n","protected":false},"author":2,"featured_media":339,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,6,10],"tags":[],"class_list":["post-345","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-configuration","category-lore","category-raspberry-pi","excerpt","zoom","full-without-featured","even","excerpt-0"],"publishpress_future_action":{"enabled":false,"date":"2026-06-08 20:25:44","action":"change-status","newStatus":"private","terms":[],"taxonomy":"category","extraData":[]},"publishpress_future_workflow_manual_trigger":{"enabledWorkflows":[]},"_links":{"self":[{"href":"https:\/\/andreberger.eu\/index.php?rest_route=\/wp\/v2\/posts\/345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/andreberger.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/andreberger.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/andreberger.eu\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/andreberger.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=345"}],"version-history":[{"count":87,"href":"https:\/\/andreberger.eu\/index.php?rest_route=\/wp\/v2\/posts\/345\/revisions"}],"predecessor-version":[{"id":448,"href":"https:\/\/andreberger.eu\/index.php?rest_route=\/wp\/v2\/posts\/345\/revisions\/448"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/andreberger.eu\/index.php?rest_route=\/wp\/v2\/media\/339"}],"wp:attachment":[{"href":"https:\/\/andreberger.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/andreberger.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/andreberger.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}