Raspberry Pi Scanner using HP PSC 2170

A few days ago I decided to have a good sort of all my old documents, statements and piles of paper that I’ve kept for years just incase I need it (I doubt I’m ever going to need my mobile phone statement from 2008).
I’ve been looking on ebay for a few months for a networked duplex document scanner. but these seem to easy break £70 and I don’t think I’d get alot of use out of it beyond initially scanning everything.
I already have a HP PSC 2170 Printer/scanner (not duplex), but the windows software is pretty crap, I use irfanview (which is a great bit of software), but the HP scanning software insists on loading for each scan then warmup the lamp and do a prescan before allowing me to actually scan. It’s always put me off using it.

So while thinking I’ve got papers everywhere, a scanner, and a few free PI’s a little light went off in my head, surely I can use a PI (I’m not expecting wonders with the scanner) but it’s something to play with. So google being your friend I went looking and came across:-
http://eduardoluis.com/raspberry-pi-and-usb-network-scanner/

ok so I could just take what he’s done and just use it. It looks like a good idea, and he/she has updated the process to include some form of web interface. Anyway it’s not what I need I just want to be able to scan to a device that’s on my network.

I put a rasbian image onto the PI, expanded the 16Gb SD card, named the PI and run updates.
Then I installed ‘sane’ via ‘apt-get install sane’
{note this is from memory, my history doesn’t contain all the commands I’ve used, I’ll need to recheck this on a fresh install}
Once sane was installed I used ‘scanimage -L’ to check my device is being detected. Nope nothing get’s listed. A quick google search for ‘sane HP PSC 2170’ I found a page listing HP PSC 2170 as good support. so I thought, well it should just be working. after a bit of scrolling around I noticed the table had an end column listing driver as hpaio, this wasn’t apparent against my printer, nevermind it’s another clue. So a bit more poking around to find out if the driver is installed I found ‘apt-get install libsane-hpaio’. Now when running ‘scanimage -L’ I get device `hpaio:/usb/PSC_2170_Series?serial=XXXXXXXXX’ is a Hewlett-Packard PSC_2170_Series all-in-one’.

With all this up and running I’m now onto getting an image. Running ‘scanimage -p –format=tiff –resolution=150 > test.tiff’ gives me a nice image within a few seconds. I was surprised at just just how quick the scanner sprang into action. No scanning the same piece of paper twice, no warming up the lamp.

Now that I have this, I’d much rather a jpg than a tiff. so I use ‘convert temp.pnm temp.jpg’ oh look another error, convert isn’t a valid command. Of course it’s not, I forgot to install anything. ‘apt-get install imagemagick’ and rerun the convert and now I have a much smaller jpg file. (I’m going to skip the steps I used to install and configure samba, to be able to pickup my images, but take it I did. I could have just as easily used WinSCP to access the files)

With all the tests done, and alot of {press up, press enter} I decided to write a quick bas script. First to just capture an image then convert it using a filename provided, then I improved it to save the filename based on the unix time, next I improved it to be able to group multiple pages into a single folder. Below is the script that when run, gives an option of single scan page or multi scan page, goes off and runs the scan and convert and returns either to the initial prompt or in multimode ask if there’s another page.

cat /usr/sbin/scan_it.sh
#!/bin/bash
scan()
{
image_date=`date +%s`
pwd=`pwd`
echo "  :  Scanning Image $image_date into $pwd"
scanimage --resolution=200 > temp.pnm
convert temp.pnm $image_date.jpg
rm temp.pnm
}
while [ true ]
do
  read -n 1 -p "Single, Multiple, Quit? " INPUT
  case "$INPUT" in
  s)
    cd /var/scans/
    scan
    ;;
  m)
    folder_date=`date +%s`
    mkdir /var/scans/$folder_date
    cd /var/scans/$folder_date
    YN=y
    while [ "$YN" == "y" ]
    do
      scan
      echo "Another Page? (Y/N) "
      read -n 1 YN
    done
    ;;
  q)
    echo " Quitting... Goodbye..."
    exit 0
    ;;
  *)
    echo " Not an Option! "
    ;;
  esac
done
This script presumes you have already made a folder ‘/var/scans’ using ‘mkdir /var/scans’
I did also setup sane to run as a network service making the scanner available from other machines, but I haven’t tested this yet. For my needs I decided to keep the images as jpgs rather than make PDF’s I still may make PDF’s out of all my documents, especially the multi paged ones. But I like the idea that I can access jpg’s on pretty much anything (including my recent experiments with python and pygame to display graphics on my TV via HDMI. I think PDF’s are a little more restrictive).
When doing the initial google search I also came across:-
Which looks like a really promising idea. To move away from needing terminal access to the PI to scan stuff.
The main reason I’ve decided not to go any further at the moment, is my printer/scanner I think is starting to die (not related to this setup) on a few occasions it’s refused to scan and needed a reboot, it’s also locked the scanner at the bottom of the page instead of returning after a scan, and went through alot of clunking (which just wouldn’t stop) when it was initializing after one reboot.
While it has the possibility of failing to complete a scan I’d rather be able to see any errors on screen.
I’ve spent tonight scanning over 400 pages, at the end of which I copied all the files to my server and run a backup then happily set fire to each piece of paper I’ve been keeping for years. It’s been something of a therapeutic exercise. I have no doubt I’ll be returning to this little project in time to actually incorporate sending the files directly to the server, having the option to email them, converting to PDF on request, and god knows whatelse. For the time being this script is doing me just fine. The only option I may incorporate is a selection of a ‘scan to’ folder before selecting single/multiple after scanning alot of bank statements, phone statements, payslips, etc I know I’m going to be sorting them all into subfolders and doing this at the time of scan just makes more sense.
Anyway that’s my rambling for today. Hopefully it will give someone some ideas.

Leave a Reply

Your email address will not be published. Required fields are marked *