Updating BlueZ on Raspberry Pi (5.23 to 5.43)


Update (Jul 9, 2019):
Now, Raspbian Buster, released on 6/20/2019, has bluez 5.50 by default!


Update (Feb 14, 2018):
If you want to install newer BlueZ on Raspbian Stretch, please see the post below:
Updating BlueZ on Raspberry Pi (5.43 to 5.48)


Update (Sep 8, 2017):
Raspbian Stretch was released on 8/16/2017, and it has BlueZ 5.43 pre-installed. So these steps below won’t be necessary if you are using Stretch.  With pre-installed BlueZ 5.43, the on-board Bluetooth chip on Raspberry Pi 3 is working fine so far.


 

BlueZ is an open source Bluetooth stack for Linux. This is how I updated BlueZ on my Raspberry Pi 3 B+ from 5.23 (pre-installed version in Jessie) to 5.43. The motivation is that I wanted to test a Bluetooth Low Energy (BLE) feature and that is not supported in the original version.

Originally, I tried to update to 5.46 which is the latest version as of 7/27/2017. However, I found that hci tools have been not included in BlueZ since 5.44 for some reason. Since I wanted to use hci tools, I decided to update to 5.43, which still has hci tools.

Also, I should mention one more thing here. After update, I’ve been facing a problem with Raspberry Pi 3’s on-board Bluetooth module. So I decided to use a USB Bluetooth dongle instead. So if you’re planning to use on-board Bluetooth chip, this post is not probably for you…

 

Here is the list of contents of this post.

Contents
– Assumptions
– Steps
1. Disabling On-board Bluetooth Chip
2. Current Version Check
3. Uninstall Current BlueZ
4. Install BlueZ
5. Bluetooth Service Setting
6. Check If Everything is Fine

Let’s get started.

 

Assumptions
<Hardware>
Raspberry Pi 3 B+ with Bluetooth dongle (Panda Bluetooth 4.0 USB Adapter)

<Software>
– Raspbian OS Jessie
– BlueZ (original version:5.23, target version 5.43)

 

Steps
1. Disabling On-board Bluetooth Chip
1-1. Boot up Raspberry Pi Board. If it’s not set up yet, please refer this post.
1-2. Let’s check if Bluetooth interfaces are recognized.

pi@raspberrypi:~ $ hciconfig -a
hci1:	Type: BR/EDR  Bus: UART
	BD Address: xx:xx:xx:xx:xx:xx  ACL MTU: 1021:8  SCO MTU: 64:1
	UP RUNNING 
	RX bytes:1046 acl:0 sco:0 events:52 errors:0
	TX bytes:2516 acl:0 sco:0 commands:52 errors:0
	Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH SNIFF 
	Link mode: SLAVE ACCEPT 
	Name: 'raspberrypi'
	Class: 0x000000
	Service Classes: Unspecified
	Device Class: Miscellaneous, 
	HCI Version: 4.1 (0x7)  Revision: 0xb6
	LMP Version: 4.1 (0x7)  Subversion: 0x2209
	Manufacturer: Broadcom Corporation (15)

hci0:	Type: BR/EDR  Bus: USB
	BD Address: yy:yy:yy:yy:yy:yy  ACL MTU: 310:10  SCO MTU: 64:8
	UP RUNNING 
	RX bytes:947 acl:0 sco:0 events:49 errors:0
	TX bytes:2446 acl:0 sco:0 commands:49 errors:0
	Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH HOLD SNIFF PARK 
	Link mode: SLAVE ACCEPT 
	Name: 'raspberrypi #1'
	Class: 0x000000
	Service Classes: Unspecified
	Device Class: Miscellaneous, 
	HCI Version: 4.0 (0x6)  Revision: 0x22bb
	LMP Version: 4.0 (0x6)  Subversion: 0x22bb
	Manufacturer: Cambridge Silicon Radio (10)

It looks both on-board chip and the dongle are recognized correctly. In this case, hci1 is the on-board chip (Broadcom) and hci0 is the dongle (CSR).
(* BD Addresses are replaced with “xx:xx:xx:xx:xx:xx” and “yy:yy:yy:yy:yy:yy”)

1-3. Since I don’t use the on-board BT chip, let’s disable it. Open “/etc/modprobe.d/raspi-blacklist.conf”,

sudo nano /etc/modprobe.d/raspi-blacklist.conf

1-4. Add two lines below and save.

blacklist btbcm
blacklist hci_uart

1-5. Then reboot Raspberry Pi 3.

sudo reboot

1-7. After reboot, type ‘hciconfig -a’ again.

pi@raspberrypi:~ $ hciconfig -a
hci0: Type: BR/EDR Bus: USB
 BD Address: yy:yy:yy:yy:yy:yy ACL MTU: 310:10 SCO MTU: 64:8
 UP RUNNING 
 RX bytes:670 acl:0 sco:0 events:46 errors:0
 TX bytes:2437 acl:0 sco:0 commands:46 errors:0
 Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87
 Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
 Link policy: RSWITCH HOLD SNIFF PARK 
 Link mode: SLAVE ACCEPT 
 Name: 'raspberrypi'
 Class: 0x000000
 Service Classes: Unspecified
 Device Class: Miscellaneous, 
 HCI Version: 4.0 (0x6) Revision: 0x22bb
 LMP Version: 4.0 (0x6) Subversion: 0x22bb
 Manufacturer: Cambridge Silicon Radio (10)

The on-board chip is successfully disabled.

 

2. Current Version Check
2-1. BlueZ version can be retrieved by typing:

pi@raspberrypi:~ $ bluetoothctl -v
5.23 

2-2. Also, let’s check the Bluetooth related packages.

