Scan from Raspberry PI terminal with SANE


With more and more people going near to programming languages, the requirement to get common external devices running from terminal command can become useful for your personal apps. A case use can include driving a scanner from terminal console and getting results with a Raspberry PI and the tool we are going to install is SANE

In this tutorial I’m going to show you how to install SANE in Raspberry PI and getting scanner job results from terminal.

SANE (Scanner Access Now Easy) project aims to make easy interfacing scanners, digital stills, cameras and, generally speaking, any image acquisition device.

It is an application programming interface (API) which standardizes access to any raster image scanner hardware. The SANE API is open source (under GNU General Public License), anyone willing to contribute can give its help as explained in SANE Contributing page. Its code is written for UNIX, but ports to MacOS X, OS/2 and Microsoft Windows are either already done or in progress.

The main benefit from SANE is that your code will not need to use a different class for each imaging device you could use. SANE works as an intermediate framework between your code and external scanners getting a standard way to call you image acquisition. This broad compatibility will make SANE package size quit big (a few hundreds of MB to download).

A secondary effect of this package, is that you can easily get images from a terminal command, without needing any GUI interface.

For this tutorial I’m going to use a Raspberry PI Zero W, connected to my HP Photosmart C4680 multi-function printer. This guide will apply to any Raspberry PI computer board and

Follow peppe8o posts on -> Twitter

What We Need

As usual, I suggest adding from now to your favourite e-commerce shopping cart all the needed hardware, so that at the end you will be able to evaluate overall costs and decide if continue with the project or remove them from the shopping cart. So, hardware will be only:

Raspberry PI Zero W unpopulated

Check hardware prices with following links:

Amazon raspberry pi boards box
Amazon raspberry pi Zero W box
Amazon Micro SD box
Amazon Raspberry PI Power Supply box

Step-by-Step Procedure

Prepare Operating System

Start installing your OS. You can use Raspberry PI OS Lite (for a fast, headless operating system) or Raspberry PI OS Desktop (in this case working from its internal terminal).

Make your OS updated. From terminal, use following command:

sudo apt update -y && sudo apt upgrade -y

Install required packages:

sudo apt install sane sane-utils

Connect your Raspberry PI to scanner USB cable and power this on.

Test Scanner Connection

I will use my HP Photosmart C4680 printer, so next steps may produce different results depending on your device.

The very first scanner connection test uses sane-find-scanner tool. From terminal:

sudo sane-find-scanner | grep found

If this finds your scanner, you are a step ahead:

pi@raspberrypi:~ $ sudo sane-find-scanner | grep found
  # No SCSI scanners found. If you expected something different, make sure that
found USB scanner (vendor=0x03f0 [HP], product=0x7411 [Photosmart C4600 series]) at libusb:001:002

An answer like this will tell us that our Raspberry PI can see scanner connection. Oherwise, please check usb cable connection and verify that your scanner is powered on. If nothing of these solves, it becomes really hard and it is really hard that SANE can work with your printer.

More lucky people can go ahead with second test:

sudo scanimage --list-devices

This checks if SANE backend can communicate with your scanner. You will probably see aready listed your device. In this case you can go on to Scan Test paragaph. Otherwise you will receive a message like following one:

pi@raspberrypi:~ $ sudo scanimage --list-devices
No scanners were identified. If you were expecting something different,
check that the scanner is plugged in, turned on and detected by the
sane-find-scanner tool (if appropriate). Please read the documentation
which came with this software (README, FAQ, manpages).

This message means that your backend can’t use your scanner. If you have an HP scanner, you can probabily solve this with following package:

sudo apt install hplip

This will setup all required files for your HP devices to work and will get us a more comfortable list result:

pi@raspberrypi:~ $ sudo scanimage --list-devices
device `hpaio:/usb/Photosmart_C4600_series?serial=CN99ING0JD05BQ' is a Hewlett-Packard Photosmart_C4600_series all-in-one

If you have a different scanner, you will need to find for a similar package (like hplip) to make things work.

Scan Test

Finally, you can test your scanner. From terminal:

sudo scanimage --format=jpeg --resolution=300 -p > output.jpg

With file command we can verify our output properties:

pi@raspberrypi:~ $ file output.jpg
output.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 300x300, segment length 16, baseline, precision 8, 2549x3506, components 3

This command will scan your image creating a jpeg format (–format=jpeg), with a 300 DPI resolution (–resolution=300), showing progress during scan (-p) and saving it in a file named “output.jpg”.

More options for scanimage command can be found in its manual. From terminal:

man scanimage


How useful was this post?

Click on a star to rate it anonymously!

Average rating 5 / 5. Vote count: 3

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?