Rapberry Pi Bluetooth

Using the Command Line

Pairing a device:

1 Enter bluetoothctl to open Bluetooth control

discoverable on
pairable on
agent on (is already on)
default-agent
scan on

2 Wait for a message to appear showing the first Pi has been found:

[NEW] Device 12:23:34:45:56:67 devicename

3 Type pair with the mac address of the first Pi:

pair 12:23:34:45:56:67

4 Enter a PIN

4 On the first Raspberry Pi again:

Link to device RFCOMM0

Following the following webpage
https://www.raspberrypi.org/forums/viewtopic.php?t=154651

Install the Bluetooth service (needed only once)

1) sudo apt-get install bluetooth bluez blueman

 bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled)
   Active: active (running) since Fri 2016-07-15 21:44:38 UTC;
  • Bind the device
  • sudo rfcomm bind 0 xx:yy:zz:59:09:FF

Read and write script

https://www.instructables.com/id/Read-and-write-from-serial-port-with-Raspberry-Pi/

#! /usr/bin/python
import serial

bluetoothSerial = serial.Serial( "/dev/rfcomm0", baudrate=9600 )

while 1:
        x=bluetoothSerial.readline()
        print x