Marcus Young

Software. Microcontrollers. Beer.

Raspberry Pi-Automated Bluetooth Audio Player !

| Comments

Backstory

After a long break, I’ve finally gotten one part of my to-do list for my Raspberry Pi….automated bluetooth audio playing!
As always: there were issues. First, the support for this sucked. I was thankful to get a starting point from John Hamelink. He wrote a set of sweet scripts that automate a lot of this. However, they were written for Arch Linux, and required a bit of work syntactically to get it working for Debians Wheezy Release. My final code is here.

The Nitty Gritty (install steps)

First, install the normal packages (as seen here) and let the pi user able to control bluetooth devices:

1
2
pi@raspberrypi ~ $ sudo apt-get install bluez pulseaudio-module-bluetooth python-gobject python-gobject-2
pi@raspberrypi ~ $ sudo usermod -a -G lp pi

Next, let’s make the bluetooth module compatible for audio streaming. Edit /etc/bluetooth/audio.conf and add this after [General]:

1
Enable=Source,Sink,Media,Socket

Next, we’ll let pulseaudio do the playback. Edit /etc/pulse/daemon.conf and uncomment:

1
resample-method = trivial ; ADD THIS LINE TO THE FILE!

We need some additional packages to make it compatible with my scripts. Qdbus allows you to send D-Bus messages to the bluez daemon, git-core is so you can clone my repo, and bluez-tools provides the bluetooth-agent which is one of the daemon pieces.

1
pi@raspberrypi ~ $ sudo apt-get install bluez-tools qdbus git-core

Now, we’re going to gain root, put my code in /root, and make a init.d file you can provide at startup.

1
2
3
4
5
6
7
pi@raspberrypi ~ $ sudo su -
root@raspberrypi:~# git clone https://github.com/myoung34/bluetoothradio.git --branch Wheezy
root@raspberrypi:~# cd bluetoothradio
root@raspberrypi:~/bluetoothradio# cp bluetooth-server /etc/init.d
root@raspberrypi:~/bluetoothradio# chmod 755 /etc/init.d/bluetooth-server && chmod +x /etc/init.d/bluetooth-server
root@raspberrypi:~/bluetoothradio# update-rc.d bluetooth-server defaults
root@raspberrypi:~/bluetoothradio# reboot

Usage

After the reboot, you can now pair your device using ’1234′ (unless you modified the bluetoothPin file), and play yo’ music!

If for some reason it’s not connection, visit KMonkey711′s tutorial and follow the steps to connect and trust the device, and reboot the pi.

Acknowledgements

Thanks to:
johnhamelink
KMonkey711

Comments