Howdy folks! I had the idea of turning my Raspberry Pi into something like the Beats By Dre portable audio system found here:

It’s a cool product, don’t get me wrong, but I’m not really down to pay $400+ tax for some fancy looking speakers (which don't even give you rechargeable batteries, by the way). So I decided to set off to replicate the functionality without the hefty price tag.

OBJECTIVE: To create a Raspberry Pi that automatically boots into the command line and becomes discoverable via Bluetooth. Any Bluetooth-enabled device with the A2DP (Advanced Audio Distribution Profile) support will be able to push audio to the Pi through its Analog (default) or HDMI speaker output. When a Bluetooth device connects, the PI routes the connection through to Pulse audio and Bluetooth discoverability is turned off. The audio should play seamlessly from here. You can then disconnect your device (likely a smartphone) and the PI will become discoverable again via Bluetooth and another device is free to connect. The default pass key will be 0000 but most devices input this automatically so it should be hassle free!

NOTE: I did find that a lot of other people in the Linux community have attempted to do the same thing to their PI but not as successfully as I have! My setup allows the device to run headless (without a monitor) from boot and any Bluetooth device can connect and disconnect without an issue. I’ve seen a lot of other people with tutorials that make you login via command line first or login to the desktop and setup the Bluetooth connection manually. LAME! The goal of this is to be as similar to a *product* as possible. :) enjoy!

NOTE: This tutorial assumes you have a fair amount of Linux/command-line knowledge. I won’t be explaining basic commands or ideology so if this is above your head find a friend!

What is the Raspberry PI?
The Raspberry Pi is a credit-card sized computer that plugs into your TV and a keyboard. It’s a capable little PC which can be used for many of the things that your desktop PC does, like spreadsheets, word-processing and games. It also plays high-definition video. --Raspberry PI website

You can learn more about the PI and how to get one, here:

• Raspberry Pi
• Bluetooth v4.0+ micro USB dongle
• 4GB SD Card

Requirements for [portable audio]
• Battery-powered speaker(s)
• Battery pack for Raspberry Pi
• Enclosure to keep everything in

Step 1: Prepare SD for base Operating System

Go ahead and pop in your SD card into your card reader. For this setup we will be using Raspbian Wheezy, which is the latest Debian based OS for the PI at the time of this writing. You should be able to find the latest version here:

Download and uncompress the image file and note the location. If you’re using a Mac it should be trivial to burn the image to the SD card. If you’re a Windows user however, go ahead and use this utility to “burn” the IMG file to the SD card.

