Set up SANE (Scanner Access Now Easy) on a Raspberry Pi

Introducing SANE (Scanner Access Now Easy)

The SANE project lets you easily use a scanner from a Linux host. It supports many different brands and models of scanners and while it is mostly a library and server that provides access to a scanner, several clients are available that you can use to scan documents.

I’ve successfully used the SANE software to turn my Raspberry Pi and Fujitsu ScanSnap S1500 into a network enabled scanner. Here are the steps that worked for me.

What I Used

Raspberry PI

I’ve successfully set up SANE on Raspberry PI Model B+ and a Raspberry Pi Model 2. The steps outlined here should work on other Raspberry PIs as long as you are using the Raspberry Pi OS (Raspbian). As of today, the latest version available (and the one I used) is dated August 2020 with a release date of 2020-08-20.

Ansible

I’ve used Ansible to make set up easier, but this is optional. You can always do the setup by hand.

Getting Started

1. Setting Up Your Raspberry Pi OS

I’m going to assume that you already have a working Raspberry Pi and are able to access and interact with it via a shell. You should be able to login and see something like this. If you aren’t here, then please look up other tutorials on setting up your Raspberry Pi. You should now have a shell open on your Pi.

Linux scan-demo 5.4.51+ #1333 Mon Aug 10 16:38:02 BST 2020 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Oct 29 22:00:41 2020 from 192.168.2.183
pi@scan-demo:~ $

2a. Using Ansible

If you are using Ansible to set up your Raspberry Pi, you’re in luck. Here is an Ansible Playbook that will set up SANE on your Raspbery Pi. If you’re not using Ansible, follow the steps in 3b. You can skip 3b and continue on step 4 if you are going to use the playbook.

- name: Set up SANE on the PI
  hosts: all
  become: true
  tasks:
    - name: Install packages
      apt:
        pkg:
        - sane-utils
        - libxml2-dev
        - libxslt-dev
        - python-dev
        - imagemagick
        - python-pip
    - name: Install pip modules
      pip:
        name: lxml
    - name: Copy access file
      copy:
        src: ./55-libsane.rules
        dest: /etc/udev/rules.d
        owner: root
        group: root
        mode: '0644'
    - name: Add pi to scanner group
      user:
        name: pi
        groups: scanner
        append: yes
    - name: update the imagemagick policy to allow it to write PDFs
      xml:
        path: /etc/ImageMagick-6/policy.xml
        xpath: "/policymap/policy[@pattern='PDF']"
        attribute: rights
        value: 'read | write'
    - name: Reboot to have the new rules apply
      reboot:

If you are going to use this playbook, you will need to create a file locally with the udev rule needed. Create a file called 55-libsane.rules in the same directory where you are going to run the Ansible Playbook from. The contents of the file should be:

ENV{DEVTYPE}=="usb_device", ENV{libsane_matched}=="yes", MODE="0666", GROUP="scanner"

Now run the playbook, and when it is finished running, connect your scanner to the Pi, make sure it is powered up and run this command:

pi@scan-demo:~ $ scanimage -L

If your scanner is displayed, then you’re all set. If that doesn’t work, follow the manual steps below, which have a couple of troubleshooting tips.

2b. Manual Installation Using the Shell

  1. Update packages

Let’s make sure we have the latest version of the package listings. In your shell, type

sudo apt update

This will get the list of the latest packages available for install.

  1. Install SANE

We need to install SANE.

sudo apt install sane-utils

4. Testing Using scanimage

Now it’s time to test how things are going so far. We’re not completely done yet but this checkpoint should help in case there are any issues. Let’s see if scanimage can access the scanner. Make sure your scanner is powered up and connected to the Raspberry Pi. Type this to see if the scanner is accessible:

sudo scanimage -L

If all is working correctly, you should see scanimage report your scanner. This is what I see:

device `fujitsu:ScanSnap S1500:326926' is a FUJITSU ScanSnap S1500 scanner

If your scanner isn’t recognized/found, try searching for any errors you might get. There are plenty of posts out there that may help with getting SANE to work.

5. Final step, allow Pi to use the scanner

This final step is optional if you are going to scan as root. If you don’t want to have to sudo when scanning, read on. Also note that if step 4 isn’t working for you, following these steps won’t help either.

The last 2 things left to do are:

  1. Add the pi user to the scanner group
sudo usermod -a -G scanner pi
  1. Add a udev rule to allow pi to access the scanner Copy the 55-libsane.rules file you created above to the /etc/udev/rules.d directory on your pi, or use nano to create it there, as outlined below
echo 'ENV{DEVTYPE}=="usb_device", ENV{libsane_matched}=="yes", MODE="0666", GROUP="scanner"' | sudo tee /etc/udev/rules.d/55-libsane.rules

And now reboot, to have the changes apply. There’s probably a better way than rebooting, so let me know and I can update that here.

sudo reboot

When the Raspberry Pi restarts, you should now be able to simply run the scanner as the Pi user:

scanimage -L

You should now also be able to see your scanner listed.

device `fujitsu:ScanSnap S1500:326926' is a FUJITSU ScanSnap S1500 scanner