初めに
タイトル通り
raspberry pi 4B
buster 32bit
$ uname -a
Linux chirimen 5.10.52-v7l+ #1441 SMP Tue Aug 3 18:11:56 BST 2021 armv7l GNU/Linux
ドライバインストール
sudo pip3 install pyPS4Controller
sudo pip3 install ds4drv
Bluetooth接続
bluetoothctl
Agent registered
[bluetooth]# power on
Changing power on succeeded
Share + PS長押しでペアリングモード(白フラッシュ)
[bluetooth]# scan on
Discovery started
[CHG] Controller AA:AA:AA:AA:AA:AA Discovering: yes
[CHG] Device 00:22:68:F1:59:7F RSSI: -22
トラストする
[bluetooth]# trust 00:22:68:F1:59:7F
[CHG] Device 00:22:68:F1:59:7F Trusted: yes
Changing 00:22:68:F1:59:7F trust succeeded
ペアリングする
[bluetooth]# pair 00:22:68:F1:59:7F
Attempting to pair with 00:22:68:F1:59:7F
[CHG] Device 00:22:68:F1:59:7F UUIDs: 00001124-0000-1000-8000-00805f9b34fb
[CHG] Device 00:22:68:F1:59:7F UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 00:22:68:F1:59:7F ServicesResolved: yes
[CHG] Device 00:22:68:F1:59:7F Paired: yes
Pairing successful
接続確認
一度終了してもう一度たちあげ
コントローラは電源を入れると接続モード(白点滅)
[bluetooth]# exit
$ bluetoothctl
[bluetooth]# power on
[CHG] Controller AA:AA:AA:AA:AA:AA Class: 0x000c0000
Changing power on succeeded
[CHG] Controller AA:AA:AA:AA:AA:AA Powered: yes
[CHG] Device 00:1F:E2:8B:32:9C Connected: yes
[Wireless Controller]#
テスト
from pyPS4Controller.controller import Controller
class MyController(Controller):
def __init__(self, **kwargs):
Controller.__init__(self, **kwargs)
controller = MyController(interface="/dev/input/js0", connecting_using_ds4drv=False)
controller.listen()
コネクトしてから上記テストコードを実行
参考
https://hellobreak.net/raspberry-pi-ps4-controller-0326/
https://hotsmmrblog.com/get-key-event-with-ds4drv/