Setting Up Bluetooth Serial Port Profile on Raspberry Pi using D-Bus API

This post shows steps to set up Bluetooth Serial Port Profile[1] (or SPP) on Raspberry Pi.

The goal is to establish an SPP connection between Raspberry Pi 3 and Android phone, then send and receive texts using serial terminal applications on both ends.

SPP is not available by default. There are two options to enable it in BlueZ (which is the default Bluetooth stack in Linux). This post shows steps for the 2nd option (D-Bus API).

  1. sdptool (please see this post for this option)
  2. D-bus API

 

Prerequisites (parentheses indicate my environment)

 

Steps
1. Installation
1-1. Install a serial terminal application on Raspberry Pi. In this post, I’ll use minicom[2].

 

2. Enable SPP on Raspberry Pi
2-1. Create a python script (e.g. “spp.py”)[3][4].

2-2. Run the script.

2-3. Suspend the script by pressing Ctrl+Z.

 

3. Pairing
To establish a connection, Raspberry Pi and the phone need to be paired.

3-1. Launch bluetoothctl.

3-2. Enter below in order to be discovered from the phone.

3-3. On the phone, scan for Raspberry Pi and pair. You should be able to see something like below.

3-4. Press Ctrl+D to quit.

 

4. Establishing Connection from Phone

4-1. Listen for incoming connection on Raspberry Pi.

4-2. Install and launch “Serial Bluetooth Terminal” app[5] on the phone.

4-3. In the app, go to “Device” menu and select Raspberry Pi. If everything goes well and the connection is established, you should be able to see like this:

 

5. Connecting Serial Terminal on Raspberry Pi
5-1. Open another terminal and launch the serial terminal.

 

6. Test
6-1. Input some text on the phone.

You should be able to see the text on Raspberry Pi’s serial terminal.

6-2. Input some text back to the phone on Raspberry Pi.

You should be able to see the text on the phone.

 

References
[1] Serial_Port_Profile_(SPP) – Wikipedia
[2] minicom(1) – Linux man page
[3] Re: Bluetooth Python script. – Raspberry Pi Forum
[4] Tutorial: Creating a Bluetooth service
[5] Serial Bluetooth Terminal – Google Play

 

 

Sponsor Link

2 Comments

  1. I use Raspberry Pi 3, my work is sending a serial from the android phone to the Raspberry Pi through the bluetooth module HC-06. But I can connect the HC-06 with my Raspberry. Can you help me??

    1. Hi Duy,
      In this post, I’m using Raspberry Pi’s on-board Bluetooth module. I don’t have HC-06, so I don’t know what’s exactly required to connect SPP using HC-06, but I think at least you need to communicate with HC-06 module via UART. This post may be useful to establish UART connection between Raspberry Pi and the module.

Leave a Reply

Your email address will not be published. Required fields are marked *