Streaming Bluetooth Audio from Phone to Raspberry Pi using ALSA

This post shows steps to setup Bluetooth audio sink on Raspberry Pi using bluez-alsa. Bluetooth audio sink (A2DP sink) enables Raspberry Pi to receive audio from other Bluetooth devices (e.g. smartphone) and play it through the connected speaker. Below are my setup.

  • Raspberry Pi3 B+ with Raspbian Stretch (2018 April version)
  • 3.5 mm plug Speaker
  • Smartphone


– Steps
1. Bluetooth Pairing and Connection
2. Audio Routing
3. Verify
– Summary
– Troubleshoot
– Reference


1. Bluetooth Pairing and Connection
1-1. Launch BlueZ command line interface.

1-2. Setup a pairing agent.

1-3. Make the Raspberry Pi discoverable.

1-4. On your phone, search and select your Raspberry Pi from Bluetooth menu.

1-5. Confirm the pairing on both your phone and Raspberry Pi.

1-6. Authorize A2DP service (first 32 bits: 0000110d). [1]

Note: You may be asked about other services (such as HFP: 0000111E) depending on what services your phone supports. Just answer ‘yes’ to all the services if you are not sure.

1-7. Trust the phone so that Raspberry Pi will automatically accept connections from the phone from the next time.

Note: Replace “XX:XX:XX:XX:XX:XX” with your phone’s Bluetooth device address.

1-8. Exit from BlueZ command line interface.


2. Audio Routing
2-1. Forward audio from the phone to Raspberry Pi’s output.


3. Verify
3-1. Launch a media player and play some music on your phone. You should be able to hear the music from Raspberry Pi’s speaker.


Troubleshoot : Sound Cutting Out
Raspberry Pi’s (3 / 3+ / Zero W) on-board Bluetooth+WiFi combo chip has an issue and the Bluetooth sound cuts out when WiFi is enabled [2]. If you don’t need WiFi, you can just disable the WiFi interface to avoid the sound cutting issue.

If you need WiFi, one of the workarounds is to disable the on-board Bluetooth and use a Bluetooth dongle (e.g. Plugable BLE Adapter, Panda Bluetooth 4.0 Adapter) instead. Below is the steps to do that.

1. Open “/etc/modprobe.d/raspi-blacklist.conf”.

2. Add lines below and save.

3. Connect Bluetooth dongle on Raspberry Pi’s USB port.

4. Restart the Raspberry Pi.


[1] Service Discovery – Bluetooth SIG
[2] Pi3 bluetooth audio stutters with Wifi enabled



Enabling Equalizer on Handsfree Sending Audio with ALSA equal plugin

This post shows steps to enable equalizer on Bluetooth handsfree (HFP) sending audio by using ALSA equal plugin.


– Prerequisites
– Steps
1. Equalizer Plugin Installation
2. ALSA Configuration
3. PulseAudio Configuration
4. Connect your phone and make a call
5. Adjust equalizer
– Reference


Bluetooth Handsfree profile needs to be enabled first. If it’s not done yet, please refer this post.


1. Equalizer Plugin Installation


2. ALSA Configuration
2-1. Load the kernel module of ALSA loopback device.

The following command enables the module at boot time,

2-2. Create .asoundrc.

2-3. Add the lines below, save and close the file.

1-4. Reload .asoundrc by entering the command below:


3. PulseAudio Configuration
3-1. Launch PulseAudio if it’s not running yet.

3-2. Add modules and set default source as below:


4. Connect your phone and make a call
4-1. Connect your phone via bluetooth by using bluetoothctl.

4-2. Make a call by using your phone, or oFono.


5. Adjust equalizer
Now adjust the equalizer by using alsamixer command and listen the audio on the far-end.


– Redirect an audio stream with aloop



Accessing SD Card from Linux VirtualBox Guest on Windows Host

This post shows steps to enable SD card access from Linux VirtualBox guest on Windows host. In this post, I use Windows 10 as the host and Ubuntu 18.04 as the guest.


– Steps
1. Create Virtual Machine Disk file (VMDK) for the SD Card device
2. Attach SD card VMDK to VM
3. Verify
– Troubleshoot


1. Create Virtual Machine Disk file (VMDK) for the SD Card device
1-1. Open Command Prompt as administrator (“Windows” key + “x” and select “Command prompt (admin)”).

1-2. Check the device ID for the SD card device

The result should be like this. In this example, the deviceID for the SD card is “\\.\PHYSICALDRIVE1”.

1-3. Create VMDK file for the SD card device by using “VBoxManage” command.

Replace “C:\Program Files\Oracle\VirtualBox” and “\\.\PHYSICALDRIVE1” with the installation folder of your VirtualBox and the device ID from the previous step respectively. The result should be like this.

