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/