EcoPrinter
Paper use has increased dramatically and the negative impact of this on the environment is significant. Undoubtedly, it is now time for us to take action and reduce the use of paper in our daily lives. That is why we are introducing the ecoPrinter!!! This innovative device which is an implementation of Android Beam and USB Printer Gadget can easily help us replace hard copies with file transferring. And guess what... this can be effortlessly achieved and at a very low cost!!!
EcoPrinter is a device which allows the user to use the NFC protocol with the Android Beam implementation in order to transfer any type of printed work to a mobile device without taking any necessary action apart from unlocking the mobile device! From the user's perspective,meaning those who wish to receive documents on the mobile device, no further action is required (works similar to the NFC Payments). No App installation, no setting up, it just magically "works". From the provider's perspective all it has to be done is to connect ecoPrinter to the computer and run a command to correlate the appropriate Microsoft Driver with the device (No custom drivers, no downloads, no installations - Just a command).This is a one-off procedure and then users can enjoy the benefits of ecoPrinter!
EcoPrinter should not only be considered as a device for personal use but for professional use as well. Imagine how helpful it would be if every business, organisation or authority used the ecoPrinter. Any receipt and other important documents would be saved and organised on your mobile device to be easily accessed any time needed. Undoubtedly, by cutting down the use of paper not only benefits our environment but can also help users to save money from paper and toner usage.
It should be noted that each ecoPrinter has a unique serial number which could be used to have the total spending's per store / category, better management of your financial state, even logs by each supplier.
EcoPrinter will not only help towards reducing the amount of paper we use but it will also help the users organise and keep their receipts, invoices, documents with the minimum amount of effort required from both parties (user & provider)
EcoPrinter is a proof of concept and only the bare minimums have been hereby described.
Let's go paperless!!!
How it works
- The provider (owner of the device) connects the ecoPrinter and correlates the appropriate driver.
- The provider of the ecoPrinter functionality simply selects the document to be printed and selects ecoPrinter as the preferable printer device.
- The file is then send to the Raspberry Pi and is converted to PDF.
- The WS2812B indicates to the user that it's time to place the device to the ecoPrinter
- With no other interaction the file is transferred to the mobile device as a PDF.
Detailed explanation of a file transfer using the ecoPrinter (What is the meaning of the different lighting effects)
- The Print job has been sent from the computer to the ecoPrinter (same as the standard printing procedure)
- Green light ring effect on ecoPrinter means that the device is receiving the print job and converts the file into a PDF.
- Red light ring effect means that ecoPrinter is waiting for an NFC Device to connect
- Green light ring effect following the red one, means that the NFC connection was successful and ecoPrinter is waiting for the Bluetooth handover
- Blue light ring effect, Bluetooth connection initiated and the file is being transferred to your mobile device.
Supplies
For the provider
- Raspberry PI Zero W ( Can be used as a USB Gadget, and has WIFI and Bluetooth onboard)
- PN532 NFCShield(other shields would also work thanks to the great work of Mr.
Stephen Tiedemann, the creator of the nfcpy library)
- WS2812 5050 RGB 12 LEDs Ring (optional)
For the end user
- Android Device with NFC functionality and Android version of 9 (PIE) or previous.
- Android Beam enabled from the Device's Settings menu.
Make the Hardware Connections
The ecoPrinter hardware configuration is very simple and is as follows:
- Connect the NFC Board, using Raspberry's UART (GPIOs 14,15). There are different types of NFC Boards but almost all of them support serial communication. Select a board which is compatible with nfcpy library and AVOID devices which connect using the USB because Raspberry PI cannot be a USB Host and a USB Gadget at the same time (So it will not work)
- Use GPIO 18 as the DATA pin to control the WS2812B led panel.
- Provide power to both boards from Raspberry PI.
Raspberry Preparation
- Download the last Raspbian (Version: February 2020) from the official page
- Prepare the SD card with the Raspbian following the official instructions from here
- Create a new file with name ssh (don't use any extension), in the boot partition of the SD Card
- Create a new file wpa_supplicant.conf , in the boot partition of the SD Card and enter the following content:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="YOUR_WIFI_NETWORK_SSID" psk="YOUR_WIFI_NETWORK_PASSWORD" }
- Append the following lines at the end of the file config.txt in the boot partition of the SD card
# Enable serial communication - It will be used for communication with the NFC Shield enable_uart=1 # Set GPU memory to 16 MB, as long as we don't use any display gpu_mem=16 # Enable dwc2 overlay in order to convert the Raspi to a Printer Gadget dtoverlay=dwc2
- Remove the following text from the file cmdline.txt in the boot partition of the SD card, in order to disable console usage via serial port.
console=serial0,115200
- Safely remove the SD-Card from your computer, insert it in the Raspberry PI and boot.
- After the boot sequence complete, follow the appropriate procedure for your Operating System (Windows, Windows 10, Mac or Linux) to connect to the device using SSH.
- Update Raspbian's repositories and software using the following commands.
sudo apt-get update sudo apt-get upgrade -y
- Set the appropriate modules to be loaded on each boot by using the following commands:
sudo su echo 'dwc2' >> /etc/modules echo 'libcomposite' >> /etc/modules exit
After typing sudo su, the user indicator will change and all commands will be executed as root. - You can confirm your actions by displaying the /etc/modules files
cat /etc/modules
- Install the required libraries for the WS2812B Neopixel Ring using the command:
sudo pip3 install rpi_ws281x adafruit-circuitpython-neopixel
Convert Raspberry PI to a Printer Gadget
- Create the directory which will hold the configuration file
sudo mkdir /usr/bin/nm_gadget
- Create the USB Gadget configuration file
sudo nano /usr/bin/nm_gadget/ecoPrinter
- Paste the printer device configuration
#!/bin/bash #ecoPrinter Gadget #author: novamostra.com modprobe libcomposite cd /sys/kernel/config/usb_gadget/ mkdir -p ecoPrinter cd ecoPrinter # Device's Information echo 0x04a9 > idVendor echo 0x1761 > idProduct echo 0x0100 > bcdDevice echo 0x0200 > bcdUSB echo 0x07 > bDeviceClass echo 0x01 > bDeviceSubClass echo 0x01 > bDeviceProtocol # Set English Locale mkdir -p strings/0x409 echo "10000001" > strings/0x409/serialnumber echo "Novamostra" > strings/0x409/manufacturer echo "ecoPrinter" > strings/0x409/product mkdir -p configs/c.1/strings/0x409 echo 120 > configs/c.1/MaxPower mkdir -p functions/printer.usb0 echo 10 > functions/printer.usb0/q_len echo "MFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;" > functions/printer.usb0/pnp_string echo "Conf 1" > configs/c.1/strings/0x409/configuration ln -s functions/printer.usb0 configs/c.1/ ls /sys/class/udc > UDC
- Use Ctrl + X key combination to close the file
- When asked to save changes, press "y"
- Press enter in order to skip selecting a new name for the file.
- Make the configuration file executable
sudo chmod +x /usr/bin/nm_gadget/ecoPrinter
- Set the configuration file to run on boot by editing the rc.local file
sudo nano /etc/rc.local
- And adding the following line before the "exit" keyword
/usr/bin/nm_gadget/ecoPrinter
- Install Ghostscript which will handle the conversion from Postscript to PDF
sudo apt-get install ghostscript -y
- The printer device is now ready. Power off your Raspberry Pi:
sudo poweroff
- Connect a usb cable from the Computer to the USB port (not the power port) of the Raspberry PI. Your PI will boot and a notification about a new unknown device, will appear on Windows.
- In the Device Manager of your Windows Computer, the Raspberry PI will appear as a Composite Device.
Driver Setup on Windows
After connecting the ecoPrinter device using a micro usb cable your computer, open a Command Prompt Window with Administrative Privileges and run the following command:
printui /if /b "ecoPrinter" /f %windir%\inf\ntprint.inf /m "Microsoft PS Class Driver" /r "USB001"
This will correlate the Microsoft PS Class Driver to the ecoPrinter, and a new printer device will appear in your available printers.
If after running the command you receive message Operation could not be completed (error 0x00000704), that means that the device was setup on a different port. Re-run the command changing the USB001 to USB002 or USB003.
If no error appears that means that your device is correctly setup. You can confirm this, by opening the Device Manager and under the Print queues the "ecoPrinter" device is available.
Setup Bluetooth Communications
Setup Obex FTP which is required for file transferring, using the command
sudo apt-get install obexftp
Find Raspberry Pi's bluetooth address using the command
hciconfig
Important: Keep a note of the Bluetooth MAC address because we will use it in the configuration file of the ecoPrinter which is required for Bluetooth Handover.
Setup NFC Communications
This device uses the nfcpy library to initiate the connection and make the handover to the Bluetooth protocol.
Start by installing the Python Package Installer running the following command:
sudo apt-get install python3-pip -y
and then install nfcpy library using the following command:
sudo pip3 install nfcpy
Make sure that everything is installed and the hardware connections are correct using the command:
python3 -m nfc --search-tty
Your device must appear at serial/ttyS0
Copy Appropriate Files From the EcoPrinter Repository
Now your Raspberry is a Printer gadget with Bluetooth and NFC functionality. The last step is to connect all this separate pieces to the final product. First install git:
sudo apt-get install git -y
and then clone the ecoPrinter repository using the command:
git clone https://github.com/novamostra/ecoPrinter
Edit the ecoPrinter.conf file and add your device's Bluetooth MAC address
sudo nano ecoPrinter/code/ecoPrinter.conf
Make a new directory to store the print jobs
mkdir ecoPrinter/code/prints
Set the appropriate permissions to the daemon:
sudo chmod +x ecoPrinter/code/ecoPrinter.sh
Edit for another time the rc.local file:
sudo nano /etc/rc.local
And add the following line before the "exit" keyword
/home/pi/ecoPrinter/code/ecoPrinter.sh
Congratulations !! Your ecoPrinter has been successfully set up! Reboot your device and you are ready to go!!!
[Update] May 2019 : All the procedure is now automated using the setup.sh from the ecoPrinter's repository!