Last mod: 2024.12.19

Raspberry Pi - Bluetooth

Bluetooth technology is a key enabler in Raspberry Pi IoT projects, offering wireless communication for devices to connect seamlessly. From smart home automation and health monitoring to industrial sensors and wearable devices, Bluetooth provides a low-energy, reliable, and versatile protocol for data exchange in constrained environments. Raspberry Pi's compatibility with Bluetooth allows developers to create innovative solutions, bridging hardware and software efficiently.

Install libraries and enable bluetooth

Installation of all required bluetooth libraries, some of the libraries may already be installed in the distribution, but it is worth making sure:

sudo apt update
sudo apt install bluetooth bluez bluez-tools rfkill -y

Where:

  • bluetooth - bluetooth daemon for device communication
  • bluez - bluetooth protocol stack
  • bluez-tools - command-line utilities
  • rfkill - manages wireless connections

We make sure that the Bluetooth service is working:

systemctl status bluetooth

systemctl status bluetooth

If it doesn't work, try running:

sudo systemctl enable bluetooth
sudo systemctl start bluetooth

Let's check if bluetooth is unlocked:

rfkill list

systemctl status bluetooth

If it is not unlocked, use the command:

sudo rfkill unblock bluetooth

Command line control tool

Run control tool:

bluetoothctl

And call comands:

power on
scan on
pair <MAC_ADDRESS>
connect <MAC_ADDRESS>
trust <MAC_ADDRESS>
info <MAC_ADDRESS>

systemctl status bluetooth

systemctl status bluetooth

systemctl status bluetooth


There will be a continuation on how to use paired devices...