ひゃまだのblog

ひゃまだ(id:hymd3a)の趣味のブログ

Debian 12(Bookworm)で、Bluetooth USBアダプタ(UB500)を接続してワイヤレスヘッドホンをつなぐ

(2024-04-03 初稿)

過去に何度もBluetooth接続で、スピーカーやマウスをつないだけど、接続方法をすぐに忘れてしまうのでメモを残す。

今回は、デスクトップのDebianに有線接続でヘッドホンをつないでいたんだけど、少しケーブルが短かったため、ヘッドホンを付けたまま自由な姿勢がとれるようにBluetooth接続のワイヤレスヘッドホンをつなぐことを目的とした。

まずは、筆者の環境を確認。

$ cat /etc/debian_version 
12.5
$ uname -a
Linux hoge 6.1.0-18-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 (2024-02-01) x86_64 GNU/Linux

今回は、以下のサイトを参考にさせていただいた。多謝。m(__)m

デスクトップPCにはBluetoothアダプタが付いていなかったので、以下のUB500というBluetooth USBアダプタを購入した。

上記USB500をデスクトップPCに挿し込んでから、lsusbで確認。

$ lsusb
(前略)
Bus 001 Device 003: ID 2357:0604 TP-Link TP-Link UB500 Adapter
(後略)

ちゃんと認識しているよう。

今回接続するのは、骨伝導のワイヤレスヘッドホンでというもの。

以下のリンクよりも古い型なので、少し形状が異なるけど…

参考にしたサイトにあるとおり、Bluetooth関連のパッケージをインストールして、起動時から使えるように。

$ sudo apt update
$ sudo apt install bluetooth bluez bluez-tools rfkill
$ sudo systemctl start bluetooth
$ sudo systemctl enable bluetooth

以下のコマンドで、Bluetoothのstatusを確認。

$ sudo systemctl status bluetoothbluetooth.service - Bluetooth service<
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; preset: en>
     Active: active (running) since Sat 2024-03-30 15:10:32 JST; 1min 14s ago
       Docs: man:bluetoothd(8)
   Main PID: 685 (bluetoothd)
     Status: "Running"
      Tasks: 1 (limit: 19037)
     Memory: 3.3M
        CPU: 28ms
     CGroup: /system.slice/bluetooth.service
             └─685 /usr/libexec/bluetooth/bluetoothdr

rfkillのリストに入っていないことを確認。

$ rfkill list

bluetoothctlコマンドで、scanしてペアリングする。

$ bluetoothctl
[bluetooth]# scan on [NEW] Device EB:06:EF:66:A9:E1 X 11

X11のヘッドホンが見つかれば、スキャンは成功。

つづけて、bluetoothctlコマンドの中で、ペアリング。

# pair EB:06:EF:66:A9:E1
Attempting to pair with EB:06:EF:66:A9:E1

たぶんペアリングは問題なく終了すると思われる。

問題は、次のコネクト。筆者の場合は、bluetoothを再起動したりして、何度かチャレンジする中で、以下のとおり接続に成功した。

# connect EB:06:EF:66:A9:E1
Attempting to connect to EB:06:EF:66:A9:E1
[CHG] Device EB:06:EF:66:A9:E1 Connected: yes
[NEW] Endpoint /org/bluez/hci0/dev_EB_06_EF_66_A9_E1/sep8 
[NEW] Endpoint /org/bluez/hci0/dev_EB_06_EF_66_A9_E1/sep6 
[NEW] Endpoint /org/bluez/hci0/dev_EB_06_EF_66_A9_E1/sep5 
[NEW] Endpoint /org/bluez/hci0/dev_EB_06_EF_66_A9_E1/sep3 
[NEW] Endpoint /org/bluez/hci0/dev_EB_06_EF_66_A9_E1/sep1 
[NEW] Transport /org/bluez/hci0/dev_EB_06_EF_66_A9_E1/sep5/fd0 
Connection successful
[CHG] Transport /org/bluez/hci0/dev_EB_06_EF_66_A9_E1/sep5/fd0 State: active
[CHG] Transport /org/bluez/hci0/dev_EB_06_EF_66_A9_E1/sep5/fd0 Volume: 0x0050 (80)
[CHG] Device EB:06:EF:66:A9:E1 ServicesResolved: yes
[CHG] Transport /org/bluez/hci0/dev_EB_06_EF_66_A9_E1/sep5/fd0 State: idle

接続に成功したら、exitコマンドでbluetoothctlコマンドを抜ける。

# exit

毎回、Bluetoothctlコマンドを叩くのは大変なので、以下のスクリプトを利用すると良い。

$ cat bin/blule-connect
#/usr/bin/env bash
# bluetooth connect
bluetoothctl << EOC
connect EB:06:EF:66:A9:E1
quit
EOC

それでもコマンドを叩くのはちょっとという方は、以下のGUIをインストールすると良い。

筆者の場合、LXDEを使っているので、以下のとおり。

$sudo apt-get install blueman

gnome-bluetooth (for GNOME)

$ sudo apt install gnome-bluetooth

bluedevil (for KDE)

$ apt install bluedevil

bluemanをインストールした状態は、以下のとおり。

BluemanでX11の状態を確認

以上、他の方の参考になれば幸い。

関連ページ