Skip to content

Bluetooth

Orlin edited this page Feb 11, 2018 · 3 revisions

Install the necessary packages:

sudo apt-get install -y alsa-utils bluez bluez-tools pulseaudio-module-bluetooth

sudo apt-get install -y connman

sudo apt-get install -y python-gobject python-smbus python-dbus

Audio Configuration

Enable and load the sound module:

echo 'snd_soc_hifiberry_dac' | sudo tee -a /etc/modules

echo 'snd-soc-hifiberry-dac' | sudo tee -a /etc/modules

sudo modprobe snd_soc_hifiberry_dac snd-soc-hifiberry-dac

Add users to pulse audio groups:

sudo usermod -a -G lp pi

sudo usermod -a -G pulse-access,audio root

sudo adduser pi pulse-access

Change configuration file for the PulseAudio daemon:

sudo nano /etc/pulse/daemon.conf

resample-method = trivial

Configure inclusions in the PulseAudio startup script for system mode:

sudo nano /etc/pulse/system.pa

.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
.endif

.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif

.ifexists module-bluez5-device.so
load-module module-bluez5-device
.endif

.ifexists module-bluez5-discover.so
load-module module-bluez5-discover
.endif

To create the service starting script:

sudo nano /etc/systemd/system/pulseaudio.service

[Unit]
Description=Pulse Audio
[Service]
Type=simple
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disallow-module-loading --disable-shm --daemonize
[Install]
WantedBy=multi-user.target

Scan for new/changed units and to restart the PulseAudio service:

sudo systemctl daemon-reload

sudo systemctl enable pulseaudio.service

sudo systemctl start pulseaudio.service

Enable output to a prefered connector (0=auto,1=headphones,2=hdmi):

amixer cset numid=3 1

Set the volume level on the server side to 100 percent:

amixer set Master 100%

pacmd set-sink-volume 0 65535

Bluetooth Configuration

Allow A2DP audio sinks

sudo nano /etc/bluetooth/audio.conf

[General]
Enable=Source,Sink,Media,Socket
HFP=true
Class=0x20041C

sudo nano /etc/bluetooth/main.conf

[General]
Name = audiGamma
Class = 0x20041C

List the BT adapter config:

sudo hciconfig -a

specify the MAC address here:

sudo nano /var/lib/bluetooth/XX:XX:XX:XX:XX:XX/settings

And paste these lines:

[General]
Discoverable=true
Name=audiGamma
Alias=audiGamma
Class=0x20041C

Bring up the BT:

connmanctl enable bluetooth

sudo hciconfig hci0 up

in the BT control shell:

bluetoothctl

execute:

agent on
default-agent
discoverable on
scan on

Next, execute the following to pair/trust your client device(s):

pair XX:XX:XX:XX:XX:XX
[agent] Confirm passkey (yes/no): yes
trust XX:XX:XX:XX:XX:XX

sudo service bluetooth restart

Setup auto connecting

pactl list sources short

0       alsa_output.platform-soc_sound.analog-stereo.monitor    module-alsa-card.c      s16le 2ch 44100Hz       IDLE
1       bluez_source.XX_XX_XX_XX_XX_XX  module-bluez5-device.c  s16le 2ch 44100Hz       RUNNING

pactl list sinks short

0       alsa_output.platform-soc_sound.analog-stereo    module-alsa-card.c      s16le 2ch 44100Hz       RUNNING

pactl load-module module-loopback source=bluez_source.XX_XX_XX_XX_XX_XX sink=alsa_output.platform-soc_sound.analog-stereo rate=44100 adjust_time=0

I've tried github.com/oleq/ _README.md#Setup auto connecting & instructables.com/dantheman_213 with no success

run child processes as different user

sudo nano /etc/rc.local

...
cd /home/pi
python child.py pi /home/pi pactl load-module module-loopback source=bluez_source.XX_XX_XX_XX_XX_XX sink=alsa_output.platform-soc_sound.analog-stereo rate=44100 adjust_time=0&

Auto–login

Auto–login can be enabled using

sudo raspi-config

in "Boot Options" -> "Console Auto–login".

Clone this wiki locally