Here is my short guide how to get a USB-Scanner with sane up and running on a Raspberry Pi.
I got the inspiration from Eduardo Luís, my setup does the same, but uses the buttons on the scanner instead of an extra button.
So it will automatically scan something and mail it to you if you press the button on your scanner (scanbuttond).
This guide is written for a Canon LIDE 20 and RASPBMC-Final as operating system.
The code you have to copy into your terminal is marked gray.
I encounterd some permission problems with apt-get on RASPMC - here is how i fixed it:
sudo chmod 777 -R /var/
First you can do an update:
sudo apt-get update && apt-get upgrade
then install screen, because the installation will take some time.
sudo apt-get install screen
start screen:
screen
press the enter key to get rid of the welcome screen.
Install the sane stuff, imagemagick to convert from tiff to jpg and scanbuttond to enable the buttons on the scanner:
sudo apt-get install sane xinetd imagemagick scanbuttond
This will take ages - if you startet this in screen you can press STRG and a and d to detach the screen and you will be able to work again.
This can be done while the rest is installing:
Create config-file for mail-client mutt:
nano /home/pi/.muttrc
insert into this file (source: Ubuntu-wiki):
set sendmail="/usr/bin/msmtp" #Pfad zu dem Programm, das die Mails verschicken soll
set envelope_from=yes #übergibt msmtp automatisch den richtigen Absender
set edit_hdrs #Empfänger u.a. auch im Editor bearbeiten
set signature ="~/.mutt/signatur" #Datei, die den Text der Signatur enthält
set attribution="%f schrieb am %d:" #Zitatkennzeichnung in unserer Muttersprache :)
set sort=threads #E-Mails werden nach Gesprächsverlauf und nach Datum sortiert
set sort_aux=date-sent
#set sort=date #würde alternativ zuerst nach Datum sortieren
unset allow_8bit #u.U. verbesserte Darstellung von Umlauten
set date_format="%a, %d. %b %H:%M" #gibt an, wie das Datum formatiert wird
set index_format="%4C %Z %D %-22.22F (%?l?%4l&%4c?) %s" #Format der Mail-Übersicht
set folder_format="%2C %8s %d %t %N %f" #Format des Datei-Browsers
set pager_index_lines=10 #Anzahl der angezeigten Mails in der Übersicht
set editor="vim +8" #Editor, der zum Verfassen der E-Mail benutzt wird, hier vim
save the file, close and create config-file for smtp-client msmtp:
nano /home/pi/.msmtprc
insert the following into this file, safe afterwards:
#for Googlemail
defaults
tls on
tls_starttls on
tls_certcheck off
auth on
account Google
host smtp.googlemail.com
from INSERT-EMAIL-HERE@googlemail.com
user INSERT-EMAIL-HERE@googlemail.com
port 587
password PASSWORD
account default: Google
create the folder scan in your pi-homefolder for your scans:
mkdir /home/pi/scan
sudo chmod 777 -R /home/pi/scan
create a message file, which contains the message of the email you are going to send:
nano /home/pi/scan/MSG
Insert for example:
Hi,
here is your scan from your RPI!
add a entry in crontab to start scanbuttond everytime you reboot:
sudo nano /etc/crontab
add the following lines, the first one is necessary to allow every user to use the usb-ports:
@reboot root chmod 777 -R /dev/bus/usb
@reboot pi scanbuttond
#
type the following to see the progress of your sane installation:
screen -r
if there are some error messages try resolving them with:
sudo apt-get install -f
if there are some permission errors try the following command with the according directories and try the step before again:
sudo chmod 777 -R /FOLDER
if everything went fine, do a reboot:
sudo reboot
after reboot is finished, make sure scanner is connected and type this to detect the scanner:
scanimage -L
HINT: i have to manually run scanimage -L everytime i reboot to get the scanner working, because my rpi won't start if i put it in the crontab. Maybe someone knows how to fix it.
now create a script, that tells the RPI what to do according to which button is pressed:
nano /etc/scanbuttond/buttonpressed.sh
insert the following:
#!/bin/sh
case $1 in
1)
DATE=$(date +"%Y%m%d%H%M")
scanimage -x 210 -y 297 --format=tiff --mode color --resolution 300 > /home/pi/scan/$DATE.tif
convert /home/pi/scan/$DATE.tif /home/pi/scan/$DATE.jpg
mutt -s "scan from your scanner" -a /home/pi/scan/$DATE.jpg -c INSERT-DESTINATION-EMAIL@googlemail.com < /home/pi/scan/MSG
rm /home/pi/scan/$DATE.jpg
rm /home/pi/scan/$DATE.tif
;;
2)
DATE=$(date +"%Y%m%d%H%M")
scanimage -x 210 -y 297 --format=tiff --mode gray --resolution 300 > /home/pi/scan/$DATE.tif
convert /home/pi/scan/$DATE.tif /home/pi/scan/$DATE.jpg
mutt -s "scan from your scanner" -a /home/pi/scan/$DATE.jpg -c INSERT-DESTINATION-EMAIL@googlemail.com < /home/pi/scan/MSG
rm /home/pi/scan/$DATE.jpg
rm /home/pi/scan/$DATE.tif
;;
3)
DATE=$(date +"%Y%m%d%H%M")
scanimage -x 210 -y 297 --format=tiff --mode color --resolution 300 > /home/pi/scan/$DATE.tif
convert /home/pi/scan/$DATE.tif /home/pi/scan/$DATE.jpg
mutt -s "scan from your scanner" -a /home/pi/scan/$DATE.jpg -c INSERT-DESTINATION-EMAIL@gmail.com < /home/pi/scan/MSG
rm /home/pi/scan/$DATE.jpg
rm /home/pi/scan/$DATE.tif
;;
4)
;;
esac
The numbers 1) 2) 3) stand for the buttons on your scanner:
1) for example scans color and 2) scans grayscale.
For 3) you could add your Girlfriends email for example.
Now try pressing a button on your scanner - it should work now!
Have a lot of fun!
sources:
Keine Kommentare:
Kommentar veröffentlichen