pi@raspberrypi:~ $ dpkg -l|grep blue
ii  bluej                                 3.1.7b                                    all          A simple but powerful Java IDE.
ii  bluez                                 5.23-2+rpi2                               armhf        Bluetooth tools and daemons
ii  bluez-firmware                        1.2-3+rpi1                                all          Firmware for Bluetooth devices
ii  libbluetooth3:armhf                   5.23-2+rpi2                               armhf        Library to use the BlueZ Linux Bluetooth stack
ii  pi-bluetooth                          0.1.3                                     armhf        Raspberry Pi 3 bluetooth
ii  pulseaudio-module-bluetooth           5.0-13                                    armhf        Bluetooth module for PulseAudio sound server
pi@raspberrypi:~ $ 

 

3. Uninstall Current BlueZ
3-1. Uninstall the current version of BlueZ.

sudo apt-get purge bluez -y

3-2. Remove unnecessary packages.

sudo apt-get autoremove -y

After uninstallation, the package list looks like this. (not sure why libbluetooth3 is still there…)

pi@raspberrypi:~/src/bluez $ bluetoothctl --version
-bash: /usr/bin/bluetoothctl: No such file or directory
pi@raspberrypi:~/src/bluez $ dpkg -l|grep blue
ii  bluej                                 3.1.7b                                    all          A simple but powerful Java IDE.
ii  libbluetooth3:armhf                   5.23-2+rpi2                               armhf        Library to use the BlueZ Linux Bluetooth stack

 

4. Install BlueZ
4-1. Update package list and installed packages.

sudo apt-get update && sudo apt-get upgrade -y

4-2. Install dependencies.

sudo apt-get install -y libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev

4-3. Download and extract BlueZ 5.43.

wget www.kernel.org/pub/linux/bluetooth/bluez-5.43.tar.xz
tar xvf bluez-5.43.tar.xz
cd bluez-5.43/

4-4. Configure.

./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var --enable-experimental --enable-tools --with-systemdsystemunitdir=/lib/systemd/system --with-systemduserunitdir=/usr/lib/system

4-5. Compile the source code.

make -j4

4-6. Install BlueZ.

sudo checkinstall --fstrans=no

You can ‘sudo make install’ instead of ‘sudo checkinstall’ as below:

sudo make install

4-7. Check the version if the installation is successfully done.

pi@raspberrypi:~ $ bluetoothctl -v
5.43

 

5. Bluetooth Service Setting
5-1. Enable Bluetooth service so that it will start on boot up.

sudo systemctl enable bluetooth

It’ll create symlinks and output like below:

pi@raspberrypi:~/src/bluez/bluez-5.43 $ sudo systemctl enable bluetooth
Created symlink from /etc/systemd/system/dbus-org.bluez.service to /lib/systemd/system/bluetooth.service.
Created symlink from /etc/systemd/system/bluetooth.target.wants/bluetooth.service to /lib/systemd/system/bluetooth.service.

5-2. Reboot Raspberry Pi 3.

sudo reboot

 

6. Check If Everything is Fine
6-1. After reboot, check if hci is UP.

pi@raspberrypi:~ $ hciconfig -a
hci0:	Type: Primary  Bus: USB
	BD Address: yy:yy:yy:yy:yy:yy  ACL MTU: 310:10  SCO MTU: 64:8
	DOWN 
	RX bytes:574 acl:0 sco:0 events:30 errors:0
	TX bytes:368 acl:0 sco:0 commands:30 errors:0
	Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH HOLD SNIFF PARK 
	Link mode: SLAVE ACCEPT

6-2. If it’s DOWN, then type:

sudo hciconfig hci0 up

6-3. And check again.

pi@raspberrypi:~ $ hciconfig -a
hci0:	Type: Primary  Bus: USB
	BD Address: yy:yy:yy:yy:yy:yy  ACL MTU: 310:10  SCO MTU: 64:8
	UP RUNNING 
	RX bytes:1178 acl:0 sco:0 events:65 errors:0
	TX bytes:1066 acl:0 sco:0 commands:65 errors:0
	Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH HOLD SNIFF PARK 
	Link mode: SLAVE ACCEPT 
	Name: 'raspberrypi'
	Class: 0x000000
	Service Classes: Unspecified
	Device Class: Miscellaneous, 
	HCI Version: 4.0 (0x6)  Revision: 0x22bb
	LMP Version: 4.0 (0x6)  Subversion: 0x22bb
	Manufacturer: Cambridge Silicon Radio (10)

Now it should be UP and RUNNING.
* If you want Bluetooth adapter powered up automatically at boot, see this.

6-4. Check if Bluetooth service is working.

systemctl status bluetooth

If everything is fine, you should see like:

pi@raspberrypi:~ $ systemctl status bluetooth
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled)
   Active: active (running) since Fri 2017-07-28 00:34:23 UTC; 2min 14s ago
     Docs: man:bluetoothd(8)
 Main PID: 456 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           └─456 /usr/libexec/bluetooth/bluetoothd

Make sure it’s ‘active (running)’.

6-5. Now you should be able to use bluetoothctl to pair devices.

pi@raspberrypi:~ $ bluetoothctl
[NEW] Controller yy:yy:yy:yy:yy:yy raspberrypi [default]
[bluetooth]#

 

 

Sponsor Link

One Comment

  1. Can you please explain to me in simpler terms what BlueZ 5.44 is and can do. I have a Bluetooth scanner (Gizmo finder…scans for Bluetooth devices) and this always shows up. I am completely I the dark as to this. Should I be concerned at all? If you could shoot me a quick email I’d appreciate it. I also noticed my phone was paired with a Yamaha ya-11 at home. I have no idea how or if that is something to worry about since I don’t have this device (not BlueZ 5.44. Any help would really be appreciated! Thanks! -Todd

Comments are closed.