- Raspberry Pi Resources
- Our resources for other geeks, designers and engineers.
- Bluetooth Commands
- Reset Bluetooth Adaptor
- Restart Bluetooth Service
- List Bluetooth Adaptors
- Scan for Bluetooth devices
- Make The Raspberry Pi Discoverable
- Discover Bluetooth Devices
- List Previously Paired Devices
- Remove Previously Paired Device
- Ping Device
- How to setup and connect to other devices using Bluetooth on Raspberry Pi
- What is a Bluetooth device
- How to setup Bluetooth on Raspberry Pi using the terminal
- How to setup Bluetooth on Raspberry Pi using the GUI
- Conclusion
- About the author
- Hammad Zahid
- How to Connect Bluetooth Device to Raspberry Pi from Terminal
- How to Connect Bluetooth Device to Raspberry Pi from Terminal
- Step 1: Open Bluetooth on Raspberry Pi
- Step 2: Scan Bluetooth Devices
- Step 3: Pair a Bluetooth Device
- Conclusion
- About the author
- Awais Khan
- Raspberry pi bluetooth terminal
- Re: Pairing Bluetooth Devices From A Raspberry Pi Command Prompt
- Re: Pairing Bluetooth Devices From A Raspberry Pi Command Prompt
- Re: Pairing Bluetooth Devices From A Raspberry Pi Command Prompt
Raspberry Pi Resources
Our resources for other geeks, designers and engineers.
Bluetooth Commands
In these notes «xx:xx:xx:xx:xx:xx» means the MAC address of the remote bluetooth device
Reset Bluetooth Adaptor
sudo hciconfig hci0 reset
Restart Bluetooth Service
sudo invoke-rc.d bluetooth restart
List Bluetooth Adaptors
Scan for Bluetooth devices
To then connect to one of the found devices you can use this:
sudo bluez-simple-agent hci0 xx:xx:xx:xx:xx:xx
Make The Raspberry Pi Discoverable
sudo hciconfig hci0 piscan
You will now be able to search and find the RPi from other devices such as windows «Add A Device» (development tip – if you’ve previously connected you’ll need to remove it from Windows Devices for it to be able to found it again by Add A Device)
To allow the connection to complete you need to also do the following step to allow a remote device to actually connect:
1234 is the pairing code for it to use, but this will can be automatically overridden by a randomly selected code displayed on both devices
Discover Bluetooth Devices
List Previously Paired Devices
(This will appear to do nothing if there are no devices).
Remove Previously Paired Device
You will need to get the devices MAC address by using the List command
If you need to disconnect it first:
bluez-test-device disconnect xx:xx:xx:xx:xx:xx
bluez-test-device remove xx:xx:xx:xx:xx:xx
Ping Device
sudo l2ping -c 1 xx:xx:xx:xx:xx:xx
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.
How to setup and connect to other devices using Bluetooth on Raspberry Pi
You want to enjoy your free time by listening to some good music on Bluetooth handsfree, but you don’t know how to connect these Bluetooth headsets to your Raspberry Pi, then no worries this write-up will solve your problem by explaining the procedure of setting up the Bluetooth devices with Raspberry Pi.
What is a Bluetooth device
Bluetooth is a wireless technology that connects the different devices on a particular wavelength with each other and the data is transferred between these devices. The Bluetooth devices can be connected with each other if they are in the range of 30 meters but when the obstacles come between the devices like walls then this range may be decreased. This is the secure way to transfer data between two devices and can be used to connect mobiles, laptops, or peripheral devices like headsets and keyboards.
How to setup Bluetooth on Raspberry Pi using the terminal
It is considered a good practice that whenever you start the Raspberry Pi OS, first update as well as upgrade all the packages of the repository of Raspberry Pi using the command:
After making sure that all the packages are up to date, we will find the status of our Bluetooth service using the command:
In the output, it is cleared that the Bluetooth service is in active status, we can stop the service of Bluetooth using the command:
Again check the status of Bluetooth service using the systemctl command:
To start the Bluetooth service, we will execute the command in the Raspberry Pi terminal:
In order to find out the name of our Bluetooth through the terminal, we will use the command:
In the above output, we can see that the name of our Bluetooth device “hci0”, using this name, we will scan the devices that are in the range of our Bluetooth:
The “DESKTOP-BSDBLIB” is the device to which we want to connect and its MAC address is E4:A4:71:79:78:D5, we will initialize the Bluetooth by using the command:
Once we are in the Bluetooth environment, we will turn on the Bluetooth module using the command:
Once again scan nearby Bluetooth devices which are in the range of our Bluetooth:
Pair the device with MAC address E4:A4:71:79:78:D5 by using the trust command:
Connect the device using its MAC address:
If you want to disconnect the Bluetooth device, execute the command:
How to setup Bluetooth on Raspberry Pi using the GUI
Another way to connect the Bluetooth device is much more convenient as it is GUI (graphical user interface) based, click on the Bluetooth icon on the right top of the screen and a drop-down menu will appear, select the “Add Device”:
Click on the device to which you want to connect through Bluetooth and click on the “Pair” button, in our case the device is “DESKTOP-BSDBLIB”:
The device will be added, a red cross is showing the device is not yet connected, click on the added device, another menu will appear to choose the “Connect”:
The red color icon will turn into the green color which indicates the device is connected successfully:
For disconnection, again click on the device and choose “Disconnect” to disconnect the device with Raspberry Pi:
Conclusion
Bluetooth technology is very popular nowadays, to connect various devices such as wireless headsets, and speakers. One of the reasons behind the popularity of these Bluetooth devices is that they are easy to handle as they do not contain a mess of wires with them. In this write-up, setting up the Bluetooth devices on Raspberry Pi has been explained through the command-line interface as well as the graphical user interface.
About the author
Hammad Zahid
I’m an Engineering graduate and my passion for IT has brought me to Linux. Now here I’m learning and sharing my knowledge with the world.
How to Connect Bluetooth Device to Raspberry Pi from Terminal
Raspberry Pi is a single-board computer, which is beneficial for creating several DIY projects, including home automation, robots, web servers and more. However, since the device doesn’t have much power to run a GUI, most people use the Raspberry Pi OS lite version to speed up the efficiency of the work. If you need help connecting a Bluetooth device to Raspberry Pi for a project, you can easily use the command-line terminal to connect the device.
In this article, you will find an easy way to connect a Bluetooth device with Raspberry Pi from the terminal.
How to Connect Bluetooth Device to Raspberry Pi from Terminal
To connect a Bluetooth Device with Raspberry Pi on terminal, use the following steps:
Step 1: Open Bluetooth on Raspberry Pi
Open the Bluetooth command-line tool using the following command:
Step 2: Scan Bluetooth Devices
Use the following command to scan Bluetooth devices near to your Raspberry Pi device:
You will see different Bluetooth devices appear in the search.
Step 3: Pair a Bluetooth Device
To pair a Bluetooth device with Raspberry Pi, use the following command:
Note: You have to find your device with the name or using the Mac Address.
In my case, I am connecting a Bluetooth device with the name “Lenovo A7010”. The Bluetooth device could be your mobile phone, speaker, controller, or air pods. Type “yes” to send a connection request.
Wait till the connection is established and once it’s done, you will see a successful pairing notification on the terminal.
Note: You have to allow pairing requests from mobile or laptop if you are paring them to Raspberry Pi:
Conclusion
Raspberry Pi system allows users to connect a Bluetooth device directly from the terminal using the “bluetoothctl” command. Once the agent is registered, you must search for Bluetooth devices using the “scan on” command and connect to your device using its MAC address. Wait till the connection is established, which may require your approval for the connection request. Once the connection is made, you can use a Bluetooth device with Raspberry Pi.
About the author
Awais Khan
I’m an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.
Raspberry pi bluetooth terminal
I have made a video on how to pair Bluetooth devices on the Raspberry Pi from a command prompt. Useful if you are using the Raspbian Lite distribution.
Re: Pairing Bluetooth Devices From A Raspberry Pi Command Prompt
And for people like me who prefer the economy of a few lines of text, Martin O’Hanlon has documented the steps needed as part of the documentation for his Blue Dot library —
Re: Pairing Bluetooth Devices From A Raspberry Pi Command Prompt
I do agree that doing this via YouTube was a bit excessive.
I would have liked if OP had includes the «few lines of text» description in the OP, along with the YouTube URL.
Meta note: If I were more ambitious, I would expend the effort necessary to deduce the «few lines of text» version and post it here. Alas, I am not.
G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:
J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!
Re: Pairing Bluetooth Devices From A Raspberry Pi Command Prompt
The video was in relation to my OBDII project to read data from a car ECU via it’s OBDII connector. I found people new to Raspberry Pi were having difficulty pairing Bluetooth devices. So I did a video they could follow to the letter, alas not all people have your technical background. However, below are the commands summarised as requested, which can also be found in the readme file of the Open Source Python script which can be found here:
https://github.com/BirchJD/PiOBDII
BLUETOOTH DONGLE (Perform operations here as root user)
EXAMPLE CONNECTING TO A BLUETOOTH ELM327 DONGLE FROM LINUX COMMAND LINE
OR THE BUILT IN RASPBERRY PI 3 BLUETOOTH DEVICE:
Bluetooth service
# Get the status of the Bluetooth service.
service bluetooth status
# If the Bluetooth service is not running, start it.
service bluetooth start
# Stop the Bluetooth service only if required.
service bluetooth stop
Pairing a Bluetooth device
# Once a device is paired it should automatically pair in future.
# Start the Bluetooth utility.
bluetoothctl
# Make sure the Bluetooth device is powered on.
power on
# Make sure an agent is running for the Bluetooth device.
agent on
# Start a scan for other Bluetooth devices in the area.
scan on
# Wait for the required Bluetooth device to be reported.
# Stop scanning when the required Bluetooth device is found.
scan off
# Attempt to pair the required Bluetooth device.
pair
# Pairing normally prompts for a password. Standard Bluetooth pairing passwords
# are: 0000 or 1234, try these if you are unsure of the password.
# If pairing fails or propt for password does not appear, try the following, and
# then try paring again.
agent off
power off
power on
agent on
# Once paired it should appear in the list of paired devices.
paired-devices
# You can now leave the Bluetooth utility and the device should be paired and
# ready for use.
quit
Creating a serial device for use in the OBDII application
# rfcomm associates the paired device ID with a serial device name.
rfcomm bind 0
# The device it should create is:
/dev/rfcomm0
# To remove the serial device do the following if required.
rfcomm release
### Shouldn’t need this command, force rfdevices to stop.
### rfkill list
Unpairing a Bluetooth device
# Start the Bluetooth utility.
bluetoothctl
# Unpair the Bluetooth device if required.
remove
# Make sure the agent is stopped for the Bluetooth device.
agent off
# Make sure the Bluetooth device is powered down.
power off
# Exit the Bluetooth utility.
quit