Bluetooth A2DP receiver?


13 posts
by timboj » Sun Jun 10, 2012 5:50 pm
Hi gang,

Has anyone tried setting up their Pi as an A2DP receiver? I'd like to stream music from my phone to my Pi then out to my hifi. I've managed to do the same thing on my Ubuntu box but I'm running into problems on my Pi.

I've managed to connect to my phone like this:

sudo qdbus --system org.bluez /org/bluez/795/hci0/dev_00_23_76_9C_23_E3 org.bluez.AudioSource.Connect

Then, with pulseaudio running, connect the bluetooth source up to the alsa sink:

sudo pactl load-module module-loopback source=bluez_source.00_23_76_9C_23_E3 sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo

This appears to work ok. But as soon as I start playing music on my phone, pulseaudio crackles then dies like this:

E: alsa-sink.c: ALSA woke us up to write new data to the device, but there was actually nothing to write!
E: alsa-sink.c: Most likely this is a bug in the ALSA driver 'snd_bcm2835'. Please report this issue to the ALSA developers.
E: alsa-sink.c: We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail.

I've tried some solutions without pulseaudio, e.g. a2recv from bluetooth-alsa but can't get that to work either.

Would appreciate some help with this one.

Cheers,
Tim
Posts: 5
Joined: Sun Jun 10, 2012 5:42 pm
by b455x » Mon Jun 11, 2012 3:46 pm
I'm really sorry, I won't be able to help you...

just wanted to say that I'm very interested in doing the exact same thing, but unfortunately it seems like I received a faulty Pi.

Can you tell which Bluetooth device you are using?
Posts: 16
Joined: Sat May 19, 2012 6:40 pm
by timboj » Mon Jun 11, 2012 4:48 pm
Hi there,

It's this one:

http://www.ebay.co.uk/itm/190402008354? ... 576wt_1398

Shows up as:

pi@raspberrypi:~$ lsusb
Bus 001 Device 005: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)

Cheers,
Tim
Posts: 5
Joined: Sun Jun 10, 2012 5:42 pm
by XavM » Tue Jun 19, 2012 9:12 am
Hello,

The ALSA driver is known to be "alpha-quality" and is still a work in progress.
I guess the problem you have is related to that.
E: alsa-sink.c: ALSA woke us up to write new data to the device, but there was actually nothing to write!
E: alsa-sink.c: Most likely this is a bug in the ALSA driver 'snd_bcm2835'. Please report this issue to the ALSA developers.
E: alsa-sink.c: We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail.

----

By the way, I have the same Bluetooth dongle as yours, but I have not been able to connect any thing to it : I always have a "Kernel NULL Pointer dereference" crash as soon as I try to connect a Mouse, a Keyboard or a Telephone.

Have you been able to connect to anything, and how did you manage to do ?

-----

My CSR BT dongle (same as yours) :
pi@raspberrypi:~$ lsusb
Bus 001 Device 005: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)

HCI0 is UP and running :
pi@raspberrypi:~$ sudo hciconfig -a
hci0: Type: BR/EDR Bus: USB
BD Address: 00:1F:81:00:08:30 ACL MTU: 1021:4 SCO MTU: 180:1
UP RUNNING PSCAN
RX bytes:1066 acl:0 sco:0 events:32 errors:0
TX bytes:390 acl:0 sco:0 commands:31 errors:0
Features: 0xff 0x3e 0x09 0x76 0x80 0x01 0x00 0x80
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF PARK
Link mode: SLAVE ACCEPT
Name: 'Accel-OB2'
Class: 0x4a0100
Service Classes: Networking, Capturing, Telephony
Device Class: Computer, Uncategorized
HCI Version: 2.0 (0x3) Revision: 0x44
LMP Version: 2.0 (0x3) Subversion: 0x3
Manufacturer: Cambridge Silicon Radio (10)

I can scan and see bluetooth devices around :
pi@raspberrypi:~$ sudo hcitool scan
Scanning ...
D8:A2:5E:FA:C3:A9 MyDevice

It crashes as soon as I connect it to any thing :
pi@raspberrypi:~$ sudo hcitool cc D8:A2:5E:FA:C3:A9

At this step everything freeze and I get a nice "kernell NULL pointer" showing on the console (TV Screen) and the raspberry pi needs a hard reboot :
Unable to handle kernel NUMM pointer dereference at virtual adress 00000001
etc ...

