Updated on 2026/08/27

Acronyms

Introduction to Bluetooth

There are two types of Bluetooth:

  1. Classic - which is used for contineous connections with high data rates such as high quality audio.
  2. Bluetooth Low Energy (BLE) - which is used for low data rates such as keyboards, mice, thermostates, and IoT devices. BLE usally transmitts and receives data in burst.

The name BLE is somewhat of a misnomer. Because BLE's data rate is low, overall, it uses less energy than Classic Bluetooth. However, during the times that it does transmit and recieves data, it uses more energy that Classic Bluetooth. BLE's range is considerable more than Classic Bluetooth. BLE did not become part of the Bluetooth Standard until version 4.0.

Bluetooth Classic has two data rate:

  1. Basic Rate (BR)
  2. Extended Data Rate (EDR)

Sometimes Bluetooth Classic is referred to as Bluetooth BR/EDR and sometimes the forward slach is suppressed (bredr).

Bluetooth Profiles

A Bluetooth keyboard is quite different than a Bluetooth speaker. One has a low data rate and is an input and other has a high data rate and is an output.

To connect to a Bluetooth device, it's profile has to be defined. There are standard profiles for keyboards, speakers, headsets, etc., but sometimes, the the user has to enter some data.

The Bluetooth Stack

The offical Bluetooth stack for Linux is BlueZ. With BlueZ's bluethoothctl command, you can pair, trust, and connect to bluetooth devices. However, the later (connect) requires that the device's profile be defined.

Bluez expects the devices profile to be defined by other packages such as PipeWire, PulseAudio or ALSA. PipeWire and PluseAudio are large packages that expect a GUI Desktop. They can usually generate a device profile without user interaction. ALSA is more suited for small and embedded systems. ALSA requires the user to supply some basic information for the device profile.

It is simple to create an ALSA device profile, but for some reason, this is not well know. I have seen numerious blogs that want to connect a Bluetooth speaker with the more more simple (and less dependences) ALSA framework, but they do everyting they can not to create an ALSA profile. This includes installing PipeWire and PuleAudio and sometimes deleting PulseAudio afterwards.

BluezALSA

At one time bluealsa (without a z) was a seperate package. Now, it is part of the bluezalsa (with a z) package. To install it:

sudo apt install bluez-alsa-utils

To define a profile for your bluetooth device, you have to create a configuration file - ether /etc/asound.config for global or .asoundrc for local. I do not know why they did not just use bluealsa.config or .bluealsarc. Nor do I do what you have to create then files. Most Linux package have default configuration file with most or all of the paramaters in the file comment out.

Reference 3 has a link to a simple configuration file. The code is below:

 
defaults.bluealsa {
    interface "hci0"
}

pcm.btheadset {
    type plug
    slave.pcm {
        type bluealsa
        device "11:22:33:44:55:66"
        profile "a2dp"
    }
    hint {
        show on
        description "Headset"
    }
}

pcm.btspeakers {
    type plug
    slave.pcm {
        type bluealsa
        device "AA:BB:CC:DD:EE:FF"
        profile "a2dp"
    }
    hint {
        show on
        description "Speakers"
    }
}
              

I had an application that used two Bluetooth Speaker. My ./etc/asound.conf file is:

 
defaults.bluealsa {
    interface "hci0"
}

pcm.btspeakers {
    type plug
    slave.pcm {
        type bluealsa
        device "38:69:63:98:83:d6"
        device "8C:CA:C6:1D:98:2F"
        profile "a2dp"
    }
    hint {
        show on
        description "Speakers"
    }
}
              

That's all there is to creating a device bluealsa profile.

In the next section we will connect to device (profile) using bluetoothctl. In the following section, we will the aplay command to send sound to the connected bluetooth speaker. Aplay is part of the blusez-alsa-utils package.

References

  1. Raspberry Pi Bluetooth Speaker: A2DP Audio Streaming Build
  2. Debian Documentation : bluealsa - Bluetooth Audio ALSA Backend
  3. Bluetooth audio on a headless Raspberry Pi using BlueAlsa
  4. Bluetooth Audio ALSA Backend

Bluetooth and Low Energy Bluetooth (LEB)

BlueZ is the official Linux Bluetooth stack. It provides the necessary infrastructure to manage Bluetooth devices, implement Bluetooth profies, and establish connections.

To install BlueZ and its utilites:

sudo apt install bluez bluez-utils

The tool for scanning, pairing, trusting and connecting to devices is bluetoothctl.

To scan for nearby devices:

bluetooth scan on

It displays a list of discovered devices with there names and MAC address.

Once you have found the device you want to pair, note it MAC address, then execute the following commands:

bluetoothctl pair xx:xx:xx:xx:xx:xx
bluetoothctl trust xx:xx:xx:xx:xx:xx
bluetoothctl connect xx:xx:xx:xx:xx:xx

You only pair and trust a device once. You reconnect to a device with the connect command above.

References

  1. Linux BlueZ: A Comprehensive Guide

Advance Linux Sound Architecture - ALSA

Alsa is a low level software framework for audio.

Higher level sound servers such as PipeWire, PluseAudio, Jack and sndio run on top of alsa. Because sound devices can come and go (plugged in and unplugge) sound servers assign a device number or node number to them. The device/node number is dynamic and can change for a device. For, this reason, they are not ideal for embedded system.

With alasa you can reference a device via its MAC address

On most Linux distributions alsa is installed by default, but not its utilities. To install alsa-utils:

sudo apt install alsa-utils

Alsa's playback command is aplay. Aplay can playback wav files but not mp3. Its syntax is:

aplay -d no_of_second_to_play -D device_name wave_file.wav

For a bluetooth speaker, device_name is bluealsa:xx:xx:xx:xx:xx:xx

alsamixer

Alsamixer is a sound mixture with a graphical (non-desktop) interface. Using the F6 key, you can select sound cards by a drop down box or by name. It will accept the name, bluealsa:xx:xx:xx:xx:xx:xx.

amixer

Amixer is a command line only sound mixture. Thus far, I have not been able to change the sound level of a bluetooth device with it.

alsactl

Alsactl provides a means of storing and retriving sound mixture setting. The following command does this:

alsactl store

References

  1. Raspberry Pi Audio: ALSA, PipeWire, DAC HATs, and Bluetooth Setup
  2. Linux amixer Command with Practical Examples
  3. aplay - Play audio files via ALSA
  4. Linux Concept - amixer
  5. Github - Help with "Couldn't get BlueALSA PCM: PCM not found" error #394
  6. amixer: Unable to find simple control 'Master',0

PipeWire

To install pipewire on a Raspberry Pi Zero 2W:

sudo apt install pipewire

sudo apt install pipewire-audio

To set the default output (sink), you have to get the sink number of the device. Get the number with wire plumber:

wpctl status

To set the default device, use the number obtianed above in the following command.

wpctl set-default <Device-No.>

To set the volume of the default device:

wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.8

To playback a wave (*.wav) file:

pw-cat --playback <sound-file.wav>

or

pw-cat --playback --volume <No.> <sound-file.wav>

PipeWire's preferred session manager WirePlumber [1].

On Raspberry Pi OS Lite (no desktop), PipeWire is not installed. Audio goes through ALSA directly. Use alsamixer for volume and aplay for playback. Install alsa-utils if missing: sudo apt install alsa-utils [2].

References

  1. How to Configure Audio Device Priorities in Pipewire / Wireplumber
  2. free-sounds.net/sirens.htm