Raspberry PI USB network scanner

Eduardo Luis came up with the nice idea of using the Raspberry PI to drive a scanner that sends the scanned images via mail by just pressing a button. I think this is a quite useful way to recycle USB-Scanners. However, I found some "glitches" when following his documentation, you can find it here. This is the reason why I added some changes to the original project, and documented these changes here.

This "tutorial" is based on the following assumptions:

You have your Raspberry PI up and running, connected to the Internet via LAN or WLAN, I am using the "2013-02-09-wheezy-raspbian" image

You have a Mailserver like Exim up and running, and can send mail when using a console client like mutt

The Scanner is supported by SANE, when you run "sudo scanimage" there are no errors shown

Python is installed

You did not make changes on your Raspberry PI based on Eduardo's project, if so, replace the files you have created already, please

First of all we need to adapt the "/etc/rc.local". Add the following lines above the "exit" statement, and do not remove the "exit" statement:

Make that script executable by doing a "sudo chmod 755 /root/scripts/blinking.sh".

The next script we need to take care for is the "/root/scripts/script_listen_for_scan.py", which controls the press of the button to start the scan job. I found some glitches here I did not like to live with, so I changed it to this:

In Eduardo's script he is referring to GPIO24, but he never uses this IO during his whole project. Therefore I deactivated that part. Another change is about blocking the scanner from running several scan-jobs at the same time, maybe by pressing the button several times. My script is waiting for 3 seconds, which means you have to press the button for 3 seconds to start the scan-job. Make the script executable by "sudo chmod 755 /root/scripts/script_listen_for_scan.py".

The last script is the script that does the scan-part itself, the "/root/scripts/scan.sh":

To prevent the scan job from running twice or more often at the the same time I added a lock-functionality. Furthermore you need to add some vars you get from the user environment when being logged it. Keep in mind, later there is no user environment running, since the scanner-"daemon" will start on booting the system. Another change by me is just to create a PDF out of the scan, at least for the recipients of my scans PDFs are easier to handle than Jpegs. And finally, don't forget to change "Diese E-Mail-Adresse ist vor Spambots geschützt! Zur Anzeige muss JavaScript eingeschaltet sein!" to something useful. Make the script executable by "sudo chmod 755 /root/scripts/scan.sh".

We are done now with the software part. Time for a small test: put something to scan into your scanner, and run "sudo /root/scripts/scan.sh". Satisfied?

It is time now to do the hardware part. I am not an electronic guru, and therefore I was quite confused when reading advice like "just use a pullup resistor"...so I will go into detail a bit - without being to technical. However, power off your Raspberry PI to avoid damage.

If you just have just connected one of the GPIOs to ground or 3.3V+, you might see kind of fast switching of that GPIO. This is a well known behavior of the Raspberry PI. You have to provide a clear Ground in case the button is not pressed, and a clear V+ when the button is pressed. To achieve this, you have to use 1 additional part, a 10 kOhm resistor - the gurus have fantastic names for that like "pull up" or "pull down" resistor, and expect everybody to know the details (LOL). Let's assume you connect the switch to V+3.3 (Pin 1). The other side of this switch will be connected with two wires: one wire going directly to GPIO23 (Pin 16), and the other wire you have to connect to the 10 kOhm resistor. The other side of the resistor will be connected to GND (Pin 14 as example).

Now we need to connect a LED (yellow), just to show the Raspberry is ready to use. Connect the short pin of the LED (-) to a resistor of 270 Ohm, and the other side of the resistor to GND (Pin 9 as example). Now connect the longer pin of the LED (+) with GPIO14 (Pin 8).

The last LED is a red one. Connect the shorter pin of the LED (-) to a 270 Ohm resistor, and connect the other side of that resistor to GND (Pin 3 as example). Now connect the longer pin of the LED (+) with GPIO18 (Pin 12).

Check the wiring, especially for shortcuts etc. Looks good? Power on the Raspberry PI. After booting the yellow LED should flash from time to time, and shows you the Raspberry is up and running. Now press the button, hold it for 3 seconds until the red LED shines bright. The scanner will start its task, finish, the Raspberry will convert the image into PDF, and send it to you via mail. After handing over the mail to Exim (or your MTA), the red LED goes off. If nothing is happen, check on the console via "ps fax" if both the "blinking.sh" and "script_listen_for_scan.py" are in the process list.

Any comments? Join the Raspberry PI communities on Google+ as example: