Last active
April 30, 2020 20:08
-
-
Save ggirou/78b5705a4bc3384617c39544a8f9628d to your computer and use it in GitHub Desktop.
Raspberry pi bluetooth speaker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hciconfig | |
hciconfig hci0 up | |
hciconfig hci0 reset | |
# Scan for Bluetooth devices | |
hcitool scan |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get update | |
# RPI non-Zero | |
sudo apt-get install -y bluez pulseaudio pulseaudio-module-bluetooth | |
# RPI Zero | |
sudo apt-get install bluealsa mpg123 | |
sudo service bluealsa start | |
sudo bluetoothctl | |
# in console [bluetooth]# | |
agent on | |
default-agent | |
scan on | |
# wait for your device to show and make it discoverable | |
trust YOURMACADR | |
pair YOURMACADR | |
connect YOURMACADR | |
quit | |
# RPI non-Zero | |
pulseaudio -k | |
pulseaudio -D | |
# look for bluez card | |
pacmd list-cards | |
# look for bluez card | |
pacmd set-default-sink bluez_sink.xx_xx_xx_xx_xx_xx | |
pacmd set-card-profile bluez_sink.xx_xx_xx_xx_xx_xx a2dp_sink | |
# RPI Zero | |
# aplay -D bluealsa:HCI=hci0,DEV=XX:XX:XX:XX:XX:XX,PROFILE=a2dp /usr/share/sounds/alsa/* | |
cat <<EOF > ~/.asoundrc | |
defaults.bluealsa.interface "hci0" | |
defaults.bluealsa.device "XX:XX:XX:XX:XX:XX" | |
defaults.bluealsa.profile "a2dp" | |
defaults.bluealsa.delay 10000 | |
EOF | |
aplay -D bluealsa /usr/share/sounds/alsa/* | |
# mpg123 -a bluealsa test.mp3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MAC_ADDRESS=78:44:05:96:3D:EE | |
MAC_ADDRESS_=`echo $MAC_ADDRESS | tr ':' '_'` | |
# a2dp_sink, headset_head_unit, off | |
PROFIL=a2dp_sink | |
bluetoothctl <<-EOF | |
agent on | |
default-agent | |
trust $MAC_ADDRESS | |
pair $MAC_ADDRESS | |
connect $MAC_ADDRESS | |
EOF | |
sleep 2 | |
pacmd list-cards | |
pacmd set-card-profile bluez_card.$MAC_ADDRESS_ $PROFIL | |
pacmd set-default-sink bluez_sink.$MAC_ADDRESS_.$PROFIL | |
pacmd set-default-source bluez_source.$MAC_ADDRESS_.$PROFIL |
Pulseaudio comes with one modulo to switch automagically to last device connected.
Try to gives this command to pulseaudio (or enable it in pulse.conf)
pactl load-module module-switch-on-connect.
I think KODI must be set to Alsa device output (or pulse)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sources:
http://youness.net/raspberry-pi/how-to-connect-bluetooth-headset-or-speaker-to-raspberry-pi-3
http://youness.net/raspberry-pi/bluetooth-headset-raspberry-pi
http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/bluetooth/bluetooth-commands
https://wiki.debian.org/BluetoothUser/a2dp
Alternatives:
Tests: