WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Howto: RPi3 built-in bluetooth  (Read 291 times)

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 9061
Howto: RPi3 built-in bluetooth
« on: March 15, 2017, 12:24:04 AM »
Enable bluetooth in the RPi3 config:
Code: [Select]
$ cat /mnt/mmcblk0p1/config.txt | grep -i pi3
[PI3]
#dtoverlay=pi3-disable-bt
#dtoverlay=pi3-miniuart-bt
..and reboot. Note that the mini-uart is now routed to GPIO14/15 and the PL011 UART is now used for bluetooth communications.

Load the required extensions and modules:
Code: [Select]
$ tce-load -i firmware-rpi3-bt bluez
$ sudo modprobe hci_uart

$ lsmod
Module                  Size  Used by    Not tainted
hci_uart               19088  0
btbcm                   6309  1 hci_uart
bluetooth             338146  2 hci_uart,btbcm
...

$ dmesg
...
[  479.835339] Bluetooth: Core ver 2.21
[  479.835665] NET: Registered protocol family 31
[  479.835677] Bluetooth: HCI device and connection manager initialized
[  479.835857] Bluetooth: HCI socket layer initialized
[  479.835877] Bluetooth: L2CAP socket layer initialized
[  479.835915] Bluetooth: SCO socket layer initialized
[  479.839214] Bluetooth: HCI UART driver ver 2.3
[  479.839234] Bluetooth: HCI UART protocol H4 registered
[  479.839244] Bluetooth: HCI UART protocol Three-wire (H5) registered
[  479.839429] Bluetooth: HCI UART protocol BCM registered

Start the bluetooth daemon in debug mode to be able to see what is going on (the bluez init.d script can also be used):
Code: [Select]
$ sudo /usr/local/etc/init.d/dbus start
$ sudo /usr/local/lib/bluetooth/bluetoothd -nd
bluetoothd[2829]: Bluetooth daemon 5.43
...
bluetoothd[2829]: src/adapter.c:read_index_list_complete() Number of controllers: 0

Open a second terminal window and start the command interface:
Code: [Select]
$ hciattach /dev/ttyAMA0 bcm43xx 921600 noflow
bcm43xx_init
Flash firmware /usr/local/lib/firmware/brcm/BCM43430A1.hcd
Set Controller UART speed to 921600 bit/s
Device setup complete

$ bluetoothctl -a
[NEW] Controller B8:27:EB:D3:66:A9 Rpi [default]
Agent registered
[bluetooth]#

Power on bluetooth, search for availaable devices and pair:
Code: [Select]
[bluetooth]# power on
Changing power on succeeded
[CHG] Controller B8:27:EB:D3:66:A9 Powered: yes
[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller B8:27:EB:D3:66:A9 Discoverable: yes
[bluetooth]# pairable on
Changing pairable on succeeded
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:D3:66:A9 Discovering: yes
[NEW] Device 00:1B:66:00:31:88 Sennheiser P
[CHG] Device 00:1B:66:00:31:88 Name: Sennheiser PXC310BT
[CHG] Device 00:1B:66:00:31:88 Alias: Sennheiser PXC310BT
[bluetooth]# pair 00:1B:66:00:31:88
Attempting to pair with 00:1B:66:00:31:88
[CHG] Device 00:1B:66:00:31:88 Connected: yes
[CHG] Device 00:1B:66:00:31:88 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1B:66:00:31:88 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1B:66:00:31:88 ServicesResolved: yes
[CHG] Device 00:1B:66:00:31:88 Paired: yes
Pairing successful
[CHG] Device 00:1B:66:00:31:88 ServicesResolved: no
[CHG] Device 00:1B:66:00:31:88 Connected: no
..note a pairing PIN will be requested where appropriate.
« Last Edit: March 15, 2017, 12:27:12 AM by Juanito »

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 9061
Re: Howto: RPi3 built-in bluetooth
« Reply #1 on: March 19, 2017, 10:49:51 PM »
To use the RPi3 with bluetooth headphones:

Load the pavucontrol extension, start bluetooth as explained above and then start pulseaudio by opening pavucontrol.

In the bluetooth command interface, issue the following command:
Code: [Select]
[bluetooth]# connect 00:1B:66:00:31:88
Attempting to connect to 00:1B:66:00:31:88
[CHG] Device 00:1B:66:00:31:88 Connected: yes
Connection successful
[CHG] Device 00:1B:66:00:31:88 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1B:66:00:31:88 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1B:66:00:31:88 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1B:66:00:31:88 ServicesResolved: yes
..this will set the bluetooth headphones as an a2dp sink and the bluetooth headphones will appear as an available output in pavucontrol.

You can play music to the headphones using the xmms-pulse extension (use <ctrl-p> to access the configuration menu and choose the pulseaudio output plugin). Note that you may need to use pavucontrol to switch the output stream from the 3.5mm jack to bluetooth.

Optionally the blueman extension can be used to pair and set the headphones as an audio sink.

The issue now is that the music pauses every few seconds for the RPi3 to catch up  :(