【Buster版】Raspberry Pi で 指紋センサ ZFM-20 を使う
【概要】
4年前に投稿した以下の記事は wheezy
版で古いので Buster
用の記事を書きます。
【環境】
$ lsb_release -a No LSB modules are available. Distributor ID: Raspbian Description: Raspbian GNU/Linux 10 (buster) Release: 10 Codename: buster $ uname -a Linux raspberrypi 5.4.47-v7+ #1322 SMP Wed Jun 17 17:52:39 BST 2020 armv7l GNU/Linux
【手順】
1. Raspberry Pi セットアップ
以下の記事などを参考に Raspberry Pi をセットアップしてください。
この記事ではセットアップの説明は省きます。
2. 指紋センサのライブラリをインストール
以下の記事内 Software installation
を参考にします。
Sicherheitskritisch | Fingerprint sensor for Raspberry Pi and Debian Linux (Update 8)
$ echo "deb http://apt.pm-codeworks.de buster main" | sudo tee -a /etc/apt/sources.list $ wget -O - http://apt.pm-codeworks.de/pm-codeworks.de.gpg | sudo apt-key add - $ sudo apt-get update $ sudo apt-get install python-fingerprint $ sudo usermod -a -G dialout pi $ sudo reboot
3. UART を有効化する
以下の記事を参考に、/boot/cmdline.txt
を書き換えます。
備忘録 Raspberry PiでUART、シリアル通信
現状は以下の通りです。
$ cat /boot/cmdline.txt console=serial0,115200 console=tty1 root=PARTUUID=e7668d32-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
念のため、別名でバックアップを取っておきましょう。
$ sudo cp /boot/cmdline.txt /boot/cmdline.txt.org
console=serial0,115200
を削除して、rpitestmode=1
を追加してください。
書き換えると以下のようになります。
$ sudo vim /boot/cmdline.txt ... $ cat /boot/cmdline.txt rpitestmode=1 console=tty1 root=PARTUUID=e7668d32-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
ここまでできたら再起動します。
$ sudo reboot
4. Raspberry Pi に指紋センサを接続
Raspberry Pi と指紋センサを直接接続します。
- 赤 5V ーーーーー GPIO 5V
- 緑 TX ーーーーー GPIO15 (RX)
- 白 RX ーーーーー GPIO14 (TX)
- 黒 GND ーーーーー GPIO GND
5. 指紋センサのライブラリを書き換える
以下のように書き換えます。
※ 今回は指紋登録用のプログラムを書き換えますが、他のプログラムを使用する場合も同じように書き換えてください
$ cd /usr/share/doc/python-fingerprint/examples/
$ sudo vim example_enroll.py
- f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) + f = PyFingerprint('/dev/ttyAMA0', 57600, 0xFFFFFFFF, 0x00000000)
6. 指紋の登録を試す
手順5で書き換えた指紋登録用のプログラムを実行すると、 指紋センサの指を当てる部分が赤く光ります。
$ python example_enroll.py Currently used templates: 0/1000 Waiting for finger...
この状態で、センサに指を当てると指紋の登録ができます。
Remove finger... Waiting for same finger again... Finger enrolled successfully! New template position #0
おわり。