Raspberry Pi Print And Scan Server part 1: Scan Straight To Dropbox

This project initially started out as a Raspberry Pi printer server. Looking for a new printer I didn’t feel like paying an additional 60 euros for a network enabled printer. I knew our beloved Raspberry Pi could do that job just fine. While waiting for my new printer to arrive I decided to also hook up my old scanner and make it a print and scan server. The scanner part is now finished and can scan straight to Dropbox with the push of a button. Not bad for a 35 euro print and scan server.

I’ll admit right away inspiration for the scanning part this project came from a few other great projects out there (references at the bottom of this post). But non of those projects did exactly what I had in mind and also weren’t described well enough to start building straight away.

The primary goal of this first part of the project was to scan without turning on a computer and pick up the result somewhere. As a  bonus I figured it would be nice to see the progress of your scan jobs. So I created my own hardware with a Scan button and progress indication LEDs, selected the right programs and wrote scripts to glue everything together. Let’s see how it’s done.

NOTE: Before reading any further (and attempting this yourself) you should know the GPIO pins of the Raspberry Pi are not protected against high voltages. Incorrect wiring can result in a framboise flambée (yep, a Fried Pi). The hardware isn’t complex but only attempt this if you’re sure you know what you’re doing. I’m in no way responsible for any damage inflicted on your Raspberry Pi.

The first thing to do is check if you’ve got all required ingredients. This project uses the following hardware:

  • A Raspberry Pi model B (revision / memory is not important)
  • An SD card (2 GB or more)
  • A Sane compatible scanner
  • Components for GPIO interface board (breadboard, push button, 6 LEDs (5 green, 1 red), 10K Ohm resistor, 300 Ohm resistor, jumper cables)

If you’ve got all the required hardware you should start of with a clean Raspbian “Wheezy” installation. Make sure you re-size the partition (more space for programs and storing scans) and enable SSH. Also give your Raspberry a fixed IP address because it is a server after all.

Once Raspbian is up and running you can start installing the required programs. For scanning images we’ll use Sane. Login to your Pi (directly or over SSH) and type: sudo apt-get update followed by sudo apt-get install sane . After that you need to fix permissions so your user is allowed to scan. To do so enter: usermod -a pi -G scanner . Now it’s time to check if Sane is setup correctly. Type scanimage –L and Sane should list your scanner. Great.

The number of image formats Sane can output is limited. We’ll install ImageMagick so we can convert our images to almost any format. The current version of my setup only supports jpegs but future versions should also allow you to export as (multi page) PDF. To install ImageMagick simply type: sudo apt-get install imagemagick .

While other projects use email or network shares to distribute scanned images I thought it would be really cool if you could upload them directly to Dropbox. Not much information could be found about this and there is also no official Raspberry Dropbox client.

Fortunately Andrea Fabrizi created a great Bash script for uploading files to Dropbox which we will use. This post works with version 0.11 of the script which can be downloaded using the following command:

wget https://dl.dropboxusercontent.com/u/14310672/dropbox_uploader.sh

After that make the script executable ( sudo chmod +x dropbox_uploader.sh ). We’ll call this script later from our own script. For now you can leave the script alone.

Since we’ll be using Python to glue everything together and control the LEDs you need to install the RPi.GPIO library. You can do this, surprise surprise, using apt-get:

  1. sudo apt-get update
  2. sudo apt-get install python-dev
  3. sudo apt-get install python-rpi.gpio

The last step can probably be skipped since it is already part of the python-dev package.

The last piece of software needed is the python script to make all the magic happen. I’ve made this script, named scan.py, available on GitHub (raspberry-pi-scan-print-server). It should be placed in your home directory (/home/pi). To do so login to your Pi if you haven’t already and go to your home directory (cd ~) and run the command wget https://raw.github.com/gijsbertpeijs/raspberry-pi-scan-print-server/master/scan.py .

With the software all in place it is time to focus on the hardware. Like said before: the scheme isn’t too difficult but if you don’t feel comfortable doing this just don’t. It’s not worth frying your Pi over this and in the future I’ll write a post about controlling the scanner with your phone anyway.

The circuit we’re trying to make looks like this:

Raspbery Pi scan server circuit

Raspbery Pi scan server circuit

Basically it’s a switch hooked up to GPIO pin 8 using a 10K Ω pull up resistor for a clear On/Off signal. The 6 LEDs are connected to GPIO pins 10, 11, 12, 13, 15 and 16 with a 300Ω resistor to keep voltages at an acceptable level. The resistor for the LEDs should be roughly 300 Ω but a bit more or less doesn’t hurt. Also make sure you connect the LEDs in the right way (minus towards the GPIO pins).

