CONTACT
お問い合わせ

RaspberryPiを利用した交通系ICカードデータ読み取り

RaspberryPiを利用した交通系ICカードデータ読み取りの構築手順を説明する。

目次

構築手順

  1. 構築手順
  2. 今後の課題

1.構築手順

1.RaspberryPiを準備する

今回はRaspberry Pi3 Model Bを利用。基本的なセッティングは済んでいる状態で以下を開始。

2.USBの状態を表示

pi@raspberrypi:~ $ lsusb
Bus 001 Device 005: ID 0461:4e22 Primax Electronics, Ltd
Bus 001 Device 004: ID 413c:2107 Dell Computer Corp.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

3.ICカードリーダPaSoRi<RC-S380>をUSBに接続する

4.USBの状態を再表示

Device006に「Sony Corp.」が表示される。※これがICカードリーダ

pi@raspberrypi:~ $ lsusb
Bus 001 Device 005: ID 0461:4e22 Primax Electronics, Ltd
Bus 001 Device 006: ID 054c:06c3 Sony Corp.
Bus 001 Device 004: ID 413c:2107 Dell Computer Corp.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

5.Pythonのパッケージ管理システム(pip)をインストールする

pi@raspberrypi:~ $ sudo apt-get install python-pip
Reading package lists... Done Building dependency tree Reading state information... Done python-pip is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

pi@raspberrypi:~ $ sudo pip2 install --upgrade pip
Downloading/unpacking pip from https://pypi.python.org/packages/b6/ac/7015eb97dc749283ffdec1c3a88ddb8ae03b8fad0f0e611408f196358da3/pip-9.0.1-py2.py3-none-any.whl#md5=297dbd16ef53bcef0447d245815f5144
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB): 1.3MB downloaded Installing collected packages: pip
Found existing installation: pip 1.5.6
Not uninstalling pip at /usr/lib/python2.7/dist-packages, owned by OS Successfully installed pip Cleaning up...

6.nfcpyモジュールをインストールする

pi@raspberrypi:~ $ sudo pip2 install nfcpy
Collecting nfcpy
Downloading nfcpy-0.13.0-py2-none-any.whl (216kB)
100% |????????????????????????????????| 225kB 906kB/s Collecting ndeflib (from nfcpy)
Downloading ndeflib-0.2.0-py2.py3-none-any.whl (42kB)
100% |????????????????????????????????| 51kB 2.1MB/s Requirement already satisfied: pyserial in /usr/lib/python2.7/dist-packages (from nfcpy) Collecting pydes (from nfcpy)
Downloading pyDes-2.0.1.tar.gz
Collecting libusb1 (from nfcpy)
Downloading libusb1-1.6.4.tar.gz (55kB)
100% |????????????????????????????????| 61kB 1.6MB/s Building wheels for collected packages: pydes, libusb1
Running setup.py bdist_wheel for pydes ... done
Stored in directory: /root/.cache/pip/wheels/34/54/ce/2ba923ed81e139b6d703f7e2927c1f15d03425c8fd3f4bad25
Running setup.py bdist_wheel for libusb1 ... done
Stored in directory: /root/.cache/pip/wheels/d0/0b/ca/656a803e1208b31eda29cbee8aafafe6c89da02f453a9562d9
Successfully built pydes libusb1
Installing collected packages: ndeflib, pydes, libusb1, nfcpy Successfully installed libusb1-1.6.4 ndeflib-0.2.0 nfcpy-0.13.0 pydes-2.0.1

pi@raspberrypi:~ $ pip show nfcpy
Name: nfcpy
Version: 0.13.0
Summary: Python module for Near Field Communication.
Home-page: https://github.com/nfcpy/nfcpy
Author: Stephen Tiedemann
Author-email: stephen.tiedemann@gmail.com
License: EUPL
Location: /usr/local/lib/python2.7/dist-packages
Requires: ndeflib, pyserial, pydes, libusb1

7.nfcpyを利用したソースコードをダウンロード

pi@raspberrypi:~ $ git clone https://github.com/nfcpy/nfcpy.git
Cloning into 'nfcpy'...
remote: Counting objects: 6925, done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 6925 (delta 15), reused 0 (delta 0), pack-reused 6897 Receiving objects: 100% (6925/6925), 6.24 MiB | 2.81 MiB/s, done.
Resolving deltas: 100% (4982/4982), done.
Checking connectivity... done.

8.[tagtool.py]を利用しICカード情報(ID等)を読み取る

tagtool.py実行により待ち受け状態となる。

pi@raspberrypi:~/nfcpy $ sudo python examples/tagtool.py show
[nfc.clf] searching for reader on path usb
[nfc.clf] using SONY RC-S380/P NFC Port-100 v1.11 at usb:001:006
** waiting for a tag **
Type3Tag 'FeliCa Mobile 2.0' ID=012900016E121822 PMM=01138B428FBECBFF SYS=FFFF


pi@raspberrypi:~/nfcpy $ sudo python examples/tagtool.py show
[nfc.clf] searching for reader on path usb
[nfc.clf] using SONY RC-S380/P NFC Port-100 v1.11 at usb:001:006
** waiting for a tag **
Type3Tag 'FeliCa Standard (RC-S915)' ID=01010212080A9C15 PMM=04014B024F4993FF SYS=0003

2.今後の課題

  ◎ 明細データの読み込み
  ◎ 読み込み時のランプ点灯および音声出力