Introduction: Turn Your Raspberry Pi Into a Wireless Portable Bluetooth Audio System A2DP

Picture of Turn Your Raspberry Pi Into a Wireless Portable Bluetooth Audio System A2DP

Howdy folks! I had the idea of turning my Raspberry Pi into something like the Beats By Dre portable audio system found here:
http://www.beatsbydre.com/speakers/beatbox-portable-usb/beatbox-portable-usb,default,pd.html

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:
http://www.raspberrypi.org/

Requirements
• 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

Picture of 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:
http://www.raspberrypi.org/downloads

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.
http://sourceforge.net/projects/win32diskimager/

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. :(

Step 2: Login to the PI Through a Monitor/keyboard or Network SSH

Picture of Login to the PI Through a Monitor/keyboard or Network SSH

Your PI will need to be connected to the Internet at this point, either through a LAN or a WiFi connection. I won’t be covering how to connect your PI to WiFi or login from SSH; Google is your friend!

Otherwise use a keyboard and a monitor and setup your PI the old fashion way!

NOTE: Make sure your Bluetooth dongle is plugged from here on.

NOTE: The default login is pi and the password is raspberry.

Step 3: Install Prerequisite Packages

Picture of Install Prerequisite Packages

Okay now that we’re all logged, connected to the Internet, and ready to go let’s go ahead and install all the packages so that Bluetooth can be utilized on your PI.

sudo apt-get upgrade

sudo apt-get install bluez pulseaudio-module-bluetooth python-gobject python-gobject-2 bluez-tools

Step 4: Modify Some Config Files to Enable Our Bluetooth Environment

Picture of Modify Some Config Files to Enable Our Bluetooth Environment

First, let’s go ahead and add our user pi to the Pulse audio group so we the user can play audio through it.
sudo usermod –a –G lp pi

Now, let’s go ahead and enable A2DP in our Bluetooth configuration. Run the following command:
sudo nano /etc/bluetooth/audio.conf

This will open the text editor nano with that config file. Add the follow text under [General]:
Enable=Source,Sink,Media,Socket

Hit CTRL+O and ENTER to save and then CTRL+X to exit nano. Next, let’s modify the Pulse daemon configuration file to change its resampling method.

sudo nano /etc/pulse/daemon.conf

Look for the following line: resample-method = speex-float-3

If the line doesn’t have a ; in front of it, please put a ; there so it looks like:
; resample-method = speex-float-3

And then add the following line underneath that.
resample-method = trivial

Before moving on, let’s also go ahead and rename our Bluetooth device (odds are you don’t want the name to be raspberry-pi0) as well as redefine the Bluetooth class device from 'Computer' to 'Portable audio device'. There are two locations you should modify.

sudo nano /etc/bluetooth/main.conf

Change the Name parameter. I chose to do a play on the BeatsByDre.
Name = BeatsByDan

Change the device's Class parameter.
Class 0x20041C

Next, you’ll have to modify the config of your specific device. The directory is based on your Bluetooth device’s MAC address so just hit TAB when typing that out and you’ll find yours.

sudo nano /var/lib/bluetooth/<bluetooth mac address>/config

Edit the name directive again.
name BeatsByDan

And the device class...
class 0x20041C

Go ahead and save and exit.

Step 5: Setup the Script That Gets Executed When a Bluetooth Device Connects

Picture of Setup the Script That Gets Executed When a Bluetooth Device Connects

Now that we have our Bluetooth environment setup, let’s go ahead and begin the process of automating Bluetooth connections and routing them to audio for us.

Let’s first setup a rule in our udev that states that whenever a device connects, our script will get executed. Run the following command to open the udev rules list.

sudo nano /etc/udev/rules.d/99-input.rules

There should be just a single line there that looks like:
SUBSYSTEM=="input", GROUP="input", MODE="0660"

Underneath it, let’s go ahead and add the following line:
KERNEL=="input[0-9]*", RUN+="/usr/lib/udev/bluetooth"

Save and exit.

Now let’s actually save that script that the above rule file is referencing. First check to see if a udev/ directory exists. Do sudo ls –la /usr/lib/udev . If it doesn’t exist go ahead and create it like so: sudo mkdir /usr/lib/udev

sudo nano /usr/lib/udev/bluetooth

Copy and paste (or type it out if you’re unlucky) the following script into your terminal.

NOTE: I did not write this script alone. I found it during research (why reinvent the wheel if not needed) and modified it to work the way I needed it to in order to be as friendly as possible, Bluetooth-wise.

#!/bin/bash
#change if you don't use default analog audio out.
#THIS DIDN'T WORK FOR MY PI SO I ADDED A amixer COMMAND BELOW
AUDIOSINK="alsa_output.platform-bcm2835_AUD0.0.analog-stereo"
echo "Executing bluetooth script...|$ACTION|" >> /var/log/bluetooth_dev

ACTION=$(expr "$ACTION" : "\([a-zA-Z]\+\).*")
if [ "$ACTION" = "add" ]
then

# Turn off BT discover mode before connecting existing BT device to audio
hciconfig hci0 noscan

# set the audio output to the analog
# COMMENT THIS LINE OUT IF YOU WANT TO OUTPUT AUDIO THROUGH HDMI
amixer cset numid=3 1

# Set volume level to 100 percent

amixer set Master 100%
pacmd set-sink-volume 0 65537


   for dev in $(find /sys/devices/virtual/input/ -name input*)
   do
      if [ -f "$dev/name" ]
      then
         mac=$(cat "$dev/name" | sed 's/:/_/g')
         bluez_dev=bluez_source.$mac

         sleep 1

         CONFIRM=`sudo -u pi pactl list short | grep $bluez_dev`
         if [ ! -z "$CONFIRM" ]
         then
            echo "Setting bluez_source to:  $bluez_dev" >> /var/log/bluetooth_dev
            echo pactl load-module module-loopback source=$bluez_dev sink=$AUDIOSINK rate=44100 adjust_time=0 >> /var/log/bluetooth_dev
            sudo -u pi pactl load-module module-loopback source=$bluez_dev sink=$AUDIOSINK rate=44100 adjust_time=0 >> /var/log/bluetooth_dev
         fi
      fi
   done
fi

if [ "$ACTION" = "remove" ]
then
# Turn on bluetooth discovery if device disconnects
sudo hciconfig hci0 piscan
fi


Save and exit! Now let’s modify the permissions of the file to make it executable.

sudo chmod 774 /usr/lib/udev/bluetooth

Great! Your Raspberry PI is now capable of playing Bluetooth audio via A2DP! Whoo! Now let’s take it a step further by turning on discovery mode and auto accepting connections right when the PI logs into the command line automatically.

Step 6: Automating Bluetooth Discovery and Auto Accepting Connections

Picture of Automating Bluetooth Discovery and Auto Accepting Connections

In order to achieve this, we’ll need to create an init script that will execute when the PI is booted up. Let’s do that!

sudo nano /etc/init.d/bluetooth-agent

Go ahead and copy this script into the text editor. Again, I found this script originally and then improved it to suit my needs!

### BEGIN INIT INFO
# Provides: bluetooth-agent
# Required-Start: $remote_fs $syslog bluetooth pulseaudio
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Makes Bluetooth discoverable and connectable to 0000
# Description: Start Bluetooth-Agent at boot time.
### END INIT INFO
#! /bin/sh
# /etc/init.d/bluetooth-agent
USER=root
HOME=/root
export USER HOME
case "$1" in
start)
echo "setting bluetooth discoverable"
sudo hciconfig hci0 piscan
start-stop-daemon -S -x /usr/bin/bluetooth-agent -c pi -b -- 0000
echo "bluetooth-agent startet pw: 0000"
;;
stop)
echo "Stopping bluetooth-agent"
start-stop-daemon -K -x /usr/bin/bluetooth-agent
;;
*)
echo "Usage: /etc/init.d/bluetooth-agent {start|stop}"
exit 1
;;
esac
exit 0


