【Raspberry Pi】 Wiiリモコンを繋げる

Python3とcwiidを利用してWiiリモコンをRaspberryPiで
認識させれたのでメモ。

f:id:Yoshichi:20170921014301j:plain

使用したもの

  • RaspberryPi2 (そろそろ3ほすぃ)
  • I-O DATA Bluetoothアダプター Class 2対応 4.0+EDR/LE対応 USBアダプター USB-BT40LE
  • Wiiリモコン

cwiidのインストール

pipではインストールできなかったので。

https://github.com/azzra/python3-wiimote
上記サイトからクローンしてきます。

必要なものが
awk, bison, flex, bluez-libs, python 3.5以上
と指定があるので、それぞれ不足しているものをインストールしていきます。
また、僕の環境ではaclocalがなかったのでautotools-devでインストールします。

sudo apt-get install autotools-dev
sudo apt-get install bison
sudo apt-get install flex
sudo apt-get libcwiid-dev
sudo apt-get install bluetooth
sudo apt-get install bluez-utils

一通り、インストールしたらクローンでとってきたディレクトリ内で
下記コマンドを打つのみ。

sudo aclocal
sudo autoconf
sudo ./configure
sudo make install

何か不足していたら./configureを実行した際に
エラーメッセージの内容を読んだら気づけるかも。

実行

  1 import cwiid
  2 import time
  3
  4 wii = cwiid.Wiimote()
  5 time.sleep(3)
  6 wii.rpt_mode = cwiid.RPT_BTN
  7 while True:
  8     buttons = wii.state['buttons']
  9     print(buttons)

を実行する

Wiiリモコンのsyncボタンを押して10秒経たないぐらい待つと
認識されて、ボタンに対応した値が返ってくる。

f:id:Yoshichi:20170921015449j:plain

サンプルはこの辺を参考にするとよい。

Wiimote/wiimote.py at master · the-raspberry-pi-guy/Wiimote · GitHub