HFP on Raspberry Pi

Update (Sep 7, 2017):
If you are using Raspbian Stretch, please refer here instead of steps below. This post below is for Raspbian Jessie.

The purpose of this post is to enable Bluetooth Handsfree Profile (HFP) on Raspberry Pi so that Raspberry Pi can act like as a handsfree speaker phone or a handsfree car kit. There is one thing needs to be mentioned before start. The original plan was to use Raspberry Pi3’s on-board Bluetooth chip for this project. Unfortunately, it didn’t work. It seems that the problem is related with the chip. So, we have to use a Bluetooth dongle instead.

Steps1. Setting Up
1-1. Connect Bluetooth dongle and USB sound card with Raspberry Pi.
1-2. Connect the microphone and speakers to 3.5 mm audio jacks on the USB sound card.
1-3. Boot up Raspberry Pi Board. If it’s not set up yet, please refer this post.
1-4. As described, we don’t use on-board Bluetooth chip. So it needs to be disabled. To do that, open “/etc/modprobe.d/raspi-blacklist.conf”.

1

sudo nano/etc/modprobe.d/raspi-blacklist.conf

1-5. Add lines below and save.

1

2

blacklist btbcm

blacklist hci_uart

1-6. Then reboot the board.

1

sudo reboot

1-7. After reboot, check dmesg and make sure there is no Bluetooth-related errors.

1

dmesg|grep-ibluetooth

1-8. Also, make sure hci0 is UP.

1

hciconfig

The result should be like this:

1

2

3

4

5

hci0:Type:BR/EDR Bus:USB

BD Address:00:1A:7D:DA:71:08ACL MTU:310:10SCO MTU:64:8

UP RUNNING

RX bytes:622acl:0sco:0events:38errors:0

TX bytes:1437acl:0sco:0commands:38errors:0

If it’s DOWN for some reason, then turn it up.

1

sudo hciconfig hci0 up

2. oFono
2-1. oFono is not installed by default, so let’s install it.

1

sudo apt-get install ofono-y

2-2. Make sure the version is 1.13 or later.

1

2

pi@raspberrypi:~$ofonod--version

1.15

2-2. Then, start the service.

1

sudo systemctl start ofono

You can check the service running like below.

1

2

systemctl-a|grep ofono

ofono.service loaded active running LSB:oFono Mobile Telephony Daemon

3. PulseAudio
Since the preinstalled PulseAudio is 5.0, it needs to be updated to at least 6.0.

If everything is ok, you should see “successful” at the end of the result for each command like below.

1

2

3

[bluetooth]# pair XX:XX:XX:XX:XX:XX

...

Pairing successful

1

2

3

[bluetooth]# trust XX:XX:XX:XX:XX:XX

...

trust succeeded

1

2

3

[bluetooth]# connect XX:XX:XX:XX:XX:XX

...

Connection successful

5. Make a Call!
To make a call, we’ll use oFono test scripts which is included in the source code.
5-1. First, download the source and extruct.

1

2

wget https://www.kernel.org/pub/linux/network/ofono/ofono-1.15.tar.gz

tar-xzvf ofono-1.15.tar.gz

5-2. Then, you can make a call by:

1

python./test/dial-number1234567890

If you want to end the call, then execute:

1

python./test/hangup-active

Conclusion
Thanks for all the forums and articles I referred, now HFP is working on Raspberry Pi!
Next, I’m planning to apply echo canceling and ambient noise suppression, maybe equalizer.

Update (June 22, 2017):
Added one step (step 3-10) to enable echo cancellation. It seems that ‘module-echo-cancel’ does not only echo cancellation but ambient noise suppression. I haven’t check the noise suppression yet but I think the echo cancellation is working well based on my brief testing.