Save and exit nano.This script basically is just a standard start/stop script for Bluetooth discoverability.

Go ahead and give the script execute permissions and then add it to the list of programs that start on start-up.

sudo chmod 755 /etc/init.d/bluetooth-agent

sudo update-rc.d bluetooth-agent defaults

Step 7: Setup the Command-line to Auto-login

Picture of Setup the Command-line to Auto-login

Everything is *almost* setup! For some reason Pulse audio won’t keep the stream alive unless you’re logged into the console! Lame! We want a headless, auto setup, right? Well, let’s adjust the environment so that we have a passwordless login at boot!

Let’s edit the inittab now.

sudo nano /etc/inittab

Find this line:

1:2345:respawn:/sbin/getty 115200 tty1

And comment it out, like so:

#1:2345:respawn:/sbin/getty 115200 tty1

Now add this line right below it:

1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1

Save and exit nano.  Finally, powercycle your Raspbery Pi!

sudo reboot

Step 8: Conclusion

Picture of Conclusion

If you did everything correctly, you should now have an awesome A2DP Bluetooth receiver that plays audio out the Analog sound jack. You can now easily add a battery pack, a GIANT speaker, and PARTY wirelessly! : )


Creating a portable audio system

I won't go into the actual process of making the Pi portable. I'm assuming that if you're smart enough to find your way to this tutorial that you're also smart enough create an enclosure, get a battery, and figure out your speaker size needs. =]

