Setting up Bluetooth on the Raspberry Pi 3

Lead Image © Alexander Pokusay, 123RF.com

Cut the Cord

The Raspberry Pi 3 comes with Bluetooth capability already on board, making it possible for every user to take advantage of this wireless technology.

The Raspberry Pi 3 (RPi3) has many upgrades and improvements – among them on-board WiFi and Bluetooth. WiFi has become the go-to capability for transmitting large amounts of data. Bluetooth, on the other hand, has some advantages when close-range transmissions are at issue. Setting up WiFi goes quickly with the help of the GUI, but using the Bluetooth module requires several modifications to the Raspbian system.

In this article, I introduce the Bluetooth architecture and describe how Linux supports the standard. I also look at programs needed for a Bluetooth setup and provide examples illustrating additional areas of application for a Raspberry Pi (Rasp Pi) outfitted with Bluetooth technology.

Blue Theory

"Bluetooth" was the code name given to a standardization project for short-range wireless communication. The name is an Anglicized reference to a 10th century Danish king, Harald Bluetooth, who was successful in using the power of communication to unite hostile Norwegians with hostile Danes. When the technology was released, the name stuck and a logo was crafted out of the Old Norse runic symbols for the king's initials, H and B. These historic references make sense in light of the significant roles played by the Ericsson (Swedish) and Nokia (Finnish) companies in developing the standard.

The Bluetooth (BT) standard [1] was originally developed to solve problems related to infrared (IR) connections that depend on visual contact. The goal was to let peripheral devices communicate with a PC. Out of necessity, original data rate specifications were low. For the first version, the theoretical maximum was 732.2Kbps. Since the advent of BT v2.0+EDR (enhanced data rate), the limit is 2.1Mbps. The Bluetooth module on the RPi3 (Figure 1) works according to the Bluetooth v4.1 Low Energy (LE) standard.

Figure 1: The antenna module for the RPi3 is located between the GPIO and the display interface.

Bluetooth transmits in the 2.4GHz band on 79 channels between 2.402 and 2.480GHz. Typical sources of interference in this band include WiFi radio waves and microwaves. The DECT standard [2] for cordless telephones uses a different wireless band (1.88-1.90GHz in Europe; 1.92-1.93GHz in North America). Various techniques such as adaptive frequency hopping and correlating codes increase the stability and the data throughput, even when other devices operate on the same band.

Bluetooth devices can generate a small network accommodating up to eight participants (the address comprises 3 bits). Even so, these devices are most often used for point-to-point connections. Additionally, a park mode has an 8-bit address that lets up to 255 devices maintain synchronicity. A master distributes time slices to the slaves for communication. Devices are permitted to participate concurrently on multiple piconets [3] but only one time as a master.

Bluetooth provides two physical data channels: One is for synchronous (language) communication, and the other is for asynchronous (data transmission) communication. These channels transmit data almost concurrently. As a result, headsets transmit commands for volume control via the data channel in parallel with the language connection.

Further technical details (e.g., the continued development of the protocol, ways of establishing a connection, and security issues) are found on Wikipedia [1]. The ability to use Bluetooth hardware requires software support, the so-called Bluetooth stack.

Bluetooth for Linux

The open source BlueZ [4] project is the official Linux Bluetooth protocol stack. Because Linux also serves as the basis for Android, this stack is well maintained. However, the low-level functions only make up half of the story. Bluetooth does not specify the manner by which components communicate with one another. Therefore, Bluetooth has protocols known as "profiles," which specify compatibilities that must be present for communication between devices to occur. By way of example, a headset has to both receive audio streams and support telephone functions.

The developers also maintain basic profiles as part of the BlueZ project [5]. However, not every profile can accommodate the BlueZ kernel [6]. For example, the file transfer profile (FTP) requires Object Exchange (OBEX), whereas the Advanced Audio Distribution Profile (A2DP) and HTTP File Server (HFS) profile require PulseAudio. Practically speaking, this means you will need to install a series of software packages to enjoy all of the Bluetooth functions. Raspbian, however, would not be Raspbian if the standard image did not come with almost everything already in place.

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content