Once you circuit board is finished you can hook it up to your Raspberry Pi (make sure you hook up all pins correctly before powering your Pi. Especially pin 1 (right next to the P1 marking on your Raspberry Pi) is very important.). Once the Raspberry Pi is booted login and type sudo python scan.py (root is required because we’re fiddling with the GPIO connector). The first LED should turn on (System Ready) and after you push the switch your scanner should start scanning.

When the scanner is finished the next LED will go green indicating the tiff file is being converted to a (much smaller) JPEG. After that the Dropbox upload script will kick in. The first time you run it you need to follow the simple on-screen instructions to connect the Raspberry Pi to your Dropbox account. Since you need you copy/paste some links to your browser it helps enormously to perform this part on a PC while connecting to your Raspberry Pi over SSH.

After you finished your Dropbox setup the 5th LED should blink three times telling you everything went well. Push the switch again to test if the script will now run without any user input. If it does go to your Dropbox folder and under Apps/<YourAppName> there should be 2 scans. Well done!

For the finishing touch go to /etc/ on your Raspberry Pi and edit the rc.local file (sudo nano rc.local). Just before the end (exit 0) add a line containing: sudo python scan.py & . This makes the scripts start up automatically on boot. Reboot your Pi and see if the System Ready LED comes up. If it does your in business and you’ve got your Raspberry Pi powered scan server with one-click-to-Dropbox capabilities.

That’s it for part 1 of this series. In part 2 I’ll be setting up the printer bit of the server. But I also got plenty of nice ideas I want to add to the scanner server. What would you think about:

  • web interface for scanning (advanced settings)
  • control scanner from your smartphone
  • scanning to PDF (with multi page support)
  • one button copy to printer

So watch this space. There’s lots more to come.

Inspiration for this project came from the following sources:

15 thoughts on “Raspberry Pi Print And Scan Server part 1: Scan Straight To Dropbox

  1. Pingback: Top 10 Coolest Things You Can Do With a Raspberry Pi | gaducated.com

  2. Pingback: Raspberry Pi Print And Scan Server part 2: CUPS and AirPrint Setup

    • Thanx. Unfortunately I didn’t have a lot of time to work out my ideas. But it seems like I’ll have some more time on my hands soon and finish the web interface/smart phone controls.

  3. Great, great job, master. I will modify the script to scan to a smb folder, but the project is amazing. I’m subscribed awaiting for that final ideas… :)

    • Hi,

      with some tweaking of this script you should be able to upload to Google Drive as well. I haven’t bothered cause Dropbox is working fine for me.

      The biggest issue with Google Drive is that if you run two-step authentication (like I do) you need to figure out a way to handle the whole security number entire and renewal.

      Think you’re better of creating a Dropbox account and save yourself the trouble.

  4. I did all the stuff in here but i end up not uploading the scanned file to Dropbox. Instead i get the something that shows how to use the dropbox script. What am I doing wrong?

    • Oh. The first time you run this script it indeed will ask you for a couple of things to setup the script for your Dropbox account.

      You should run it once from an SSH terminal and after that the Python script should be able to use it without any problems. Hope this solves your problem..

      • I already did the setup. I run the python script and the scanning process start. but after the 3rd LED blinks up this is what shows up.

        /home/pi/scan_19-01-14_11-22-38
        Dropbox Uploader v0.13
        Andrea Fabrizi – andrea.fabrizi@gmail.com

        Usage: /home/pi/dropbox_uploader.sh COMMAND [PARAMETERS]…

        Commands:
        upload
        download [LOCAL_FILE/DIR]
        delete
        move
        copy
        mkdir
        list [REMOTE_DIR]
        share
        info
        unlink

        Optional parameters:
        -f Load the configuration file from a specific file
        -s Skip already existing files when download/upload. Default: Overwrite
        -d Enable DEBUG mode
        -q Quiet mode. Don’t show messages
        -p Show cURL progress meter
        -k Doesn’t check for SSL certificates (insecure)

        For more info and examples, please see the README file.

        -anything on mind on what’s causing these problem?

  5. Hey thanks for this project. I’m having some trouble to get it to work correctly. I made the scheme and it works. However, there seems to be a constant ‘on’ signal going on. The script keeps running and every minute there is a new scan uploaded to my dropbox, which obviously is not my intention. The only way to stop the script is to remove the push button (it’s still on a breadboard). Any ideas what might be going wrong?

    • Have you got the 10K Ω pull up resistor in place. This realy helps to create a clear push button signal. Apart from that there is little I can think of that would cause this behaviour.

      • I had the resistor in place, but it turns out this was just me being a noob. You’re supposed to wire up the push button diagonally, not straight across as I did. After I fixed that it works :-).

Leave a Reply