I personally used the equipment in the picture above as a test while developing the software components. I am getting a sizable rear car speaker, an amplifier, a large battery pack for my system.  I'm also building a custom enclosure to house it all. I will be buying a Pi just for the system and screw into the inside of the body of the enclosure.

As for the enclosure itself, I haven't decided whether to make it from wood or plastic or even a 3D printing option. If anyone comes up with anything worth while please post a pic in the comment section below. Thanks!


I welcome any suggestions or improvements to this guide. Please email me at danielg@danielgillespie.net.

Regards,
Daniel Gillespie

NOTE: You should unplug any other USB devices so that just the Bluetooth dongle is there (unless you have a powered USB hub). If you see your Raspberry Pi via Bluetooth but are unable to successfully pair, this may be the reason. Your adapter may have enough power to work but not enough to work as it should.

NOTE: iOS devices seem to connect just fine to the receiver from the get go however I've seen some Android devices have a little trouble. If you're using an Android smartphone and it isn't playing audio through the receiver after connecting, try unpairing and pairing again. It seemed to work for my friends' Android devices!

Final Note:  Only connect one device at a time and disconnect it before attempting to connect another device. Should work flawlessly. :]

IF YOU FOUND THIS GUIDE USEFUL LET ME KNOW! Also, check out my iPhone app, CalcMate:
https://itunes.apple.com/us/app/calcmate/id538650487?mt=8


Troubleshooting

In the event that the Bluetooth device may not be connecting correctly, you can see when a Bluetooth device is added/removed from the Pulse audio system in real-time by using the following command:

tail -f /var/log/bluetooth_dev

Comments

mohtaprashantrocks (author)2017-07-21

would it be possible to add a microphone for taking phone calls ?

BrianHwang (author)2016-01-31

Thanks for your wonderful posting.

But I have some error while following your writing.

I am using Raspbian jessie.

Whenever I tried to register the service, I met this error.

pi@raspberrypi ~ $ sudo update-rc.d bluetooth-agent defaults
insserv: Service pulseaudio has to be enabled to start service bluetooth-agent
insserv: exiting now!
update-rc.d: error: insserv rejected the script header

Also I have installed 'pulseaudio'.

pi@raspberrypi ~ $ sudo apt-get install pulseaudio
Reading package lists... Done
Building dependency tree
Reading state information... Done
pulseaudio is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

This is my scrpt header of '/etc/init.d/bluetooth-agent'.
# Required-Start: $remote_fs $syslog bluetooth pulseaudio

# Required-Start: $remote_fs $syslog bluetooth
If I change the header like above by omitting 'pulseaudio', 'sudo update-rc.d bluetooth-agent defaults' doen't make any error. But the bluetooth-agent service doesn't start at boot time of my Raspbian.

How can I fix my problem? Please help me. Thank you very much.
-from Brian

bigyosu (author)BrianHwang2016-02-25

I have the same issue, don't know how to fix it....

pip773 (author)bigyosu2017-07-05

Hi, I'm getting this exact same problem and i cannot figure it out for the life of me, Anyone got any advice?

SewerynC (author)BrianHwang2016-07-16

change the first line to:
#!/bin/sh

BaReinhard (author)2017-02-16

For those wanting an updated version that works with the Latest Raspbian and includes AirPlay use the following repo and follow the instructions in the README.md

