RaspberryPi
bluetooth
IoT

raspberry pi3 で bluetooth スピーカーに接続する

More than 1 year has passed since last update.

ゴール
Raspberry Pi3 から SoundLink Revolve Plus Bluetooth® Speaker に接続する。

Bluetooth関連のパッケージをインストール

bluemanはGUIのBluetoothマネージャーアプリらしい(へー

pi@raspberrypi:~ $ sudo apt-get install pi-bluetooth blueman
 :
Do you want to continue? [Y/n] Y
 :
Fetched 66.5 MB in 2min 31s (440 kB/s)
E: Failed to fetch http://mirrordirector.raspbian.org/raspbian/pool/main/g/graphite2/libgraphite2-3_1.3.6-1~deb8u1_armhf.deb  404  Not Found [IP: 93.93.128.193 80]

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

apt-get を update しろって出た

pi@raspberrypi:~ $ sudo apt-get update
 :
 Fetched 9,927 kB in 53s (185 kB/s)
Reading package lists... Done

再チャレンジ

pi@raspberrypi:~ $ sudo apt-get install pi-bluetooth blueman
 :
Do you want to continue? [Y/n] Y
 :
Processing triggers for systemd (215-17+deb8u7) ...

めちゃ時間がかかる...(20~30minくらい?

サウンド周りのパッケージをインストール

pi@raspberrypi:~ $ sudo apt-get install pulseaudio pavucontrol pulseaudio-module-bluetooth
 :
Do you want to continue? [Y/n] Y
 :
Processing triggers for dbus (1.8.20-0+deb8u1) ...
  • pulseaudio ... サウンドサーバ
  • pavucontrol ... PulseAudioの音量などを調整するもの
  • pulseaudio-module-bluetooth ... PulseAudioのbluetoothモジュール

Raspberry Piを再起動する

Bluetooth関連はパッケージをインストールしたあとは一回再起動したほうが良いらしい。

pi@raspberrypi:~ $ sudo reboot

Broadcast message from pi@raspberrypi on pts/0 (Sun 2017-07-02 23:20:23 JST):

The system is going down for reboot NOW!

pi@raspberrypi:~ $ Connection to raspberrypi.local closed by remote host.
Connection to raspberrypi.local closed.

Bluetoothスピーカーの接続

Bluetooth設定する前に、pulseaudioを立ち上げておく

pi@raspberrypi:~ $ pulseaudio -D

立ち上がるのも、時間がかかる...
次に、bluetoothctlを使って設定する

pi@raspberrypi:~ $ bluetoothctl
[NEW] Controller B8:27:EB:DE:7F:EF raspberrypi [default]
[NEW] Device 04:52:C7:B2:19:F5 Bose Revolve+ SoundLink
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# agent on
Agent registered
[bluetooth]# pair 04:52:C7:B2:19:F5
Attempting to pair with 04:52:C7:B2:19:F5
Pairing successful
[bluetooth]# trust 04:52:C7:B2:19:F5
Changing 04:52:C7:B2:19:F5 trust succeeded
[bluetooth]# connect 04:52:C7:B2:19:F5
Attempting to connect to 04:52:C7:B2:19:F5
Connection successful
[bluetooth]# quit
Agent unregistered
[DEL] Controller B8:27:EB:DE:7F:EF raspberrypi [default]
  • bluetoothctl ... 対話型の設定ツール

もし bluetooth デバイスが見つからない場合は次のコマンドを実行

[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:DE:7F:EF Discovering: yes
[NEW] Device 2C:B4:3A:0C:AD:75 2C-B4-3A-0C-AD-75
[NEW] Device 04:52:C7:B2:19:F5 LE-Bose Revolve+ SoundLink
 :

bluetooth スピーカーに接続できたかチェック

pi@raspberrypi:~ $ speaker-test -t wav

speaker-test 1.0.28

Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
WAV file(s)
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 192 to 2097152
Period size range from 64 to 699051
Using max buffer size 2097152
Periods = 4
was set period_size = 524288
was set buffer_size = 2097152
 0 - Front Left
Time per period = 1.484907
 :

音が流ればcompleted.