Bluetooth on Raspberry Pi and embedded systems.

1 minute read

Related:


BlueZ5 allows using Bluetooth on Linux for useful tasks like:

  • playing sound from the Linux device over Bluetooth headphones
  • send text with Android phones

This works for Linux computers in general, from laptops to Raspberry Pi Zero W / 3 / 3+ or other single board computers with Bluetooth on-board or via USB adapater. BlueZ is very handy for command line Bluetooth on Linux:

apt install bluez5

Configure Bluetooth connection

From any Linux computer with Bluetooth, pair the Bluetooth device from Terminal:

  1. Hardware enable Bluetooth adapter
    rfkill unblock bluetooth
    
  2. start HCI UART service
    systemctl start hciuart
    
  3. Go into Bluetooth interactive mode. Use sudo if “no default controller available” error occurs.
    bluetoothctl
    

    This shows a list of devices already paired, and goes into an interactive Bluez program. Type

    list
    

    to show Bluetooth adapters usable (there must be at least one).

  4. Software enable Bluetooth adapter
    power on
    agent on
    
  5. Find Bluetooth devices to pair with
    scan on
    

    A list of Bluetooth pairing-mode UUIDs stream in continuously. Wait several seconds if you don’t immediately see your device. Be sure the device (e.g. smartphone/laptop) is in visible/pairing mode.

  6. Stop the scan:
    scan off
    
  7. Pair with Bluetooth device, where uuid is your device
    pair uuid
    
    trust uuid
    
  8. Connect to the Bluetooth device:
    connect uuid
    

bluetoothctl commands

These commands are issues from within bluetoothctl interactive prompt.

  • paired-devices: list devices this computer is paired with
  • info UUID: for device with UUID, list capabilities (Bluetooth service profiles). For example, PANU is PAN user.

Bluetooth from Linux Terminal

Here are several basic Bluetooth commands from the Linux terminal.

List installed Bluetooth devices from Linux

rfkill list

The listing will look like:

0: phy0 Bluetooth: bluetooth Soft blocked: yes Hard blocked: no

enable Bluetooth devices:

rfkill unblock bluetooth

Which reveals another device:

1: hci0: bluetooth Soft blocked: no Hard blocked: no

List Bluetooth adapter (device) UUID

hcitool dev

Which returns:

hci0

and Bluetooth adapter (device) UUID.

enable Bluetooth

hciconfig hci0 up

BlueZ interactive interface

bluetoothctl

This enables pairing/trusting devices, setup Linux Bluetooth audio, and much more.

Notes

Intel Edison Bluetooth user guide manual

Leave a Comment