Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tutorial: setting-up Bluetooth - PulseAudio #24

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
138 changes: 138 additions & 0 deletions docs/tutorials/setting-up-bluetooth-audio-with-pulseaudio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
title: Setting Up Bluetooth audio with PulseAudio - A2DP only
subject: Bluetooth
---

### Overview
Debian jessie is using BlueZ 5 and PluseAudio 5, which are fairly new.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of trailing spaces to prevent line breaks. This applies to the whole file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On some places it's a matter of taste, but you are right. will do.

There were major breaking changes in these versions.
Most stuff you find on the Internet will be for BlueZ 4 and PulseAudio 4,
so watch out, those configurations may not work.

[PulseAudio 5 only supports the A2DP profile](http://www.freedesktop.org/wiki/Software/PulseAudio/Notes/5.0/) and not Headset profile (HSP) or Hands-free profile (HFP),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put links at the end of the file. For example, this line should be something like...

[PulseAudio 5 only supports the A2DP profile][PA5-relnotes]

...and at the end of the file...

[PA5-relnotes]: http://www.freedesktop.org/wiki/Software/PulseAudio/Notes/5.0/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done
Good to have all links in one spot

although it is [under development](http://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/?id=1f0de01bfc85f92785fcd2f0e863e471af7e6ace).

The A2DP profile provides these two profiles:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The profiles are not provided by A2DP, rather, they are provided by PulseAudio. (A2DP is just a specification).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sharp :-)
done


UUID: Audio Source
UUID: Audio Sink

The remote device we are connecting to needs to have at least one of these profiles.

### How to get PulseAudio working with Bluetooth
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put blank line after all heading lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

**This should all be done as root**

1. Install pulseaudio:

apt-get install --no-install-recommends pulseaudio pulseaudio-module-bluetooth

2. Create a systemd service for running pulseaudio as the pulse user.
Save the following lines as `/etc/systemd/system/pulseaudio.service`

[Unit]
Description=Pulse Audio
[Service]
Type=simple
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need blank lines before and after the "code"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That indeed helps a lot, thanks
done


and reload systemd with `systemctl daemon-reload`

3. Give the `pulse` user permission to use Bluetooth.
Save the following lines to `/etc/dbus-1/system.d/pulseaudio-bluetooth.conf`

<busconfig>

<policy user="pulse">
<allow send_destination="org.bluez"/>
</policy>

</busconfig>

4. Paste the following lines to the **end** of `/etc/pulse/system.pa`:

### Automatically load driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
.endif
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif

5. Start the systemd service: `systemctl start pulseaudio.service`

6. Connect the device, example using brickman on the EV3 screen.
You only need to do the pairing stuff once.
Be sure to substitute the address of the actual device your are connecting to.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In brickman, we see the name of the device, so we don't have to worry about the address.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hihi :-)
removed.

Actions to do:

On the brickman main screen scroll to the `Bluetooth` option:
![brickman mainscreen](https://cloud.githubusercontent.com/assets/8142081/5093619/612eb254-6f5a-11e4-86a6-213b31526856.png)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use liquid template for images. Also, brickman screenshots should be given meaningful names and go in images/brickman in this repo.

Example:

{% include screenshot.html source="/images/brickman/main-menu-bluetooth-selected.png" scale="50" %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

learned.
I only "knew" about the way to paste pictures in an issue.
This way is much better.
Question 1: there is an image main-menu.png that lacks the bluetooth option.
Have made an extra main-menu-incl-bluetooth.png
Or would you want to replace the original?
Question 2: how to synchronize the colors in the images, so they all look alike?
Mine are white, so there is no distinct border.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found an answer for my second question, will change the brickman images to have a background of 0xadb578 and push into my repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q1: Yes, replacing the existing file would be good. However, see answer to Q2 for caveat.
Q2: I used the brickman test program (a desktop program built using the brickman source code) to stage the screenshots that I made - they did not actually come from a real EV3. This is why the background color is different. Also, they are scaled to 2x (without any fancy interpolation that uses anti-aliasing) so that they are easier to read. So, if you are going to go through the trouble to change the background color, you might as well scale them to 2x also.


Press the EV3 "ENTER" button (the center button)
Scroll with the up or down button to `Start Scan` and press "ENTER"
![brinkman bt scan](https://cloud.githubusercontent.com/assets/8142081/5094570/4f8fa23a-6f62-11e4-9999-ef5773092735.png)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a blank line between all screenshots and surrounding text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


Did you set the target device "discoverable"? If not, better do that now.
Scroll down (or up if you like) to the device you want to use.
Press "ENTER" to select:
![brickman select device](https://cloud.githubusercontent.com/assets/8142081/5094436/3843f302-6f61-11e4-9f8f-16444abc6959.png)

On the brickman device page:
Select `Pair` and press "ENTER"
![brickman device page](https://cloud.githubusercontent.com/assets/8142081/5094449/4d0f485e-6f61-11e4-998c-0e77ca95a5d9.png)

On the remote device you also need to accept the pairing.
Select `Accept` and press "ENTER"
![brickman pairing](https://cloud.githubusercontent.com/assets/8142081/5094463/730e0e64-6f61-11e4-8137-0bf35a10c6bb.png)

After successful pairing select `Connect` and press "ENTER":
![brickman after pair device](https://cloud.githubusercontent.com/assets/8142081/5094470/809a64b0-6f61-11e4-9d02-7c95b8e838ef.png)

7. Now, you should be able to play sound from a remote device on your EV3 without any further configuration.

8. To play sound from the EV3 on a remote device, there are a few more steps.
* add your own non-root user(s) to the `audio` and `pulse-access` groups:

usermod -a -G pulse-access,audio myuser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs additional indenting so that it is displayed as code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


* Run `pactl list cards`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be run as myuser, not root.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.
Done

The end of the output should look something like this:

Card #1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - needs more indenting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helps, thanks
done

Name: bluez_card.00_17_E7_BD_1C_8E
Driver: module-bluez5-device.c
Owner Module: 14
Properties:
device.description = "BlueZ 5.23"
device.string = "00:17:E7:BD:1C:8E"
device.api = "bluez"
device.class = "sound"
device.bus = "bluetooth"
bluez.path = "/org/bluez/hci0/dev_00_17_E7_BD_1C_8E"
bluez.class = "0x0c0000"
bluez.alias = "BlueZ 5.23"
device.icon_name = "audio-card-bluetooth"
Profiles:
a2dp_source: High Fidelity Capture (A2DP Source) (sinks: 0, sources: 1, priority: 10, available: yes)
a2dp: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
Active Profile: a2dp
Ports:
unknown-output: Bluetooth Output (priority: 0, latency offset: 0 usec)
Part of profile(s): a2dp
unknown-input: Bluetooth Input (priority: 0, latency offset: 0 usec)
Part of profile(s): a2dp_source

The active profile probably doesn't say `a2dp`, although in the output above it already has been set.
So set it by running: `pactl set-card-profile 1 a2dp`
The "1" in this command is the number of the BT card from the output above.

9. Now you can play sound using paplay.
Example: `paplay -d bluez_sink.00_17_E7_BD_1C_8E /usr/share/sounds/alsa/Front_Center.wav`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the command on its own line and indented so that it displays as a larger code block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and blanks lines before and after.
Looks better
done

Possibly error messages like `xcb_connection_has_error() returned true` have been seen and not explained.
There seems to be no ill effect on BT audio.
Using my simple non-root user I get:

Failed to create secure directory (/run/user/0/pulse): Permission denied

but playback **does** work.
6 changes: 6 additions & 0 deletions docs/tutorials/setting-up-bluetooth-keyboard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Setting Up Bluetooth keyboard
subject: Bluetooth
---

### Needs to be created