LoginSignup
19

More than 5 years have passed since last update.

Raspberry Pi 3 Raspbian でUSB NFCリーダーライターを使ってみる

Last updated at Posted at 2016-07-01

はじめに

RaspbianではじめてUSB NFCカードリーダーを使ったときの記録です。ほぼnfcpyのサイトにある手順です。ちなみに楽天Edyのためにもともと持っていたRC-S360はこの手順では動きませんでした。

ハードウェア

  • Raspberry Pi 3
  • RC-S380/P

ソフトウェア

  • Raspbian
  • libusb1
  • pyserial
  • Python 2.7.11
    • NFCPY

作業

Raspberry にログインしてください。

Pythonパッケージの追加

$ pip install libusb1 pyserial

nfcpyを取得

$ sudo apt-get install bzr
$ bzr branch lp:nfcpy trunk

bzrはnfcpyのリポジトリからファイル一式を取得するツール
trunkフォルダにnfcpy一式が保存されます。

exampleの実行

NFCタグをかざして実行してみた

$ cd trunk
$ 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:004
** waiting for a tag **
Type2Tag 'NXP NTAG203' ID=04E4ED72773480
NDEF Capabilities:
  readable  = yes
  writeable = yes
  capacity  = 137 byte
  message   = 0 byte

sudo なしで実行させる設定

sudoなしで実行させてみるとエラーになります。

$ cd trunk
$ examples/tagtool.py show
[nfc.clf] searching for reader on path usb
[nfc.clf] no reader available on path usb
[main] no contactless reader found on usb
[main] no contactless reader available

lsusbでusbのDevice情報を見る。「ID 054c:06c3 Sony Corp」がRC-380/Pのようだ

$ lsusb
Bus 001 Device 004: ID 054c:06c3 Sony 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

--deviceオプションで情報を見ると 最後から2行目に実行するコマンドが表示されている。nfcdev.rulesファイルに情報を付加すればよいらしい。コピペして実行してみる。

$ examples/tagtool.py --device usb:054c:06c3
[nfc.clf] searching for reader on path usb:054c:06c3
[main] access denied for device with path usb:054c:06c3
[main] first match for path usb:054c:06c3 is usb:001:004
[main] usb:001:004 is owned by root but you are pi
[main] members of the root group may use usb:001:004
[main] you may want to add a udev rule to access this device
[main] sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"054c\", ATTRS{idProduct}==\"06c3\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules'
[main] no contactless reader available

コピペして実行してみる。

$ sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"054c\", ATTRS{idProduct}==\"06c3\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules'

そして実行、あれ、変わらない。

$ examples/tagtool.py show
[nfc.clf] searching for reader on path usb
[nfc.clf] no reader available on path usb
[main] no contactless reader found on usb
[main] no contactless reader available

rebootしてからもう一度.. 成功しました。

$ 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:004
** waiting for a tag **
Type2Tag 'NXP NTAG203' ID=04E4ED72773480
NDEF Capabilities:
  readable  = yes
  writeable = yes
  capacity  = 137 byte
  message   = 0 byte

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19