Make sure you select the right file and the right drive letter before hitting the WRITE button or you could have some nasty things happen. :(
<p>Don't Work for Me ! My Phone can connect, but no sound. <br><br>Any Solutions ?</p>
<p>this wirks for me, but i need to run it manually everytime i power up RPi</p><p>try this, but you need to type this in everytime you turn off RPi, i am still looking for solution</p><p>type</p><p>pactl list sources short <br></p><p>(you should get)</p><p>0 alsa_output.platform-bcm2835_AUD0.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED</p><p>1 bluez_source.B8_C6_8E_52_E8_CA module-bluetooth-device.c s16le 2ch 44100Hz SUSPENDED</p><p>than type</p><p>pactl list sinks short <br></p><p>(you should get)</p><p>0 <strong>alsa_output.platform-bcm2835_AUD0.0.analog-stereo</strong> module-alsa-card.c s16le 2ch 44100Hz SUSPENDED</p><p>type (replace your own bluez_source and alsa_output) <br></p><p>pactl load-module module-loopback source=<em>bluez_source.B8_C6_8E_52_E8_CA</em>sink=<em>alsa_output.platform-bcm2835_AUD0.0.analog-stereo</em></p>
<p>Thanks, this worked for me, you are right, I need to run it every single time I reconnect the BT:</p><p>pi@raspberrypi ~ $ pactl list sources short</p><p>0 alsa_output.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED</p><p>1 bluez_source.B8_E8_56_BA_48_2D module-bluetooth-device.c s16le 2ch 44100Hz SUSPENDED</p>
<p>I forgot this part: </p><p>pi@raspberrypi ~ $ pactl load-module module-loopback source=bluez_source.B8_E8_56_BA_48_2D sink=alsa_output.0.analog-stereo</p>
<p>Hey Thanks for your help, I have the same problem and can able to solve with this. Now my beats are on my speakers but Can I do this without giving command (like - &quot;pi@raspberrypi ~ $ pactl load-module module-loopback source=bluez_source.B8_E8_56_BA_48_2D sink=alsa_output.0.analog-stereo&quot;)? And do connect automatically?</p>
I just get 'connection refused' from this. :(
Did you Ty pushing audio out the 3.5mm jack in raspi-confit?
how do you do this?
<p>Yes, and i See My phone into capture device, i think Pulse don't work with new versions, or the script don't work</p>
<p>I'm having the same exact problem.</p>
<p>Hey guys! I am using HC-05 Bluetooth module and have seem to stuck on step 4. </p><p>I can't seem to understand the line &quot;<em>sudo nano /var/lib/bluetooth/&lt;bluetooth mac address&gt;/config.&quot; </em></p><p>No matter whatever I write in the bluetooth mac address area, a new file gets opened and there is nothing to edit. Please help me with this step. How should I proceed.</p>
<p>I found the MAC address using this command: hcitool dev</p>
<p>Have you tried to use type `sudo nano /var/lib/bluetooth/` and then double-press tab? It should come up with a list of options (as in files and directores in the directory `/var/lib/bluetooth`). See if your MAC-address is there. If it fails, rinse and repeat the previous step(s).</p>
<p>Oh, make sure you're root by the way. The directory can't be read by anyone non-root apparently...</p>
<p>I found this error, parring working with Android but when I try to activate it like multimedia device It doesn't work:</p><p>on syslog I found (no bluetooth file found)</p><p>syslog:Oct 9 00:09:46 rasp1 bluetoothd[1959]: input-headset driver probe failed for device 18:3A:2D:C1:33:87<br>syslog:Oct 9 00:15:40 rasp1 bluetoothd[1959]: Unable to get a audio source object</p>
<p>amixer call inside <em>/usr/lib/udev/bluetooth needs </em>alsa-utils package (I'm coming from a minbian distro)</p><p>Unfortunately I did not manage yet to hear any audio neither from HDMI nor analog AV 3,5 jack while BT pairing and connection works well.</p><p>Another problem is that upon boot the bluetooth-agent do not start and I did not understand why.</p><p>However the guide is very well done, thanks</p>
<p>Few minutes after my post I managed to hear audio thanks to <a href="/member/ŽanK" rel="nofollow">ŽanK</a> contribution</p>
Great instructable, very clear, but doesn't work for me either. Tried two phones. They pair but get no sound. I added the extra lines in the comments below too, still nothing. Shame. Thanks anyway.
<p>Hi, this instructable is very well done and just what I wanted. However I have a problem....</p><p>I followed the instructions and my phone connects with my Pi via the Bluetooth. However the only sound I hear if I play any music is a buzzing. I have my Pi line out plugged into the Line in of my stereo amp. Is that correct? Other options would be CD, Phono or Tape.</p><p>Any idea why I just get buzzing?</p><p>Thx.</p>
<p>Any suggestions anyone?</p>
<p>Excellent tutorial! Really easy to follow to completion in ~15 minutes. Works fantastic. One minor thing I will say is that the audio lags by about .5 seconds, so maybe not perfect if you're watching a video (this is probably a limitation of the pi itself) But for audio alone, it works exactly the way I hoped it would!</p>
<p>I'm having the same issue as Philrlewis</p><p>&quot;Every time I try to set my class as 0x20041C in /var/lib/bluetooth/ it saves, but on reboot the class has reverted back to 0x4e041c. Any ideas how to stop this?&quot;</p>
change class as 0x4e041C in /var/lib/bluetooth ,and it's work!
<p>Hi all, the same for me... I think this file is generated at boot.</p><p>When editing /etc/bluetooth/main.conf, I set the device's Class parameter by 'Class = 0x20041C' instead of 'Class 0x20041C' regarding the classic syntax for all parameters of the file.</p>
<p>just chmod to 444. fixes the problem.</p>
<p>how to solve it?</p><p>i get this issue too, i'm so frustated..</p>
<p>Thank you very much for a very useful guide.<br><br>I got this up and running on my Pi 2. The only changes I made to the guide above were items 2 and 3 from gliuzzo's comment below and I skipped step 7 above, autologin. (I think gliuzzo's third tweak possibly takes care of this issue?)<br><br>Although it seems to be working nicely through the analogue output, I'd like it to work through HDMI, and I can't for the life of me work out how. I've tried commenting out the amixer line in /usr/lib/udev/bluetooth, without success. I'm assuming that the AUDIOSINK line of that file needs to be changed too, but to what? Can anyone help.<br><br>Many thanks in advance for any help.</p>
<p>Ah-hah. Changing the last number in the (first) amixer line from a 1 to a 2 did the trick!</p><p>There's a delay of maybe about 1.5 seconds. I was optimistically hoping to use it for audio output on Skype, so that might be just a little bit too long for it to be bearable (oh well!). Other than that, though, it seems to work a treat.</p><p>Thanks again,</p><p>Gareth</p>
<p>Great guide, i only have one problem,<br>when connecting with my android phone it connects without any problem and i can stream audio, but when connecting with my macbook air it connects on the macbook but not in the /var/log/bluetooth file. This has the result of not being able to stream audio from my macbook air.</p>
<p>This is a great guide, Dan. I had to make some changes to how pulse connects, but I don't think I would have made it through the process without this guide, which covers all the steps to automate the bluetooth connection.<br>Sincere thanks - I salute you!<br>The symptom/problem I had was that bluetooth audio would stream for a few seconds and then the pulseaudio daemon would quit.<br><br>Just in case it helps anyone, this is how I got pulse to stream from bluetooth with the current version of Raspbian, which, as of this writing is:<br>Linux raspberrypi 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l GNU/Linux<br><br>nohup pulseaudio --disallow-exit --disallow-module-loading=0 --high-priority --load=&quot;module-loopback source=bluez_source.XX_XX_XX_XX_XX_XX sink=0 &quot; 1&gt;&gt;/var/log/bluetooth_dev 2&gt;&gt;/var/log/bluetooth_dev &amp; <br><br>I hope this helps somebody.</p>
<p>Running this on the rpi2 i had to make the changes gliuzzo did below, and also added a sleep to the bluetooth-agent script, since it needed a delay before running.</p>
<p>also, changed Master to PCM in the bluetooth script to adjust volume properly.</p><p>If you're using the crappy analog audio output, you might want to also add the following line to /boot/config.txt:</p><p>disable_audio_dither=1</p><p>I'm actually using a USB audio output since its worlds better.</p><p>AUDIOSINK=&quot;alsa_output.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device.analog-stereo&quot;</p>
<p>I've been stuck on the 'sudo usermod -a -G Ip pi'</p><p>whenever i put it in, i get this:</p><p>usermod: group 'Ip' does not exist</p><p>Ive tried all the suggestions in the comments so far but nothing works. Does anybody know why its not working?</p>
<p>I actually figured this one out, instead of 'sudo usermod -a -G Ip pi'</p><p>I used 'sudo adduser pi bluetooth'</p>
<p>So I finally got it working... Sort of.</p><p>The Raspberry Pi comes up, I can connect, But it still plays through my ipod and not the Raspberry pi</p><p>How do I fix this?</p>
<p>Hi guys! <strong>I Made it!</strong></p><p>It works nice, but I had some problems. These:</p><p>1&deg; <b>sudo usermod &ndash;a &ndash;G lp pi doesn't found</b></p><p>when I copied and pasted it didn't work. terminal didn't found it! then I manually wrote it exactly same and then worked perfectly. I don't know why</p><p>2&deg; <strong>output audio doesn't work</strong></p><p>in this file: /usr/lib/udev/bluetooth :</p><p>Replace this line:</p><p>AUDIOSINK=&quot;alsa_output.platform-bcm2835_AUD0.0.analog-stereo&quot;</p><p>With this:</p><p>AUDIOSINK=&quot;alsa_output.0.analog-stereo&quot;</p><p>3&deg; <strong>output audio after 20 seconds stopped</strong></p><p>Edit daemon configuration:</p><p>sudo nano /etc/pulse/daemon.conf</p><p>Change</p><p>; exit-idle-time 20</p><p>to</p><p>exit-idle-time -1</p><p>4&deg; <strong>bluetooth devices doesn't connect</strong></p><p>this is a proble about auto-login in tty1; I resolved this re-writing the <strong>/etc/inittab </strong>file like this, from:</p><blockquote>#1:2345:respawn:/sbin/getty 38400 tty1 <br>1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2&gt;&amp;1 <br>2:23:respawn:/sbin/getty 38400 tty2 <br>3:23:respawn:/sbin/getty 38400 tty3 <br><br>4:23:respawn:/sbin/getty 38400 tty4 <br><br>5:23:respawn:/sbin/getty 38400 tty5 <br><br>6:23:respawn:/sbin/getty 38400 tty6</blockquote><p>to:<br></p><blockquote>1:2345:respawn:/sbin/getty 38400 tty6 <br>2:23:respawn:/sbin/getty 38400 tty2 <br>3:23:respawn:/sbin/getty 38400 tty3 <br>4:23:respawn:/sbin/getty 38400 tty4 <br>5:23:respawn:/sbin/getty 38400 tty5 <br>#6:23:respawn:/sbin/getty 38400 tty6 <br>6:23:respawn:/bin/login -f pi tty1 /dev/tty1 2&gt;&amp;1</blockquote><p><strong>Enjoy!! Thanks @dantheman_213</strong><br></p><p>Finally, this is my 5+1 Hi-Fi with bluetooth receiver :)</p><p>I'll upload a video tomorrow :)</p>
<p>goddammit i really regret not reading comments had to debug the hell out of it and came to the same solution. could have saved alot of time. but thank you for posting so i dont have to ;P</p>
<p>&gt;1&deg; <b>sudo usermod &ndash;a &ndash;G lp pi doesn't found</b></p><p>Ya, I have a same error and found the cause of it.</p><p>`&ndash;` are not same with `-`!</p><p>Maybe the character are replaced by instructables's system.</p>
<p>Does anybody knows of this also works with the raspberry pi model 2B? I had it working a few times, but with a older raspbian image. I want to use the version of 5/5/2015. Thanks</p>
<p>Worked great for me after changing the sink as other users have mentioned.</p><p>The one thing I changed to avoid having to enter pins was the following line in the bluetooth-agent</p><p>sudo hciconfig hci0 sspmode 0</p>
<p>There was also a crazy long delay (about 30 seconds) which was fixed by following https://wiki.archlinux.org/index.php/PulseAudio/Troubleshooting#Bluetooth_headset_replay_problems</p>
<p>Hi, finally got this to work. </p><p>But what about Navi-Commands: next left ... next right. Is this possible too ?</p>
<p>If you're looking for a instructable for Raspberry Pi on Debian Jessie/SystemD (e.g. OSMC), maybe you'll find this one useful: http://www.instructables.com/id/Enhance-your-Raspberry-Pi-media-center-with-Blueto/</p>
<p>Thanks for a nice guide and the helpful comments below to tweak it. I just got it working with latest Raspberian. I understood from @NathanH11's comments that the reason I got no sound was related to pulse and access rights. Instead of switching to system mode I set the DISPLAY environment variable for the commands that run pulse commands as pi, changing:</p><p><em>CONFIRM=`sudo -u pi pactl list short | grep $bluez_dev`</em></p><p><em>to</em></p><p><em>CONFIRM=`sudo -u pi DISPLAY=:0 pactl list short | grep $bluez_dev`</em></p><p><em>and</em></p><p><em>sudo -u pi pactl load-module module-loopback source=$bluez_dev</em></p><p><em>to</em></p><p><em>sudo -u pi DISPLAY=:0 pactl load-module module-loopback source=$bluez_dev</em></p><p>...that might be helpful for more people.<br></p>
<p>5.1 hi-fi bluetooth :)</p>
I managed to fix the audio not playing problem by forcing audio out of the 3.5mm jack in raspi-config. sudo raspi-config &gt; advanced &gt; Audio &gt; force 3.5mm.
This was after following gliuzzo's fixes
and running the chmod 444 that groovechampion1 suggested
sorry for all the additional replies, I drank a couple victory beers before I thought to share how I figured it out. <br><br>I also had a problem with it being too quiet, I fixed this by running &quot;amixer cset numid=3 100%&quot;
<p>After playing with this for 2 days I just got this working on the latest. I had to make some pretty substantial changes... I'll list them out here, but I'm working from memory; they should give you enough pointers to self-solve:</p><p>1) The biggest problem is that pulseaudio will not work unless it's in system mode. Otherwise you'll always see it fail when it tries to access dbus. The problem stems from it not working in user mode unless you're running X11 and in an X session. I tried everything I could think of, but couldn't get a user daemon of pulseaudio to successfully access the system dbus. My guess is that this is the difference between a pristine minimal raspbian image and a Noobs image with all the trimmings.</p><p>The fix: run pulseaudio as a system service. To do that, you'll need to edit the /etc/default/pulseaudio config file, and the /etc/pulseaudio/ config files (plural). They should all match and declare themselves as system config; the pulseaudio page has info about the various settings and the precedence: it's a mess. You'll also need to add the bluetooth module to the puleaudio system.pa config, and there are some other modules that try to load and fail without X11, which need to be masked. You'll figure it out sequentially by tailing /var/log/syslog; the only one that seems to not be an actual problem is that the HFP endpoint in bluez isn't being set up: I chased that error but ultimately got everything working with it still there; (it will be there if you precisely follow the guide above and it's a red herring). You'll then need to go through the steps of giving user permissions to the pulse user and the pi user. Once that's done, you need to go setup dbus to allow bluez to contact pulse and vice versa. Pulse needs to be in the 'lp' group among other things.</p><p>2) The name of the pulseaudio alsa sink has changed. That's easy. You can fix with a little one-liner script to automatically pull the endpoint name when loading the loopback module, or since it's not likely to change, just 'pactl list sinks short' and hard-code it.</p><p>3) If you happen to pair the bluetooth device in the wrong order/with the wrong profile, you'll get a bunch of random config in /var/lib/bluetooth/&lt;mac&gt;/. Delete those files and fix the config file. Note: if you use a comment or mis-format the config file, the BT drivers will overwrite your settings. The file must be clean. If you fubar the setup, delete the whole directory and the next time the device loads it'll be clean.</p><p>Best of luck everyone!</p>

About This Instructable


327 favorites


Bio: 20-something programmer.
More by dantheman_213: Turn your Raspberry Pi into a Wireless Portable Bluetooth Audio System A2DP
Add instructable to: