Setting up Bluetooth on the Raspberry Pi 3
Blue Wireless on the RPi3
The Raspbian image from 03.18.2016 serves as the basis for this article. This "jessie" image is a must for the RPi3. Older models also benefit from the updated Bluetooth stack. After booting into Raspbian, you should check to see that Bluetooth runs (Listing 1).
Listing 1
Checking Bluetooth
$ sudo systemctl status bluetooth * bluetooth.service - Bluetooth service Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled) Active: active (running) since Tue 2016-05-03 12:40:01 UTC; 5s ago Docs: man:bluetoothd(8) Main PID: 8554 (bluetoothd) Status: "Running" CGroup: /system.slice/bluetooth.service |-8554 /usr/lib/bluetooth/bluetoothd May 03 12:40:01 raspberrypi bluetoothd[8554]: Bluetooth daemon 5.23 May 03 12:40:01 raspberrypi systemd[1]: Started Bluetooth service. May 03 12:40:01 raspberrypi bluetoothd[8554]: Starting SDP server May 03 12:40:01 raspberrypi bluetoothd[8554]: Bluetooth management interface 1.9 initialized May 03 12:40:01 raspberrypi bluetoothd[8554]: Sap driver initialization failed May 03 12:40:01 raspberrypi bluetoothd[8554]: sap-server: Operation not permitted (1)>
The error message Sap driver initialization failed should be ignored. It is not generated because a piece of software is missing; however, you can keep the SIM Access Profile (SAP) Bluetooth component from loading by adding --noplugin=sap
in the configuration file /lib/systemd/system/bluetooth.service
[7] as follows:
ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=sap
Then, reload systemd and restart Bluetooth:
$ sudo systemctl daemon-reload $ service bluetooth restart
As shown here, the systemctl
command shown in Listing 1 also lets you control an active Bluetooth service running in the background by replacing the status
subcommand with start
, stop
, or restart
.
Bluetooth is not yet stable on the Rasp Pi. In fact, my Bluetooth hardware stopped completely while I was working on this article, and I had to restart the computer. In addition to the Bluetooth service, you need a series of commands to control and administer Bluetooth connections. If your Rasp Pi is connected to a monitor, a graphical interface, discussed in more detail later, makes this process easier.
Under Control
The tool of choice for administering the Bluetooth stack is the interactive bluetoothctl
command, comprising the simple command-line program and a command shell. The shell is used to set commands for status requests, scans, pairings, and more. Table 1 provides an overview of the commands that are available, and Figure 2 shows output from various status requests.
Table 1
bluetoothctl Commands
Command | Parameter | Description |
---|---|---|
|
– |
Display available controllers |
|
[ctrl] |
Controller information |
|
|
Set default controller |
|
– |
List available devices |
|
– |
List paired devices |
|
|
Set controller power on or off |
|
|
Set controller pairable mode on or off |
|
|
Set visibility on or off |
|
|
Enable or disable agent with given capability |
|
– |
Set current agent as default |
|
|
Set scan for devices on or off |
|
|
Device information |
|
|
Pair with device |
|
|
Trust device |
|
|
No longer trust device |
|
|
Block device |
|
|
Enable blocked device |
|
|
Remove device |
|
|
Establish low-level connection with device |
|
|
Disconnect device |
|
– |
Display version |
|
– |
End Bluetoothctl program |
The commands list
and show
are used to display the local Bluetooth devices. With respect to the RPi3, it would display the on-board Broadcom chip. Moreover, the show
command lists the supported profiles and thus the possible functions. Visible foreign devices, on the other hand, are listed via the devices
command. As shown in Figure 2, this is dependent on an active scan process that is enabled with scan on
. Similarly, the scan off
command turns the search function off.
The interactive Bluetoothctl shell supports typical Bash shell functions, such as browsing and searching through the command history, editing, and command completion with the Tab key. Tab completion makes it easier to query the device, especially when cryptic Bluetooth addresses are involved.