Bluetooth関係のパッケージのインストールをします
$ sudo apt-get install pi-bluetooth blueman
サウンド関係のパッケージをインストールします
$ sudo apt-get install pulseaudio pavucontrol pulseaudio-module-bluetooth
サービスを自動起動するためのふぁいるを作成します。
$ sudo vi /etc/systemd/system/pulseaudio.service
以下の内容で作ります。
[Unit]
Description=Pulse Audio
[Service]
Type=simple
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm
[Install]
WantedBy=multi-user.targetb
bluezのプロファイルの設定を追加します
$ sudo vi /etc/dbus-1/system.d/pulseaudio-bluetooth.conf
以下の内容で作成します。
bluetoothモジュールの読み込み設定を追加します
$ sudo vi /etc/pulse/system.pa
### Automatically load driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
.endif
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif
再起動します。
pulseaudioサービスの起動
$ sudo systemctl start pulseaudio
$ sudo systemctl status pulseaudio
$ sudo systemctl enable pulseaudio
スピーカー(Marsboy)に接続する
$ sudo bluetoothctl
[NEW] Controller B8:27:EB:44:0A:FB raspberrypi [default]
[NEW] Device FC:58:FA:CC:45:9C Marsboy
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# scan on
Discovery started
:
[bluetooth]# pair FF:88:AA:CC:44:99
Attempting to pair with FF:88:AA:CC:44:99
:
[bluetooth]# connect FF:88:AA:CC:44:99
Attempting to connect to FC:58:FA:CC:45:9C
:
Connection successful
[bluetooth]# quit
動作テストします
$ sudo paplay /usr/share/sounds/alsa/Front_Center.wav
スピーカーから音が出れば成功です。
多くのサイトはここで解説は終わりですが、Bluetoothのプロトコルのことを知らないと、毎回上記のコマンドを手動でしないといけないのかと、でも手動で行ってもうまくいきません。
実は、このページに書いてある内容で、以降再起動して自動的に接続できるようになります。
まず、RaspberryPiを起動します。
起動後、少し待ってから、スピーカの電源を入れます。
わたしのスピーカの場合、電源が入ると「ぴぽっ!」と音がします。
さらに待っていると、接続が成功し「ぽっ!」と音がします。
すると音が出るようになります。