https://github.com/BaReinhard/Raspberry-Pi-Audio-Receiver-Install-Car-Install


If there are any issues feel free to let me know or open an issue on the repo

BaReinhard (author)BaReinhard2017-02-27

The Repo has been moved to the following location:

https://github.com/BaReinhard/Super-Simple-Raspber...

RabbitlL (author)2016-03-28

I succeeded config raspberryPi 3 with bluetooth audio last night.

There are something new in raspberryPi 3 with newest operate system, in pure command environments.

I've recorded all the processes https://github.com/jobpassion/raspberryPi/blob/mas...

smaxfish (author)RabbitlL2016-04-25

I followed your instruction and it worked! But the sound quality is terrible. Is there a way to improve it?

sspence (author)smaxfish2016-12-19

Maybe you can use I2S output instead of the analog?

https://www.adafruit.com/products/3006

charlfasching (author)smaxfish2016-10-18

I've also done much research on this, it seems the Digital to Analog Converter on the Pi that is used to create the sound is not that great, seems like high sound fidelity was not a big concern when creating the Pi. You will have to either live with it or get something like HiFiBerry, which is a High Fidelity Audio Hat for the Pi with RCA output.

cdnr1 (author)smaxfish2016-10-02

did you find a solution?

smaxfish (author)RabbitlL2016-04-25

Many thanks!

RichardL251 (author)2016-11-19

Hello

Thanks for all this usfull info. I wonder if any one here can help me make my Bluetooth device connect with my bt headphones whenever they are on. And If off then use standard alsa audio out ?

cdnr1 (author)2016-10-02

can some 1 show me how to get it working i followd rabbitILs tutorial but that's realy bad quality please help

Official_sniff122 (author)2016-08-29

doesn't work for me, i am running raspbian jessie, i can not see the bluetooth device on an android phone or an ipod touch

DanielR404 (author)2016-07-22

Instead of setting up an auto-login, you can configure pulseaudio to not exit after a default time:

1. Go to /etc/pulse/daemon.conf

2. Replace the line

; exit-idle-time = 20

with

exit-idle-time = -1

This way, pulseaudio will keep the stream alive. (-1 is used as a placeholder for an infinite amount of time)

snoop911 (author)2016-07-10

Is it possible to transmit from one rpi to another? Or, even better, can the rpi send audio to an android for playback?

From what I've seen,

http://stackoverflow.com/questions/21104611/how-to-modify-androids-bluetooth-stack-to-enable-a2dp-sink#_=_

the bt stack on the android doesn't support a2dp sinking? But maybe things have changed recently... I wouldn't mind using a different bt profile (HFP or HSP ) in order to achieve this!

https://www.raspberrypi.org/forums/viewtopic.php?t...

StéphaneR19 (author)2016-06-15

Is it working on Rapsberry pi 3 ?

shrikrishnakatore (author)2016-05-27

sudo apt-get install bluez pulseaudio-module-bluetooth python-gobject python-gobject-2 bluez-tools

I get Error:

Errors were encountered while processing:
libapache2-mod-php7.0
E: Sub-process /usr/bin/dpkg returned an error code (1)

Score8 (author)2015-05-13

Don't Work for Me ! My Phone can connect, but no sound.

Any Solutions ?

ŽanK (author)Score82015-05-23

this wirks for me, but i need to run it manually everytime i power up RPi

try this, but you need to type this in everytime you turn off RPi, i am still looking for solution

type

pactl list sources short

(you should get)

0 alsa_output.platform-bcm2835_AUD0.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED

1 bluez_source.B8_C6_8E_52_E8_CA module-bluetooth-device.c s16le 2ch 44100Hz SUSPENDED

than type

pactl list sinks short

(you should get)

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

type (replace your own bluez_source and alsa_output)

pactl load-module module-loopback source=bluez_source.B8_C6_8E_52_E8_CAsink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo

JichunQ (author)ŽanK2016-05-03

Hi ZanK, thanks very much for the info. I solved the problem that the command had to be run every time manually.

type the command:

sudo nano /usr/lib/udev/bluetooth

then comment out two lines from:

mac=$(cat "$dev/name" | sed 's/:/_/g')

bluez_dev=bluez_source.$mac

to

#mac=$(cat "$dev/name" | sed 's/:/_/g')

#bluez_dev=bluez_source.$mac

finally add a new line, which is the specific MAC address of your bluetooth module:

bluez_dev=bluez_source.C4_07_2F_74_52_E9

C4_07_2F_74_52_E9 is the MAC address of my bluetooth module. Give a try, it should work.

TomC46 (author)ŽanK2015-08-24

Thanks, this worked for me, you are right, I need to run it every single time I reconnect the BT:

pi@raspberrypi ~ $ pactl list sources short

0 alsa_output.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED

1 bluez_source.B8_E8_56_BA_48_2D module-bluetooth-device.c s16le 2ch 44100Hz SUSPENDED

TomC46 (author)TomC462015-08-25

I forgot this part:

pi@raspberrypi ~ $ pactl load-module module-loopback source=bluez_source.B8_E8_56_BA_48_2D sink=alsa_output.0.analog-stereo

KhelanM1 (author)TomC462015-11-02

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 - "pi@raspberrypi ~ $ pactl load-module module-loopback source=bluez_source.B8_E8_56_BA_48_2D sink=alsa_output.0.analog-stereo")? And do connect automatically?

tallnuttphone (author)TomC462015-09-03

I just get 'connection refused' from this. :(

RodolfoF (author)Score82015-05-14

I'm having the same exact problem.

cavalier0000 (author)RodolfoF2016-05-02

I found the problem.

In the instructions, we may be adding the rules to the wrong file. For instance, mine did not have 99-inputs.rules but instead its 99-com.rules. I added that additional line to that file instead and it works without needing to type the load-module instruction.

BlahBlahBlase (author)Score82015-05-13

Did you Ty pushing audio out the 3.5mm jack in raspi-confit?

how do you do this?

Score8 (author)BlahBlahBlase2015-05-14

Yes, and i See My phone into capture device, i think Pulse don't work with new versions, or the script don't work

Siedelsack. (author)2016-04-14

Pin code to pair was 0000

sekn-dev (author)2016-03-24

I am running a Pi MusicBox 0.6.0 and cant get pulse audio to work.

After pactl load-module module-loopback i get error module initialization failed or module connection refused

But parecord and aplay seems to work very well.

here is my bluetooth script, the pi user needs to be in the audio group

http://pastebin.com/BFVUtSpu

BaReinhard (author)2016-03-19

Also with the new raspbian updates is this still possible by using this same tutorial?

RobertD141 (author)BaReinhard2016-03-22

Hey,
it didn't work for me with the latest raspbian jessie. I took wheezy from 05-05-2015 and it worked.

You can get it here:

http://downloads.raspberrypi.org/raspbian/images/

BaReinhard (author)2016-03-19

Also with the new raspbian updates is this still possible by using this same tutorial?

BaReinhard (author)2016-03-19

I'm missing the audio.config file what do I need in there for it to work?

RobertD141 (author)2016-03-13

Hi everyone

Thanks to dan for this nice tutorial and also a big thanks to gliuzzo for his troubleshooting.

I run a RPi B+ with Wheezy 05-05-2015 and the bluetooth audio thing works great...the first ten minutes.

Audio quality is fine and so on but after a while (about 10 to 15 minutes) i get a echo in the music that makes me crazy. The longer i let the music play, the more echo sound i hear. After a reboot of the Pi everything works again as it should.

Anyone else got that problem?

I tried the Echo/Noise-Cancellation as described in

https://wiki.archlinux.org/index.php/PulseAudio/Tr...

but after making this, the RPi doesnt play music anymore...why? I dont get it.

Anyone gut suggestions? Thanks in advance
Robert

Franklindee (author)2016-02-17

Hi all i was tryng to make it but seems that this guide is too old for the new bluez 5 and pulse audio version infact some of the file are missing or the name is changed, could you please update the guide so i can made it?

a big thank you

ChristianM85 (author)2016-01-09

Hi Guys,

this tutorial is working great, but after disconnecting with any device its not possible to connect whit an other device. So i made a little script that restart the bluetooth service after a disconnect. This works fine and now i can play sound from any device at any time.

Here the details:

-> sudo touch /usr/local/bin/bluewatch.sh

-> sudo nano /usr/local/bin/bluewatch.sh

-> add this and save

________________

#!/bin/bash

tail -f -n0 /var/log/bluetooth_dev |grep --line-buffered "|remove|" | while read line; do sleep 3; /etc/init.d/bluetooth restart ; sleep 2; /etc/init.d/bluetooth-agent start ;done

________________

-> sudo chmod 775 /usr/local/bin/bluewatch.sh

-> sudo nano /etc/rc.local

-> Insert this line directly above "exit 0" :

________________

/usr/local/bin/bluewatch.sh &

________________

-> Save the file and close nano.

-> Reboot your PI

Thats all.

Nheliteuf (author)ChristianM852016-01-30

Hi ChristianM85,

Following your post: as we say in France: " Je ne t'embrasse pas, mais le coeur y est!"

A big big thank you!

gliuzzo (author)2015-03-26

Hi guys! I Made it!

It works nice, but I had some problems. These:

sudo usermod –a –G lp pi doesn't found

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

output audio doesn't work

in this file: /usr/lib/udev/bluetooth :

Replace this line:

AUDIOSINK="alsa_output.platform-bcm2835_AUD0.0.analog-stereo"

With this:

AUDIOSINK="alsa_output.0.analog-stereo"

output audio after 20 seconds stopped

Edit daemon configuration:

sudo nano /etc/pulse/daemon.conf

Change

; exit-idle-time 20

to

exit-idle-time -1

bluetooth devices doesn't connect

this is a proble about auto-login in tty1; I resolved this re-writing the /etc/inittab file like this, from:

#1:2345:respawn:/sbin/getty 38400 tty1
1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3

4:23:respawn:/sbin/getty 38400 tty4

5:23:respawn:/sbin/getty 38400 tty5

6:23:respawn:/sbin/getty 38400 tty6

to:

1:2345:respawn:/sbin/getty 38400 tty6
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
#6:23:respawn:/sbin/getty 38400 tty6
6:23:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1

Enjoy!! Thanks @dantheman_213

Finally, this is my 5+1 Hi-Fi with bluetooth receiver :)

I'll upload a video tomorrow :)

yohtm (author)gliuzzo2015-12-28

Your comment made my setup finally work, thanks!

Lars BoR (author)gliuzzo2015-06-14

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

ironsand (author)gliuzzo2015-03-27

>1° sudo usermod –a –G lp pi doesn't found

Ya, I have a same error and found the cause of it.

`–` are not same with `-`!

Maybe the character are replaced by instructables's system.

TheCyberzwerg (author)2015-12-27

I also added a two lines to play a sound when connecting and disconnecting:

This requires a connected and disconnected wav file in the /etc/bluetooth-sounds directory. Thanks to the OP, I love it!


For connect sound:



sudo -u pi pactl load-module module-loopback source=$bluez_dev sink=$AUDIOSINK rate=44100 adjust_time=0 >> /var/log/bluetooth_dev

omxplayer /etc/bluetooth-sounds/connected.wav



For disconnect sound:


if [ "$ACTION" = "remove" ]
then
# Turn on bluetooth discovery if device disconnects
sudo hciconfig hci0 piscan

omxplayer /etc/bluetooth-sounds/disconnected.wav
fi

ds00424 (author)2015-12-22

NICE writeup. Thanks for posting.

I got it working but had sporadic popping noises even when not playing anything. The following seemed to fix the issue (well at least for the last 24 hrs - which is good).

From: https://dbader.org/blog/crackle-free-audio-on-the-...

Edit /etc/pulse/default.pa and remove or comment outload-module module-suspend-on-idle. This is the important part that prevents PulseAudio from sending the audio hardware to sleep. I’ve read that simply using PulseAudio lessened the problem for some people. But on my Pi only disabling idle suspend really helped.

Also some other info here: https://wiki.archlinux.org/index.php/PulseAudio/Tr...

HTH.

shubh22man (author)2015-09-21

Hey guys! I am using HC-05 Bluetooth module and have seem to stuck on step 4.

I can't seem to understand the line "sudo nano /var/lib/bluetooth/<bluetooth mac address>/config."

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.

LucasK6 (author)shubh22man2015-10-28

I found the MAC address using this command: hcitool dev

About This Instructable

848,313views

422favorites

License:

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