The Hunting of the Snark


category: picategory: techcategory: en created: 9. Feb. 2024
canonical: http://snark.de/index.cgi/0016

Sacnberry part 1: Scanning with a Brother scanner on the raspberry pi

So i want to us a raspberry pi to implement an easy to use scan to mail solution. My Brother printer/scanner can only do this when a Windows PC with the Brother software is running. That is not really what i wanted.

Should be easy - right? just do something like

scanimage ...
convert to pdf
ocrmypdf
mail the resulting pdf

but wait: installing sane-utils and running scanimage on raspbian does not know about this scanner:

root@shrink:~# scanimage -L

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).

root@shrink:~# sane-find-scanner
[ ... ]
found USB scanner (vendor=0x04f9 [Brother], product=0x036f [DCP-9022CDW]) at libusb:001:003
could not fetch string descriptor: Pipe error
  # Your USB scanner was (probably) detected. It may or may not be supported by
  # SANE. Try scanimage -L and read the backend's manpage.

Oh well - maybe installing sane-airscan will help? This is a generic IP based scanning protocol that most vendors implement. After installing this package i get:

root@shrink:~# scanimage -L
device `airscan:w1:Brother DCP-9022CDW' is a WSD Brother DCP-9022CDW ip=192.168.###.###
and it kind of works: you can scan - but only via the network, not over USB. And it does not work elegantly with the automatic document feeder (ADF): you have to either invoke it with
scanimage -d 'airscan:w1:Brother DCP-9022CDW' --source ADF
to get it to use the ADF (and it fails if there is nothin in there) or invoke it without the ADF option to get it to use the flatbed. I remember, that with the brother module fore sane scanning, it was possible to do this by magic: if something was in the ADF: use that. otherwise use the flatbed.

There is Linux support on the brother support pages. Right?
NOOO! Brscan is only available precompiled for i386. And the source brother provides seems incomplete and unusable. Tough some people seem to be working on that.

So let's do the most complicated means to get what i want: use quemu and a virtual i386 environment on the ARM arcitecture of the raspberry pi to get scanimage to work with the original brother scanner drivers:

wget -O /tmp/brscan4-0.4.11-1.i386.deb https://download.brother.com/welcome/dlf105201/brscan4-0.4.11-1.i386.deb
apt-get install qemu-system-x86 qemu-user-static debootstrap binutils
mkdir /opt/scanberryd-i386
debootstrap --arch=i386 --variant=minbase --foreign bullseye /opt/scanberryd-i386/
mount -t proc proc /opt/scanberryd-i386/proc
mount -t sysfs sys /opt/scanberryd-i386/sys
mount -o bind /dev /opt/scanberryd-i386/dev
mount -o bind /dev/pts /opt/scanberryd-i386/dev/pts
mount -o bind /tmp /opt/scanberryd-i386/tmp
chroot /opt/scanberryd-i386/
/debootstrap/debootstrap --second-stage
apt install /tmp/brscan4-0.4.11-1.i386.deb
This sets up an (allegedly minimal) i386 debian environment in /opt/scanberryd-i386 of nearly 600MB. I am sure that could be trimmed down a lot.
And voila: we have an environment in which the scanner can be used via USB and with the magic ADF detection:
root@shrink:~# chroot /opt/scanberryd-i386/
root@shrink:/# scanimage -L
device `brother4:bus1;dev4' is a Brother DCP-9022CDW USB scanner
root@shrink:/# scanimage -d "brother4:bus1;dev4" \
--mode "True Gray" --resolution 300 \
--source "Automatic Document Feeder(centrally aligned)" \
--format tiff --batch=/tmp/scan%03d.tiff

To make this transparently usable (at least as the root user) i set up this script to /usr/local/bin/scanimage:

#!/bin/bash

if [ ! -d /opt/scanberryd-i386/dev/net ]; then
     mount -t proc proc /opt/scanberryd-i386/proc
     mount -t sysfs sys /opt/scanberryd-i386/sys
     mount -o bind /dev /opt/scanberryd-i386/dev
     mount -o bind /dev/pts /opt/scanberryd-i386/dev/pts
     mount -o bind /tmp /opt/scanberryd-i386/tmp
     mount -o bind /home /opt/scanberryd-i386/home
     mount -o bind /var /opt/scanberryd-i386/var
     mount -o bind /root /opt/scanberryd-i386/root
fi

chroot /opt/scanberryd-i386/ /usr/bin/scanimage "$@"


(c) Heiko Hellweg 2005 - 2009 top