Bluetooth on Raspberry Pi and embedded systems.
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 or other single board computers with Bluetooth on-board or via USB adapter. BlueZ is very handy for command line Bluetooth on Linux:
apt install bluez5From any Linux computer with Bluetooth, pair the Bluetooth device from Terminal:
Hardware enable Bluetooth adapter
rfkill unblock bluetoothstart HCI UART service
systemctl start hciuartGo into Bluetooth interactive mode. Use sudo if “no default controller available” error occurs.
bluetoothctlshows a list of devices already paired, and goes into an interactive Bluez program.
show Bluetooth adapters usable (there must be at least one).
listsoftware enable Bluetooth adapter
power on
agent onFind Bluetooth devices to pair with
scan onA 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.
Stop the scan:
scan offPair with Bluetooth device, where uuid is your device
pair uuid
trust uuidConnect to the Bluetooth device:
connect uuidbluetoothctl commands: from within bluetoothctl interactive prompt.
paired-devices: list devices this computer is paired withinfo UUID: for device with UUID, list capabilities (Bluetooth service profiles).
For example, PANU is PAN user.
Here are several basic Bluetooth commands from the Linux terminal.
List installed Bluetooth devices from Linux:
rfkill listThe listing will look like:
0: phy0 Bluetooth: bluetooth Soft blocked: yes Hard blocked: no
enable Bluetooth devices:
rfkill unblock bluetoothWhich reveals another device:
1: hci0: bluetooth Soft blocked: no Hard blocked: no
List Bluetooth adapter (device) UUID
hcitool devWhich returns:
hci0
and Bluetooth adapter (device) UUID.
enable Bluetooth
hciconfig hci0 upBlueZ interactive interface
bluetoothctlThis enables pairing/trusting devices, setup Linux Bluetooth audio, and much more.
Related: