Edit 2017May14: Finally found a way to make it work on Raspbian Jessie distro. Please refer to this link for instructions to setup bluetooth speaker.
Hi~ Here is a small project for my new RPi B+. So i got some bluetooth peripherals lying around the house, so i thought i can make a small music box using RPi. Did some research and got it working!
So here are what you need for the hardware:
- RPi Model B+ with Raspbian Installed (Should work with model B or A)
- Bluetooth Speaker
- USB Bluetooth dongle
- USB Wifi dongle / LAN cable for internet connection
- 5V 1A/2A Power Supply
Figure6: Hardware Setup |
- "sudo apt-get update && sudo apt-get upgrade" - upgrade your Raspbian packages list to latest version. Wait for program to finish upgrade before next command.
- "sudo apt-get install bluetooth bluez bluez-utils bluez-alsa blueman" - install five packages for bluetooth dongle and bluetooth audio. Wait for installation to complete before next command.
- "sudo usermod -a -G lp pi" - this command will add "lp" group under account "pi". You account need to have access to this group for this to work. If you are using other account, just replace the "pi" in command with your account name.
- "sudo nano /etc/bluetooth/audio.conf" - you need to add some command in the audio.conf file. This command will open nano text editor and allow you to edit the file. You need to add in two line in the file. "Enable=Source,Sink,Socket" and "Disable=Media". Refer to Figure1 and Figure2 below. After edit file, press Ctrl+O and Enter to save the file.
Figure1: Editing audio.conf file - Once save the file, enter command "sudo shutdown -h -P now" to safe shutdown the Pi. Once you see green light blip for 10 times. You can turn off the power supply.
- Now plug-in your bluetooth dongle to the USB and start up your RPi.
- Wait for boot complete, go to terminal and enter command "lsusb". You should see your bluetooth dongle available as shown in Figure3. You can refer HERE for list of working bluetooth adapter for RPi in case your bluetooth dongle is not detectable.
Figure3: Bluetooth Dongle Detected in USB list - If you able to find your bluetooth dongle in USB list, you should see a Bluetooth icon at your RPi tray. If you did not boot up your Pi in GUI and you are in command line interface, enter "startx" to start your GUI session. Refer to Figure4 below to setup your bluetooth connection with your bluetooth speaker with 3 simple steps.
Figure4: Setup Bluetooth Connection with Your Bluetooth Speaker - Follow up on step 8. You can also click "Trusted" on the device as shown in Figure4 if you want to let the speaker auto connect to RPi in the future. Mine is showing "Untrust" because i've already "Trusted" this device.
- Open up terminal again to edit one last file. Enter "sudo nano ~/.asoundrc" and enter the script as shown in Figure5. For line start with "device 00:", that the place where you put your bluetooth speaker's MAC address. You can find you MAC address in Figure4. Copy and paste in to the script. Once done save the file and you are done setting up the bluetooth portion for RPi.
Figure5: Script to Connect Bluetooth to Alsa - If you completed the steps up to 10, you are almost ready. You just need to install one more package so that you RPi can play music. In this case i recommend Mplayer because it is a terminal player that can support wide range of audio format including m4a. Go to terminal and enter "sudo apt-get install mplayer" and wait for installation complete.
- Once you complete installation of mplayer. Navigate to your music folder using terminal and then enter command "mplayer -volume 10 -ao alsa:device=bluetooth youmusic.mp3" to play music.
- You should be able to listen to your music from bluetooth speaker from now.
- Here is the video showing the working bluetooth speaker using RPi.
Hope you like this tutorial. Thanks for your time!
Reference:
http://elinux.org/RPi_USB_Bluetooth_adapters
http://www.correderajorge.es/bluetooth-on-raspberry-audio-streaming/
do you know how to stream audio to wifi speakers (jongo s3) on the rpi? haven't been able to find much on the subject. it must be doable because i was able stream wifi (limited to a few apps) with my android.
ReplyDeletethanks John
Hi John, unfortunately i haven't try this yet because i don't own a wifi speaker myself. You can start searching for packages available in Linux that can enable access to your wifi speaker. Good Luck. =)
DeleteHi, nice tutorial!
ReplyDeleteIs it possible to stream online radio instead of mp3? If yes, can you tell me how?
Look great...
ReplyDeleteI will try to make this working for my Home Automation.. [ stream music to a Bt speaker... ]
Is there a option to have acces from a Http comand/.
Or acces from a lua/bash script...
My Home automation can work with this scripts an can set the player then on or off...
Like to hear [ i orderd my first pi] so i must wait ]
Actually there is a github project (pulseaudio-dlna) that streams wifi to dlna renderer speakers (such as I have). It works on Ubuntu, Linux Mint and LMDE 2 and I would imagine any linux box that runs some form of debian jessie. But it requires jessie which at the moment the RPI doesn't support (I haven't had any luck upgrading from wheezy to jessie on the pi yet). I did try running it on my goflex that runs debian jessie (armel) but it kept crashing pulseaudio. I couldn't figure out how to get pulseaudio to stay up and work correctly while pulseaudio-dlna was running.
ReplyDeleteThanks for showing how to make bluetooth speaker work with RPi! Curious what wifi and bluetooth adapters did you use?
ReplyDeleteI bought the wifi module from element14, from adafruit industries. Link below:
Deletehttp://my.element14.com/webapp/wcs/stores/servlet/ProductDisplay?catalogId=15001&langId=83&urlRequestType=Base&partNumber=2301652&storeId=10188
For the bluetooth dongle I'm using the one comes with my Samsung hands free module. I believe it is the normal Cambridge Silicon bluetooth 2.0 dongle.
Just about any bluetooth dongle that supports a2dp should work. I would suggest ver 4.0 and up either Broadcom or Cambridge Silicon Radio as Linux supports both. You should be able to purchase it on ebay for $5 and up. The following bluetooth dongle should work.
ReplyDeletehttp://www.ebay.com/itm/USB-Wireless-Bluetooth-4-0-CSR-Dongle-Adapter-Audio-Transmitter-XP-vista-win7-8-/301582691619?hash=item4637baad23
For WiFi once more any wifi dongle that supports N should work. However the dongles don't have a whole lot of range as the antenna is very short. If range and signal strength is a concern I would suggest something such as Edimax EW-7811UAC 11AC (Amazon) or similar that has a high-gain external antenna will work much better. They are a little pricey though.
CAUTION: no matter what you do be careful to always use the extension cradle with it as the connections on the dongle itself are reversed and will blow-it-out if you plug it directly into the usb port without the cradle.
The other problem with the Edimax is that you will have to build a driver for it. It wasn't easy so if you're not familiar with compiling you will probably have problems with getting it to compile without errors. Check out MrEngman's post at
https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=66499&p=779003#p779003
on how to build it. He may be willing to help you with it.
YMMV
Good luck
John
Thanks for the info and the time u took to share this project.
ReplyDeleteMy pi b+ runs only osmc (kodi) as a media player. Do you know if I can use a bluetooth dongle on the pi to play the audio from movies and series to a set of bluetooth headphones?
Thanks for this tutorial I got a RPi 2 connected to a bluetooth speaker. I followed all steps except that after step 7, I cannot see the Bluetooth icon within the GUI. Searching google lead me to an important step that appears to be missed on this guide:
ReplyDeletesudo apt-get install blueman
After I installed blueman, everything else was good.
Thanks for the feedback! Yes somehow i miss out blueman (bluetooth manager) in my post. Edited my post.
DeleteReally good tutorial. Is it possible to play ALL audio through the bluetooth speakers? Thanks
ReplyDeleteThanks for the tutorial. I'm not able to install the Bluez apps though. It tells me "E: Package 'bluez-utils' has no installation candidate" and "Package bluez-utils is not available, but is referred to by another package.
ReplyDeleteThis may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
bluez"
I tried the Bluez package but it didn't work. Any suggestions?
May i know which repo you use for your Pi? I was using wheezy Raspbian when i write this post. Not sure it will work for jessie Raspbian or not.
DeleteThis comment has been removed by the author.
Delete"sudo apt-get install bluez" is the command if you are using jessie version
DeleteHere is the full post on how to make it works on raspbian jessie. http://mygeeks014.blogspot.my/2017/05/audio-streaming-to-bluetooth-speaker.html
DeleteHi can you tell me which blotooth dongle are you using?
ReplyDeleteIts a random bluetooth dongle lying around my room. If i remember correctly it was a bluetooth dongle for my Samsung handsfree module. Based on the driver, the name is Cambridge Silicon bluetooth 2.0 dongle.
DeleteI have question does all formats can play in bluetooth speakers. Some dont have it. - Latestone.com where i bought a bluetooth speaker which has more options in speaker
ReplyDeleteIt should be able to play all audio supported by mplayer.
DeleteHave you been able to make it work under Jessie ? If so, how ?
ReplyDeleteHi Andre, It seems like the old methods are not working. I switched to PulseAudio to make it work under Jessie however, it require GUI to work. I'm still figuring out how to make it work under command line.
DeleteHere is the full post on how to make it work under Jessie.
Deletehttp://mygeeks014.blogspot.my/2017/05/audio-streaming-to-bluetooth-speaker.html
I do not run like you that music. You can help me
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
Deletehi! really thorough tutorial, much appreciated.
ReplyDeleteso i have managed to follow it through, but the song does not play,
step 12 results in a bunch of code, where these were the points that i could find:
BILITIES failed: invalid argument
failed to initialise alsa:device=bluetooth
could not open/initialise audio device-> no sound
exiting... (end of file)
Would really really appreciate any insights
May i know which distro you are using? If you are using jessie, please follow instruction in post below to make it work.
Deletehttp://mygeeks014.blogspot.my/2017/05/audio-streaming-to-bluetooth-speaker.html
Hi,
ReplyDeleteBluetooth audio streaming is no more supported by ALSA, you have to do it with PulseAudio, find a tutorial here: http://youness.net/raspberry-pi/bluetooth-headset-raspberry-pi
Great post. I was just about to create another post using PulseAudio and Bluez5. Will publish once complete =)
DeleteHere you go. http://mygeeks014.blogspot.my/2017/05/audio-streaming-to-bluetooth-speaker.html
Delete