and “sdcard.vmdk” file will be appared on the Desktop.


2. Attach SD card VMDK to VM
2-1. Launch VirtualBox as administrator.

2-2. Navigate to “Settint” > “Strage”.

2-3. Click on “Controller: SATA”.

2-4. Check “Use Host I/O Cache” check box.

2-5. Then, click on “Adds hard disk” icon.

2-6. Select “Choose Existing Disk”.

2-7. Navigate to Desktop and select the “sdcard.vmdk” file.


3. Verify
3-1. Launch the VM and verify. In my case it appeared as “/dev/sdb” as below (Raspbian OS image in 32GB SD card).


If you got the error below (during/after you made changes on the SD card), please go back to Step 2 and make sure “Use Host I/O Cache” check box is checked.

“I/O cache encountered an error while updating data in medium “ahci-0-1″ (rc=VERR_ACCESS_DENIED)”



Using Your Phone as Touch Screen Display for Raspberry Pi

Got a Raspberry Pi but don’t have a display, keyboard, or mouse? You can go with headless setup, or use your phone as a touch screen display (with onscreen keyboard).

This post shows steps to connect Raspberry Pi with your phone wirelessly and use it as a touch screen display by using Remote Desktop Protocol [1].

Here is the list of contents of this post.

– Assumptions
– Steps
1. Remote Desktop Server Setup on Raspberry Pi
2. Remote Desktop Client Setup on Your Phone
– Reference



Here are some assumptions before start. In parentheses, it shows my environment for reference.

  • Raspbian Desktop runs on Raspberry Pi (Raspbian 2018 March on Raspberry Pi 3+)
  • iOS or Android device (Android 7.0)
  • Raspberry Pi and phone is connected to same network (private Wi-Fi network:
  • SSH enabled on Raspberry Pi



1. Remote Desktop Server Setup on Raspberry Pi
xrdp [2] is a remote desktop server which is capable of accepting connections from Microsoft Remote Desktop.

1-1. Update the package list.

1-2. Install xrdp.


2. Remote Desktop Client Setup on Your Phone
For client side, we’ll use Microsoft Remote Desktop app which is available for both iPhone and Android. I used Android for below example but the steps are very similar for iPhone.

2-1. Install Microsoft Remote Desktop from the app store.

2-2. Launch the app, then read and accept the terms of the agreements.

2-3. Touch “+” button, then select “Desktop”.

(* I changed the display orientation to portrait mode.)

2-4. Enter Raspberry Pi’s IP address, user name and password.

IP address can be found by using ip command on Raspberry Pi.

The result should look like this:


2-5. Tap on newly created Desktop.


2-6. If everything is fine, Raspberry Pi’s desktop will be displayed on your phone!


Microsoft Remote Desktop app provides an onscreen keyboard.


Also, you can select “Touch” or “Mouse Pointer” in setting menu.



[1] Remote Desktop Protocol – Wikipedia
[2] xrdp: Open Source Remote Desktop Protocol Server
[3] How to Use an Android Tablet as a Screen for Raspberry Pi



Mapping Caps-Lock Key to Control Key

I used to use Happy Hacking Keyboard. Its control key is located where usual keyboard has caps-lock key. (see below picture). So, for me it’s natural that control key is there, below the tab key and above the shift key.

This post shows steps to reassign the caps-lock key to control key on ordinary keyboard, on Windows, Mac OS X, and Linux.


1. Windows
2. Mac OS X
3. Linux
4. Reference


1. Windows
I tested with Windows 10 laptop. According to [1], this also works for Windows 7, 8 and Vista.

1-1. Download and install SharpKeys from here.

1-2. Launch SharpKeys and click on “Add” button.

1-3. In “Edit Key Mapping” window, select “Caps Lock” as “From key”, and “Left Ctrl” as “To key”, then click on “OK”.

1-4. Click on “Write to Registry”.

1-5. Restart PC for the changes to take effect.



2. Mac OS X
2-1. Open “System Preferences”.

2-2. Select “Keyboard”.

2-3. Click on “Modifier Keys…” button.

2-4. Select “Control” from pull-down menu for Caps Lock Key, then click on “OK”.



3. Linux
I tested this with Ubuntu 16.04.

3-1. Open keyboard config file.

3-2. Search a line starts with “XKBOPTIONS” and edit as below:

3-3. Restart PC for the changes to take effect.



4. References
[1] Map Any Key to Any Key on Windows 10, 8, 7, or Vista – How-To Geek
[2] macOS Sierra: Change modifier keys – Apple Support
[3] Change caps-lock to control in virtual console on Ubuntu 17 – ask ubuntu