Nothing seems to be loggeg in /var/log after a reboot

I tried with a fresh Debian stock image 20120419 where I only installed bluetooth, bluez-utils and blueman :
sudo apt-get install bluetooth bluez-utils blueman

And I tried with this same image after installing latest kernel and firmware using rppi-update, and running an apt-get update and upgrade, but I still have the same problem.:

pi@raspberrypi:~$ uname -a
Linux raspberrypi 3.1.9+ #125 PREEMPT Sun Jun 17 16:09:36 BST 2012 armv6l GNU/Linux

( I couldn't try with the new Wheezy Debian image because of this "Segmentation fault" problem starting bluetooth )

This dongle is reported to be working on the Wiki : http://elinux.org/RPi_VerifiedPeriphera ... h_adapters

Has any one been able to pair any thing to it ?
Posts: 35
Joined: Thu May 31, 2012 11:29 pm
by timboj » Tue Jun 19, 2012 10:29 am
I didn't have much luck with hcitool either. Instead, in /etc/rc.local I have this:

bluetooth-agent 0000 &

Which allows me to pair (with pin 0000) and connect from my phone. To connect to my phone from my Pi I use the qbus command I mentioned earlier.

I bought a Lindy USB sounds card (about £10 from Amazon) which has a mature and very usable ALSA driver. I've made a bit of progress using this as the pulse audio sink rather than the bcm2835 and some noise comes out, but I still get a crash at the end of it:

D: alsa-sink.c: Wakeup from ALSA!
I: core.c: We are idle, quitting...
I: main.c: Daemon shutdown initiated.
I: module.c: Unloading "module-device-restore" (index: #0).
I: module.c: Unloaded "module-device-restore" (index: #0).
I: module.c: Unloading "module-stream-restore" (index: #1).
I: module.c: Unloaded "module-stream-restore" (index: #1).
I: module.c: Unloading "module-card-restore" (index: #2).
I: module.c: Unloaded "module-card-restore" (index: #2).
I: module.c: Unloading "module-augment-properties" (index: #3).
I: module.c: Unloaded "module-augment-properties" (index: #3).
I: module.c: Unloading "module-alsa-card" (index: #4).
D: alsa-sink.c: Requested volume: 0: 82% 1: 82%
D: alsa-sink.c: Got hardware volume: 0: 82% 1: 82%
D: alsa-sink.c: Calculated software volume: 0: 100% 1: 100% (accurate-enough=yes)
D: alsa-sink.c: hwbuf_unused=0
D: alsa-sink.c: setting avail_min=87319
D: alsa-sink.c: Requested to rewind 352800 bytes.
D: alsa-sink.c: Limited to 5404 bytes.
D: alsa-sink.c: before: 1351
D: alsa-sink.c: after: 1351
D: alsa-sink.c: Rewound 5404 bytes.
D: sink.c: Processing rewind...
D: source.c: Processing rewind...
D: module-suspend-on-idle.c: Sink alsa_output.usb-0d8c_C-Media_USB_Headphone_Set-00-Set.analog-stereo becomes idle, timeout in 5 seconds.
D: module-suspend-on-idle.c: Sink alsa_output.usb-0d8c_C-Media_USB_Headphone_Set-00-Set.analog-stereo becomes idle, timeout in 5 seconds.
D: module-suspend-on-idle.c: Source bluez_source.00_23_76_9C_23_E3 becomes idle, timeout in 5 seconds.
D: module-suspend-on-idle.c: Source bluez_source.00_23_76_9C_23_E3 becomes idle, timeout in 5 seconds.
D: core.c: Hmm, no streams around, trying to vacuum.
I: sink-input.c: Freeing input 0 "Loopback of Nexus One"
I: source-output.c: Freeing output 0 "Loopback to Audio Adapter Analog Stereo"
D: core-subscribe.c: Dropped redundant event due to remove event.
D: alsa-sink.c: Thread shutting down
I: sink.c: Freeing sink 0 "alsa_output.usb-0d8c_C-Media_USB_Headphone_Set-00-Set.analog-stereo"
I: source.c: Freeing source 0 "alsa_output.usb-0d8c_C-Media_USB_Headphone_Set-00-Set.analog-stereo.monitor"
D: alsa-source.c: Thread shutting down
I: source.c: Freeing source 1 "alsa_input.usb-0d8c_C-Media_USB_Headphone_Set-00-Set.analog-mono"
I: card.c: Freed 0 "alsa_card.usb-0d8c_C-Media_USB_Headphone_Set-00-Set"
I: module.c: Unloaded "module-alsa-card" (index: #4).
I: module.c: Unloading "module-alsa-card" (index: #5).
D: alsa-sink.c: Thread shutting down
I: sink.c: Freeing sink 1 "alsa_output.platform-bcm2835_AUD0.0.analog-stereo"
I: source.c: Freeing source 2 "alsa_output.platform-bcm2835_AUD0.0.analog-stereo.monitor"
I: card.c: Freed 1 "alsa_card.platform-bcm2835_AUD0.0"
I: module.c: Unloaded "module-alsa-card" (index: #5).
I: module.c: Unloading "module-udev-detect" (index: #6).
I: module.c: Unloaded "module-udev-detect" (index: #6).
I: module.c: Unloading "module-bluetooth-device" (index: #7).
D: core-subscribe.c: Dropped redundant event due to change event.
D: core-subscribe.c: Dropped redundant event due to remove event.
D: module-bluetooth-device.c: IO thread shutting down
I: source.c: Freeing source 3 "bluez_source.00_23_76_9C_23_E3"
I: card.c: Freed 2 "bluez_card.00_23_76_9C_23_E3"
I: module.c: Unloaded "module-bluetooth-device" (index: #7).
I: module.c: Unloading "module-bluetooth-discover" (index: #8).
I: module.c: Unloaded "module-bluetooth-discover" (index: #8).
I: module.c: Unloading "module-esound-protocol-unix" (index: #9).
I: module.c: Unloaded "module-esound-protocol-unix" (index: #9).
I: module.c: Unloading "module-native-protocol-unix" (index: #10).
I: module.c: Unloaded "module-native-protocol-unix" (index: #10).
I: module.c: Unloading "module-default-device-restore" (index: #11).
I: module.c: Unloaded "module-default-device-restore" (index: #11).
I: module.c: Unloading "module-rescue-streams" (index: #12).
I: module.c: Unloaded "module-rescue-streams" (index: #12).
I: module.c: Unloading "module-always-sink" (index: #13).
I: module.c: Unloaded "module-always-sink" (index: #13).
I: module.c: Unloading "module-intended-roles" (index: #14).
I: module.c: Unloaded "module-intended-roles" (index: #14).
I: module.c: Unloading "module-suspend-on-idle" (index: #15).
I: module.c: Unloaded "module-suspend-on-idle" (index: #15).
I: module.c: Unloading "module-console-kit" (index: #16).
I: module.c: Unloaded "module-console-kit" (index: #16).
I: module.c: Unloading "module-position-event-sounds" (index: #17).
I: module.c: Unloaded "module-position-event-sounds" (index: #17).
I: module.c: Unloading "module-cork-music-on-phone" (index: #18).
I: module.c: Unloaded "module-cork-music-on-phone" (index: #18).
I: module.c: Unloading "module-loopback" (index: #19).
I: module.c: Unloaded "module-loopback" (index: #19).
I: main.c: Daemon terminated.

Currently trying to compile latest pulse audio from git source but I'm stuck on dbus which seems to have issues on ARM.

Think I have another bluetooth dongle lying around so I might try with that.

Cheers,
Tim
Posts: 5
Joined: Sun Jun 10, 2012 5:42 pm
by XavM » Tue Jun 19, 2012 12:06 pm
Thank's for the update.

I have the same problem using bluetooth-agent and rfcomm

The system freeze and I have the same "Kernel NULL pointer" issue using bluetooth-agent :
$ sudo hciconfig hci0 piscan
$ sudo hciconfig
hci0: Type: BR/EDR Bus: USB
BD Address: 00:1F:81:00:08:30 ACL MTU: 1021:4 SCO MTU: 180:1
UP RUNNING PSCAN ISCAN
RX bytes:1539 acl:0 sco:0 events:51 errors:0
TX bytes:470 acl:0 sco:0 commands:50 errors:0
$ sudo bluetooth-agent 0000

The Raspberry Pi appears on the telephone but when I try to connect the "Kernel NULL pointer" happens.

If try to initiate the connexion from the Raspberry Pi with rfcomm, it fails as well :
$ sudo hcitool scan
Scanning ...
5C:59:48:4A:0F:FC XiPhone$ sudo bluetooth-agent 0000
$ rfcomm connect hci0 5C:59:48:4A:0F:FC

"Kernel NULL pointer"

I have opened a separated thread on this particular subject, but feel free to give your updates <- viewtopic.php?p=103591#p103591
Posts: 35
Joined: Thu May 31, 2012 11:29 pm
by fbutler » Wed Jun 20, 2012 5:38 am
XavM wrote:( I couldn't try with the new Wheezy Debian image because of this "Segmentation fault" problem starting bluetooth )

It would be worthwhile trying again using the Wheezy image as the bluetooth segmentation bug has now been fixed. See https://github.com/asb/spindle/issues/34
User avatar
Posts: 299
Joined: Thu Mar 15, 2012 4:09 pm
Location: Surrey, England
by ratherDashing » Mon Jul 23, 2012 12:02 pm
Has anyone gotten this to work?

On the raspbian image I can get bluetooth installed, run bluetooth-agent, pair my phone, but then it never "connects". Same with my computer, it'll see my bluetooth, and then fail installing the drivers to connect to it. I get:

[ 452.462332] Bluetooth: hci0 command tx timeout

Here is my device:

Bus 001 Device 005: ID 0cf3:3005 Atheros Communications, Inc. AR3011 Bluetooth

And here is dmesg | grep Bluetooth:

[ 10.178333] Bluetooth: Core ver 2.16
[ 10.538748] Bluetooth: HCI device and connection manager initialized
[ 10.607756] Bluetooth: HCI socket layer initialized
[ 10.667869] Bluetooth: L2CAP socket layer initialized
[ 10.728849] Bluetooth: SCO socket layer initialized
[ 10.796864] Bluetooth: Generic Bluetooth USB driver ver 0.6
[ 33.524052] Bluetooth: RFCOMM TTY layer initialized
[ 33.524112] Bluetooth: RFCOMM socket layer initialized
[ 33.524161] Bluetooth: RFCOMM ver 1.11
[ 33.538970] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[ 33.539020] Bluetooth: BNEP filters: protocol multicast

Any help would be appreciated.
Posts: 39
Joined: Tue Jun 05, 2012 3:00 am
by AmosK » Thu Aug 16, 2012 2:25 pm
Since the ALSA drivers are in Alpha, has anyone tried sending the audio out through the HDMI? XBMC successfully sends audio to the TV reliably, and more Stereo Rcvrs have HDMI inputs theses days. Audio quality should be superior to analog this way too.
Posts: 2
Joined: Fri Aug 10, 2012 5:27 pm
by gvergine » Tue Nov 20, 2012 3:22 pm
Hi timboj,
I have the *exact* issue like your (in the first post). Did you manage to solve it?
Posts: 1
Joined: Tue Nov 20, 2012 3:20 pm
by timboj » Tue Nov 20, 2012 3:49 pm
Hi gvergine,

Sorry, I gave up in the end and bought a Belkin A2DP receiver thing from ebay. Would be nice to get it working with the Pi though, I assumed it was a problem with the audio driver.

Cheers,
T
Posts: 5
Joined: Sun Jun 10, 2012 5:42 pm
by kmonkey331 » Mon Dec 03, 2012 8:46 pm
Hi,
I've gotten A2DP to work fairly well in Arch Linux. I've posted the steps in a blog:
http://kmonkey711.blogspot.de/2012/12/a2dp-audio-on-raspberry-pi.html

maybe that will help out.
good luck.. it took me a while to get anything to work.
Posts: 1
Joined: Mon Dec 03, 2012 8:29 pm
by jkulow » Tue Feb 26, 2013 8:52 pm
kmonkey331 wrote:Hi,
I've gotten A2DP to work fairly well in Arch Linux. I've posted the steps in a blog:
http://kmonkey711.blogspot.de/2012/12/a2dp-audio-on-raspberry-pi.html

maybe that will help out.
good luck.. it took me a while to get anything to work.


KMonkey331, which Bluetooth dongle are you using on the Raspi?

Great write up on how to get it working on wheezy, this will help the project I'm working on right now.
Posts: 1
Joined: Tue Feb 26, 2013 8:49 pm