raspberry pi をつかってNFCタグを読んでみたいと思っていたら
nfcpyという便利そうなものを見つけたので導入してみた。
まずはインストール
1 2 |
#インストール $ pip3 install nfcpy |
1 |
$ git clone https://github.com/nfcpy/nfcpy.git |
いろいろ設定する
1 2 3 |
# ソニーのリーダーがラズパイに接続されていることを確認 $ lssub Bus 001 Device 006: ID 054c:06c3 Sony Corp. RC-S380 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ python3 -m nfc This is the 1.0.3 version of nfcpy run in Python 3.7.3 on Linux-4.19.75-v7+-armv7l-with-debian-10.1 I'm now searching your system for contactless devices ** found usb:054c:06c3 at usb:001:004 but access is denied -- the device is owned by 'root' but you are 'admin' -- also members of the 'root' group would be permitted -- you could use 'sudo' but this is not recommended -- better assign the device to the 'plugdev' group sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"054c\", ATTRS{idProduct}==\"06c3\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules' sudo udevadm control -R # then re-attach device I'm not trying serial devices because you haven't told me -- add the option '--search-tty' to have me looking -- but beware that this may break other serial devs Sorry, but I couldn't find any contactless device |
上記のメッセージの指示に従う。
恐らくsudo権限じゃなくても実行できるようにしている。
1 2 3 4 5 |
# 1つ目 $ sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"054c\", ATTRS{idProduct}==\"06c3\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules' # 2つ目 $ sudo udevadm control -R # then re-attach device |
一旦再起動する。
1 |
$ sudo reboot now |
再度入力すると表示が変更されている。
1 2 3 4 5 6 7 8 9 |
$ sudo python3 -m nfc This is the 1.0.3 version of nfcpy run in Python 3.7.3 on Linux-4.19.75-v7+-armv7l-with-debian-10.1 I'm now searching your system for contactless devices ** found SONY RC-S380/P NFC Port-100 v1.11 at usb:001:004 I'm not trying serial devices because you haven't told me -- add the option '--search-tty' to have me looking -- but beware that this may break other serial devs |
読み込み実行
ディレクトリを移動してサンプルファイルを実行してみる。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#ディレクトリの移動 $ cd nfcpy/ $ cd examples/ $ ls __init__.py cli.py listen.py llcp-test-client.py phdc-test-manager.py snep-test-client.py __pycache__ handover-test-client.py llcp-dta-iut.py llcp-test-server.py rfstate.py snep-test-server.py beam.py handover-test-server.py llcp-dta-test.py phdc-test-agent.py sense.py tagtool.py #pyファイルの実行 $ python3 tagtool.py Traceback (most recent call last): File "tagtool.py", line 29, in <module> import ndef ImportError: No module named ndef |
あら?エラー発生。
そーいえばnfcpyはpython2に対応しているらしいので
念のためインストールしておく。
1 2 3 |
$ sudo pip install nfcpy $ sudo reboot now |
再度読み込み実行!
ディレクトリを変更して実行すると。。。
1 2 3 4 5 6 7 |
$ cd nfcpy/ $ cd examples/ $ python3 tagtool.py [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 ** Type3Tag 'FeliCa Lite-S (RC-S966)' ID=***** PMM=***** SYS=*** |
無事読み込みできた。次は書き込みするプログラムを書いてみようっと.
コメントを残す