🪪

Raspberry PiでRC-S330を使いたかったメモ

に公開

使ったもの

  • Raspberry Pi Zero W
  • SONY RC-S330

Raspberry Piのセットアップ

ここではPythonのライブラリであるnfcpyを使うので公式ドキュメントに従ってインストールします。

libusb をインストールする

Raspberry Piでは標準で入っているのでスキップします。

Pythonをインストールする

Raspberry Pi OSにはPython3が標準で入っているはずですが、一応確認してください。

bash
~$ python3 --version

インストールされていない場合はバージョンが出ないのでインストールしてください。

bash
#インストールされていない場合のみ
~$ sudo apt update
~$ sudo apt install python3 -y

pipをインストールする

python3が入っていればpipもあるはずですが、なぜかインストールされていない時もあるので一応、pipの確認もします。

bash
~$ pip --version

もちろんここでバージョンが出てこない場合はインストールされていないのでインストールします。

bash
#インストールされていない場合のみ
~$ sudo apt update
~$ sudo apt install python3-pip

事情により、再インストールをしたい場合は以下のコマンドでできます。

bash
~$ python -m pip install --upgrade --force-reinstall pip

nfcpyをインストールする

Pythonとpipが入れられればnfcpyをインストールできます。

bash
~$ pip install -U nfcpy

問題なくインストールできたか試してみます。

bash
~$ python -m nfc
This is the 1.0.4 version of nfcpy run in Python 3.9.2
on Linux-6.1.21+-armv6l-with-glibc2.31
I'm now searching your system for contactless devices
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

デバイスが見つからないといわれているのでRC-S330をUSBに差し込んでみます。

bash
#USBでRC-330を差し込み後
~$ python -m nfc
This is the 1.0.4 version of nfcpy run in Python 3.9.2
on Linux-6.1.21+-armv6l-with-glibc2.31
I'm now searching your system for contactless devices
** found usb:054c:02e1 at usb:001:007 but access is denied
-- the device is owned by 'root' but you are 'user'
-- 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}==\"02e1\", 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

デバイスのアクセス権限がrootであるためuserの権限ではアクセスできないといわれてしまいました。
そこでこのコマンドを入力してデバイスを再接続しろと言われているのでやってみます。

bash
~$ sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"054c\", ATTRS{idProduct}==\"02e1\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules'
~$ sudo udevadm control -R # then re-attach device

終わったのでUSBを抜き差しします。

bash
#抜き差し後
~ $ python -m nfc
This is the 1.0.4 version of nfcpy run in Python 3.9.2
on Linux-6.1.21+-armv6l-with-glibc2.31
I'm now searching your system for contactless devices
ERROR:nfc.clf.rcs956:input/output error while waiting for ack
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

ERROR:nfc.clf.rcs956という謎のエラーが出てしまいました。
詳細なデバッグを確認します。

bash
~ $ python -m nfc --search-tty --verbose -v -v -v
This is the 1.0.4 version of nfcpy run in Python 3.9.2
on Linux-6.1.21+-armv6l-with-glibc2.31
I'm now searching your system for contactless devices
DEBUG:nfc.clf.transport:using libusb-1.0.24
DEBUG:nfc.clf.transport:path matches '^(usb|)$'
INFO:nfc.clf:searching for reader on path usb:001:009
DEBUG:nfc.clf.transport:using libusb-1.0.24
DEBUG:nfc.clf.transport:path matches '^usb(:[0-9]{1,3})(:[0-9]{1,3})?$'
DEBUG:nfc.clf.device:loading rcs956 driver for usb:054c:02e1
#中略
ERROR:nfc.clf.rcs956:input/output error while waiting for ack
DEBUG:nfc.clf.device:[Errno 5] Input/output error
DEBUG:nfc.clf.transport:^(tty(S|ACM|AMA|USB)\d+|cu\.usbserial.*)$
DEBUG:nfc.clf.transport:check: /dev/ttyAMA0
DEBUG:nfc.clf.transport:avail: /dev/ttyAMA0
INFO:nfc.clf:searching for reader on path tty:AMA0
DEBUG:nfc.clf.transport:^ttyAMA0$
DEBUG:nfc.clf.transport:check: /dev/ttyAMA0
DEBUG:nfc.clf.transport:avail: /dev/ttyAMA0
DEBUG:nfc.clf.device:trying arygon on /dev/ttyAMA0

ctrl+cを押して強制的に抜け出します。

nfcpyの不具合?

どうやらnfcpy側の問題でarmv6系統ではRC-S330の動作ができないようです。
github issueで質問してみましたがいつになったら返信が来るのかわからないのでいったん保留にします。
後日RC-S380で試してみたいと思います。

Discussion