This walks you through setting up your Raspberry PI 3 (Raspbian Jessie) as a bluetooth audio receiver.
Credits https://www.raspberrypi.org/forums/viewtopic.php?t=68779. Parts of this tutorial did not work for me, so I'm noting my fixes here. Also, I added instructions for setting up a custom USB sound card for better quality.
aplay -l
This will list the available audio devices. In my case:
**** List of PLAYBACK Hardware Devices ****
card 1: Set [C-Media USB Headphone Set], device 0: USB Audio [USB Audio]
Subdevices: 0/1
Subdevice #0: subdevice #0
card 2: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 2: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0
We need to tell ALSA (Advanced Linux Sound Architecture) to use the USB sound card.
sudo nano /usr/share/alsa/alsa.conf
Change
defaults.ctl.card 0
to
default.ctl.card 1
and
defaults.pcm.card 0
to
defaults.pcm.card 1
sudo apt-get update
sudo apt-get install bluez pulseaudio-module-bluetooth python-gobject python-gobject-2
Note: bluez is used to manage bluetooth and pulse-audio is used for sound-management.
sudo usermod -a -G lp pi
The original tutorial says to edit sudo nano /etc/bluetooth/audio.conf, but no such file in latest RPI. Instead, edit /etc/bluetooth/main.conf.
Add complete the following line in the [General] section:
Enable=Source,Sink,Media,Socket
sudo nano /etc/pulse/daemon.conf
Add or edit the following line:
resample-method = trivial
Reboot:
sudo reboot
The RPI 3 comes with bluetooth.
I used the GUI and followed these steps:
1. Right click the bluetooth systeay icon at the top right and click "Make discoverable"
2. Right click the bluetooth systray icon at the top right. Add device , then select the appropriate device from the scanned list, and connect. This will ask to confirm a code on both the RPI and the bluetooth device. Confirm on both sides.
3. Connect via the Bluetooth manager: Menu > Preferences > Bluetooth Manager, right click on the device and click "Connect"
Note: I found the above process to work for me, but not sure I need to connect twice.
The device needs to be paired and trusted.
pulseaudio -D
pactl list sources short
In the list you should see something like bluez_source.AA_AA_AA_AA_AA_AA where AA_AA_AA_AA_AA_AA is the MAC address of your bluetooth device.
pactl list sinks short
Note: you must change the name of the sink and source to the names of your own bluetooth device and sink:
pactl load-module module-loopback source=bluez_source.AA_AA_AA_AA_AA_AA sink=alsa_output.usb-0d8c_C-Media_USB_Headphone_Set-00-Set.analog-stereo
You can test by playing a youtube video, music file, etc. on your bluetooth-connected phone.
TODO: add instructions for automating connection and sink/source coupling. Haven't gotten to that part yet.
possible reason if I don't see a bluez device in
pactl list sources short
??