bondjames12
Posts: 7
Joined: Sat Feb 16, 2013 3:22 pm

A2DP Sink Pre-built RPI Image

Sat Feb 16, 2013 4:05 pm

With this RPI image (based on Occidentalis V0.2) you can use your RPI as an A2DP sink.

Software Included and pre-configured:
  • Bluez 4.99
    Pulseaudio
    DBus
    Several python scripts:
    • python daemon (runs on boot) to accept Bluetooth pairing requests via DBus
      python daemon (runs on boot) that listens for Bluez and Pulseaudio DBus events to configure BT/Pulseaudio audio sources when a device connects/disconnects.
      python script (crontab run every minute) to connect to paired Bluetooth devices if there's nothing connected
Whats required:
  • Raspberry Pi
    SD card at least 3GB image is 3,093,299,200 bytes)
    USB Bluetooth adapter (that works with linux/RPI)

Download
Contained in the following archive is an SD card image.
http://www.mediafire.com/?c7acv8vcdwxvq
Download all 5 parts, use 7zip http://www.7-zip.org/download.html to combine and and uncompress the image.

In the event there is file corruption since this is a large file you can use the provided par files with a program such as http://www.quickpar.org.uk/Download.htm repair the archive.

Instructions:
  • Download, Combine, and uncompress the image
    Write to a suitable SD card. (Win32Imager (https://launchpad.net/win32-image-writer or DD)
    Boot RPI
    Connect speakers or headphones to RPI
    Pair your BT A2DP source with RPI
    If you have problems connecting after you first pair your device, reboot RPI by cycling the power (sometimes required but only once)

I'm just sharing what I've been working on. I'm using it in my vehicle to stream music to my stereo. Hopefully this is enough instruction for anyone interested in trying this out.

Some problems I've had:
  • The RPI I have this working on uses a MSI BT Adapter, I have another Asus BT adapter which doesn't seem to work in the RPI but gives many weird USB errors
    Bluez service sometimes needs to be restarted after pairing a new device before it will be able to connect and stream audio. (easier just to reboot the OS or cycle the power)
    The crontab I setup to automatically run every minute to try and connect to all paired A2DP sources might be causing some BT disconnects if there is already a device connected, although I haven't confirmed this.

yogimaster2k
Posts: 4
Joined: Tue Feb 19, 2013 4:41 am

Re: A2DP Sink Pre-built RPI Image

Tue Feb 19, 2013 4:46 am

Hi and thank you for this! I am getting audio out from the headphone jack (which I know was your intent), but is there a way to change the default audio out back to HDMI? I am very new to all of this and wasn't able to solve this on my own. Thanks again!

bondjames12
Posts: 7
Joined: Sat Feb 16, 2013 3:22 pm

Re: A2DP Sink Pre-built RPI Image

Wed Feb 20, 2013 5:29 pm

There is some useful information about this OS I forgot to mention:

DHCP is enabled on boot (ifplugd), RPI should get an IP when Ethernet is connected.

SSH daemon (sshd OpenSSH_6.0p1 Debian-2, OpenSSL 1.0.1c 10 May 2012) is enabled on boot
username: root
password: root

The copies of any changed configuration files and the custom python scripts are stored in: /root/config_files/
  • /root/config_files/
  • [list]
  • /root/config_files/bin/
  • a2dp_connect.py - Tries to connect all paired A2DP sources bt-pairing-daemon.py - Automatically responds to Bluez pairing requests (pairs with everything) bluez_pulse-dbus-daemon.py - Registers for Bluez Dbus events and loads a pulseaudio loopback module when a A2DP source connects, also writes some debug information to a log file. pulse_audio-volume.py - Sets audio output volume via pulseaudio and dbus to maximum or to something specified on commandline eg: python pulse_audio-volume.py <volumelevel0-65536>
  • /root/config_files/bluetooth/ - Copies of bluez configuration files (actual files in /etc/bluetooth)
  • /root/config_files/dbus/ - Copies of changed dbus configuration files (actual files in /etc/dbus-1/)
  • /root/config_files/pulse/ - Copies of changed pulseaudio configuration files (actual files in /etc/pulse/)
  • /root/config_files/startup_scripts/ - Copies of init.d scripts used to start bt-pairing-daemon.py and bluez_pulse-dbus-daemon.py (actual files in /etc/init.d)
[/list]

bondjames12
Posts: 7
Joined: Sat Feb 16, 2013 3:22 pm

Re: A2DP Sink Pre-built RPI Image

Wed Feb 20, 2013 6:29 pm

yogimaster2k wrote:Hi and thank you for this! I am getting audio out from the headphone jack (which I know was your intent), but is there a way to change the default audio out back to HDMI? I am very new to all of this and wasn't able to solve this on my own. Thanks again!
yogimaster2k, I looked into your question:

Run command:
amixer -c 0 cset numid=3 '2'
This should switch alsa audio outout from the headphone jack to HDMI.

To switch audio back:
Auto: amixer -c 0 cset numid=3 '0'
headphone jack: amixer -c 0 cset numid=3 '1'
HDMI: amixer -c 0 cset numid=3 '2'

If it doesn't work you might need to force some HDMI options:
edit /boot/config.txt and add

To force a HDMI mode rather than DVI. This can make audio work in DMT (computer monitor) modes add:
hdmi_drive=2

To force a specific HDMI mode:
add:
hdmi_mode=4

List of HDMI modes are here:
http://elinux.org/RPiconfig

yogimaster2k
Posts: 4
Joined: Tue Feb 19, 2013 4:41 am

Re: A2DP Sink Pre-built RPI Image

Wed Feb 20, 2013 8:46 pm

This looks great! I'm at school right now, but I'll try it out when I get home. Thanks!

gftstf
Posts: 1
Joined: Sun Feb 24, 2013 11:39 am

Re: A2DP Sink Pre-built RPI Image

Sun Feb 24, 2013 11:54 am

So far works best of all the A2DP receiver recipes one can google up. However I'm still getting random glitches on my 256 MB model B once a minute or two.

Is anyone else experiencing this kind of problem?

bondjames12
Posts: 7
Joined: Sat Feb 16, 2013 3:22 pm

Re: A2DP Sink Pre-built RPI Image

Sun Feb 24, 2013 4:29 pm

I'd recommend removing the crontab I set-up. It runs every minute and it looks like it can sometimes cause the glitches.

yogimaster2k
Posts: 4
Joined: Tue Feb 19, 2013 4:41 am

Re: A2DP Sink Pre-built RPI Image

Mon Feb 25, 2013 5:18 pm

Sorry I've been busy with school stuff. I tried your recommendations but I still can't get audio out via HDMI. Is it possible that one of your changes prevents the drivers for the HDMI audio from being loaded at startup? I installed pavucontrol in order to see what was going on with a GUI and the only output available is the analog output.

yogimaster2k
Posts: 4
Joined: Tue Feb 19, 2013 4:41 am

Re: A2DP Sink Pre-built RPI Image

Mon Feb 25, 2013 11:06 pm

Well I got it working. I'm not sure what I did but after trying the same settings a few times it finally worked!

bondjames12
Posts: 7
Joined: Sat Feb 16, 2013 3:22 pm

Re: A2DP Sink Pre-built RPI Image

Tue Feb 26, 2013 4:28 am

yogimaster2k wrote:Well I got it working. I'm not sure what I did but after trying the same settings a few times it finally worked!

I also had to mess around a bit. First I had a problem with my HDMI modes not being right, then I was only testing with a short sound file and the TV audio apparently is muted until it detects audio and automatically unmutes itself my sound test was too short I couldn't hear it! But yes it does work once you get the settings all worked out.

Delacor
Posts: 2
Joined: Thu Nov 03, 2011 8:43 pm

Re: A2DP Sink Pre-built RPI Image

Mon Apr 15, 2013 10:24 pm

Love this! Working like a charm! Keep doing this! :mrgreen:

sgkini
Posts: 16
Joined: Thu Jan 19, 2012 1:07 pm

Re: A2DP Sink Pre-built RPI Image

Sat Apr 20, 2013 4:56 pm

Hi,
Wanted to know if you plan to use AVRCP to control media playback or is it already part of the image ?

Satish

bondjames12
Posts: 7
Joined: Sat Feb 16, 2013 3:22 pm

Re: A2DP Sink Pre-built RPI Image

Tue Apr 23, 2013 11:33 am

sgkini wrote:Hi,
Wanted to know if you plan to use AVRCP to control media playback or is it already part of the image ?
Satish
I've finished work on this. But you can add AVRCP functionality using the existing Bluez Dbus interface and a python script.

bdejong
Posts: 4
Joined: Thu May 02, 2013 12:12 pm

Re: A2DP Sink Pre-built RPI Image

Thu May 02, 2013 12:18 pm

bondjames12,

Does that image contain all the latest scripts you used? I'm quite interested in using and extending your version, but I'd rather just figure out all the changes you did so I can reproduce/edit/emhance for my particular usage. Knowing what exactly you changed (from the raw image) would be cool too. You mention you set up DHCP etc, I'm wondering if you have a list of all the files you changed. Doing a diff between two images will be a bit tedious :-)

Also, what bluetooth dongle would you recommend - seeing you have had some trouble with the ones you own...

- bram

danielg466
Posts: 3
Joined: Sun May 05, 2013 10:21 pm

Re: A2DP Sink Pre-built RPI Image

Sun May 05, 2013 10:25 pm

I have installed this image onto my Raspberry Pi but after I boot the Pi and login I go to my iPhone 5 and turn on bluetooth but the Pi never shows up in my device's Discovery List. My bluetooth dongle appears to be working normally. It shows up in lsusb, hcitool scan reveals my iPhone but I can't seem to get the device into discovery mode.

I want the Pi to behave like a Beats By Dre or any other portable audio system. Where when you power it on it immediately goes into discover mode and any bluetooth a2dp device can connect and play music through the audio connection.

danielg466
Posts: 3
Joined: Sun May 05, 2013 10:21 pm

Re: A2DP Sink Pre-built RPI Image

Sun May 12, 2013 9:02 pm

I never could get this to work as it was supposed to! And since nobody really helped me out I helped myself out and wrote a guide on how to make a self-contained A2DP bluetooth receiver. Please check it out here:

http://www.instructables.com/id/Turn-yo ... uetooth-A/

doppelkeks
Posts: 1
Joined: Fri May 17, 2013 6:06 pm

Re: A2DP Sink Pre-built RPI Image

Fri May 17, 2013 6:11 pm

I am very interested on this image, but my raspi did not boot with this image.
I wrote it with diskimager.
What can I do?

thanks a lot

edit: I copied the boot folder of a working copy and now it's booting.

I want to use my raspi as music server and I want to stream via blootooth to my car radio.
Is this possible with your image?

Delacor
Posts: 2
Joined: Thu Nov 03, 2011 8:43 pm

Re: A2DP Sink Pre-built RPI Image

Fri May 24, 2013 9:49 pm

danielg466 wrote:I never could get this to work as it was supposed to! And since nobody really helped me out I helped myself out and wrote a guide on how to make a self-contained A2DP bluetooth receiver. Please check it out here:

http://www.instructables.com/id/Turn-yo ... uetooth-A/
THIS is soo awesome!!

fireside
Posts: 6
Joined: Tue Mar 26, 2013 4:40 pm

Re: A2DP Sink Pre-built RPI Image

Wed Sep 04, 2013 8:55 pm

Thank you this is great!

RandomLlama
Posts: 1
Joined: Mon Sep 16, 2013 8:07 pm

Re: A2DP Sink Pre-built RPI Image

Mon Sep 16, 2013 8:13 pm

bondjames12 wrote:
sgkini wrote:Hi,
Wanted to know if you plan to use AVRCP to control media playback or is it already part of the image ?
Satish
I've finished work on this. But you can add AVRCP functionality using the existing Bluez Dbus interface and a python script.
Any chance you would share your work on this?

bondjames12
Posts: 7
Joined: Sat Feb 16, 2013 3:22 pm

Re: A2DP Sink Pre-built RPI Image

Tue Sep 17, 2013 1:07 am

It is all shared, read the first post. AVRCP was never added if thats what you were referring to.
RandomLlama wrote:
bondjames12 wrote:
sgkini wrote:Hi,
Wanted to know if you plan to use AVRCP to control media playback or is it already part of the image ?
Satish
I've finished work on this. But you can add AVRCP functionality using the existing Bluez Dbus interface and a python script.
Any chance you would share your work on this?

Devfarse
Posts: 9
Joined: Sat Dec 08, 2012 1:44 am

Re: A2DP Sink Pre-built RPI Image

Thu Sep 26, 2013 4:46 pm

This is great, I just posted in another thread about seeing if anyone got the automatic reconnect working so it's pretty awesome to have found your solution.

A couple of things I had to do were to make sure everything was working and enabled.

The sudo commands below aren't necessary because this application is root but useful for other users using a non root login.

These are excerpts from a how to guide I have made for myself through lots of experimenting. The inittab lines will vary some however the code I recommend inserting works.

1 Make computer discoverable

Code: Select all

sudo hciconfig hci0 piscan
2 Change the class of device

Code: Select all

sudo nano /etc/bluetooth/main.conf
Change the device's Class parameter.
Class 0x200420

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

And the device class...
class 0x200420
This code represents car audio per bluetooth specs

And automatic login to the command line for headless setups so that pulse audio starts.

Code: Select all

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 root tty1 </dev/tty1 >/dev/tty1 2>&1

Save and exit nano.

storealutes
Posts: 3
Joined: Tue Oct 29, 2013 12:36 am

Re: A2DP Sink Pre-built RPI Image

Sun Jan 12, 2014 12:55 pm

After adding a startup script that makes my bluetooth discoverable this image works seamlessly playing audio for as long as I want; stopping pairing another device and playing from there as well, but after a reboot I no longer get audio. I can connect still and even forget device and pair again but when I hit play its just silence after the reboot.

Here is the only command besides an echo in my added startup script which works great.

Code: Select all

hciconfig hci0 piscan
I also changed the bluetooth class to 0x20041c in the ~/config_files/bluetooth/main.conf, /etc/bluetooth/main.conf and /var/lib/bluetooth/ [mac address] /config. There was two mac addresses in the var/lib/bluetooth directory I changed both. I also changed the the bluetooth name in the main.conf files and one of the mac address devices. I dont know if it was something i did or just something people have had problems with any help would be greatly appreciated.

Thanks,
Sterling Lutes

Jan 12, 2014 SOLVED!!!

Once I dd a fresh image with no altered files I found the solution. If anyone else has this problem you need to ssh or use a keyobard to login to your pi Username:root | Password:root and run the following command:

Code: Select all

rm -r /var/lib/bluetooth/00\:15\:83\:48\:30\:34/
after that with your bluetooth dongle plugged in run this code:
(hit tab after bluetooth/ to find your mac address)

Code: Select all

nano /var/lib/bluetooth/[Mac Address]/config
then in the nano editor delete all the stuff inside and paste this in place of the old settings
(You can change the name to whatever)

Code: Select all

name PiPlay
pairable yes
class 0x4e0100
onmode discoverable
mode discoverable
after this is all done run this last command and wait for your pi to reboot and it should be working

Code: Select all

reboot
*if you are not logged into root you need to sudo all of the above commands

Thanks,
Sterling Lutes

therealpanse
Posts: 1
Joined: Thu Jan 16, 2014 9:58 pm

Re: A2DP Sink Pre-built RPI Image

Thu Jan 16, 2014 10:02 pm

The Image doesn't seem to be bootable. Tried unpacking it twice, no errors on that. Also I tried to write the image twice on two different SD cards (both 8 GB Class 10). No errors there either.

idaadi
Posts: 7
Joined: Thu May 24, 2012 1:15 pm

Re: A2DP Sink Pre-built RPI Image

Sun Feb 16, 2014 9:36 pm

Dear OP,

your image works good , but I had to find out some settings:

The computer name has to be a word without special characters ( for me macbookpro , from XXX's MacbookPro) the single quote kills python a2dpconnect.py

another thing, the time was 1969 , but that was fixed with ntpdate pool.ntp.org

Thank you for the prebuilt image, I had problems/still have to figure out, to make it work in an environment without X. pulseaudio was complaining that it cannot launch without X.
but Thank you for the neat and cool file structure.

BR,
Adrian

Return to “Graphics, sound and multimedia”