Raspberry pi bluetooth наушники

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

clopresti/rpi-bluetooth

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Using Bluetooth With The Raspberry Pi

The following instructions show how to setup and use a USB Bluetooth adapter with the Raspberry Pi. Please note that these instructions only apply to the latest Raspbian Jessie distribution. If you are using a different distribution or an older Raspbian build such as Wheezy some of the instructions will need to be changed as the Bluetooth stack and utilities have changed with the Jessie release and BlueZ 5.23.

A lot of the instructions I found online were relating to the older wheezy builds and it took some extra time to find the correct way to do things with Jessie. There were also a few configuration changes that needed to be made in order to work around some known issues/bugs relating to the RFCOMM (serial over Bluetooth) communication on the Pi. I have documented all this and hopefully I can save you some time if you are trying to do a similar things.

I am using a USB Bluetooth 4.0 adapter with a Broadcom BCM20702 chipset but there are many other supported Bluetooth adapters including those with CSR (Cambridge Silicon Radio) chipsets. I tested on a Raspberry Pi 2 but all this should work with any version of the Raspberry Pi as long as you are running the latest Raspbian Jessie distribution.

First make sure your Pi is up to date:

> sudo apt-get update > sudo apt-get upgrade > sudo rpi-update > sudo reboot 

Insert your USB Bluetooth adapter into one of the USB ports on the Pi and enter:

Читайте также:  Air mouse keyboard bluetooth

You should see output similar to the following:

If you used an adapter with a different chipset like CSR you might see ‘Cambridge Silicon Radio’ insead of ‘Broadcom Corp’. If you do not see something similar to this it might mean that there is something wrong with your adapter or it is not recognized/supported.

Next install the bluez and bluetooth manager packages:

> sudo apt-get install bluetooth blueman bluez python-gobject python-gobject-2 

Now you can check you your adapter state:

You should see output similar to the following:

BD Address: XX:XX:XX:XX:XX:XX UP RUNNING PSCAN ISCAN 

The [XX:XX:XX:XX:XX:XX] part is the MAC address of your Bluetooth adapter If you do not see «UP RUNNING» enter the following to turn on Bluetooth:

Part 2. Paring and Connecting Devices

Start the command line Bluetooth manager

You should see a line similar to:

Controller XX:XX:XX:XX:XX:XX raspberrypi [default] 

‘raspberrypi’ is the default name you will see when pairing/connecting to the Pi from other devices

Источник

Connecting bluetooth audio device to Raspberry Pi

Raspberry Pi Bluetooth cover

Raspberry Pi Bluetooth cover

In this tutorial we are connecting bluetooth audio device to Raspberry Pi that is running Raspberry Pi OS and PulseAudio. This works with bluetooth speaker and headphones. What i have learned in the process that its important to do all the steps in the right order so that you don’t get any errors. This tutorial is tested with the Raspberry Pi 3/4 and Raspberry Pi OS Lite (32bit) that is released in 2020-12-02.

Connect Raspberry Pi to bluetooth speaker

1. Connect to your Raspberry Pi over SSH using terminal software like PuTTy, or if you are using desktop version of Raspberry Pi OS then you have to open Raspberry menu and go to Raspberry Menu > Accessories > Terminal.

2. Let’s start by updating package repositories by writing sudo apt-get update and hit enter.

3. Install pulseaudio and needed modules to Rasperry Pi OS. You have now two options to choose from. You can go with the option a that doesn’t install all the modules and takes 164 MB less space, or you can ago with option b, where you install all the extra modules. There has been cases where users had to install all the modules (Option b), because they couldn’t pinpoint what was the missing module.

Option a. sudo apt-get install pulseaudio pulseaudio-utils pulseaudio-module-bluetooth
(After this operation, 676 MB of additional disk space will be used.)

Option b. sudo apt-get install pulseaudio*
(After this operation, 840 MB of additional disk space will be used.)

4. Next we need to add user pi to group lp: sudo usermod -a -G lp pi . If you are not doing this, you will get «Failed to connect: org.bluez.Error.Failed» -error while connecting to device with bluetoothctl.

5. Reboot Raspberry Pi with this command: sudo reboot . You need to reboot so that the group change comes into effect. Closing and reconnecting with PuTTy wasn’t enough for me, but reboot worked.

Install Pulseaudio and utils using PuTTy

6. Next start pulseaudio with command: pulseaudio —start

7. Let’s access bluetooth using: sudo bluetoothctl

8. Power on bluetooth by writing: power on and then select default agent: default-agent .

Читайте также:  What is bluetooth hid device

9. Start your headphones/speaker and put it in the pairing mode. Then start scanning the devices with: scan on . Wait untill you see your device in the scan list, and then add that device to trusted list with command: trust xx:xx:xx:xx . After that, pair Raspberry Pi with: pair xx:xx:xx:xx , and then connect with: connect xx:xx:xx:xx .

10. If you did everything in right order you should be now connected to your bluetooth device. If thats the case, exit bluetoohctl with command: exit

Connect to bluetooth speaker using Pulseaudio and bluetoothctl

11. Check that your newly connected audio device is showing in the audio card list with: pactl list cards short . Sometimes there is small delay untill your bluetooth device is showing, so you might have to run the command multiple times. If you want more info about the available cards just write the command without short pactl list cards .

12. When you see your audio device in the list, you can test that the device is working. Check the number of the card with the previous command and use that number with this command by replacing the —device id.
paplay -p —device=1 /usr/share/sounds/alsa/Front_Center.wav

13. If you are hearing sound, then everything is working like it should!

Play audio on your audio device using paplay

Make Raspberry Pi to connect bluetooth automatically on boot

There might be situations where you want Raspberry Pi to connect to your bluetooth device automatically on boot, so let’s also cover that up. We are going to use simple crontab approach. Here is the reasons why you shouldn’t run PulseAudio as system mode: What is wrong with system mode?

1. First we need to create bash script. I’m creating the file to /home/pi with command touch btconnect.sh

2. Next we need to change the file permission so that we can run it chmod +x btconnect.sh

3. Then we can open the file for editing. I’m using nano for editing. nano btconnect.sh . Copy&paste or write the lines below to the sh file. Replace the XX with the address of your bluetooth device, so that Raspberry Pi will attempt to connect to that specifig device on boot. Optionally you don’t have to add the bluetoohctl lines at all, then Raspberry Pi doesn’t connect to your device, but when you start your speaker/headset it will automatically connect to Raspberry.

#!/bin/bash pulseaudio --start bluetoothctl power on bluetoothctl connect XX:XX:XX:XX 

You can paste text to shell by right clicking your mouse in PuTTy. You can also copy text in shell just by highlighting text with left click.

4. Then you can save the file by pressing [Ctrl] + X then y and then [Enter].

5. Now we can test that the script works by writing ./btconnect.sh . If you don’t get any errors, then you can add the script to crontab.

6. Write crontab -e and add line @reboot /home/pi/btconnect.sh . If you are using nano for editing then you can save and exit by pressing [Ctrl] + X then y and then [Enter].

7. Reboot your Raspberry Pi to see if it works. You can reboot by writing sudo reboot . If you did everything right, Rasperry should automatically connect to your speaker/headphones, and if you power off your audio device and start it again, it should automatically connect to Raspberry, so it works both ways.

Читайте также:  Программатор для bluetooth модулей

Troubleshooting

pa_context_connect() failed: Connection refused

You might get «Connection failure: Connection refused, pa_context_connect() failed: Connection refused» -messages when entering pactl list cards command. You can try to fix that by first killing pulseaudio process by writing pulseaudio -k and then starting it again by writing pulseaudio —start .

Failed to connect: org.bluez.Error.Failed

This is the most commonly seen error, and the problem is that it doesn’t tell you anything specific. You will get this error if: You don’t have all necessary modules, or if pulseaudio is not started, or if your user doesn’t have permission to use bluetooth.

1. Run this command pulseaudio —dump-modules to see all the available modules for PulseAudio. Make sure that you find these modules from the list: module-bluetooth-policy, module-bluetooth-discover, module-bluez5-discover. If you don’t have these modules installed, then you can just run sudo apt-get install pulseaudio* to install all the available modules.

2. Run this command pactl list short modules to see all the currently loaded modules for PulseAudio. Make sure that you find the modules mentioned on step 1. If you don’t find them, then check PulseAudio config with sudo nano /etc/pulse/default.pa and see if there is commented lines that contains these modules. If you don’t find this modules at all from this file, then you can try to manually add them to file.

3. Make sure that you added your user to lp group and rebooted Raspberry like mentioned in step 4.

4. You can check errors from systemlog by writing sudo cat /var/log/syslog | grep -i protocol and bluetooth errors by writing systemctl status bluetooth .

1 Comments

Hello internet. I have tried to install this using the second option shown. I am having trouble with this, because every time I type «power on», it tells me that the whole org.bluez thing is blocked. I am unsure of how to fix this (if it even is fixable). Any advice would be of great help. Thank you.

I am not familiar with this error, but there is blog posts about that. And the list of possible causes is long: https://blog.timekit.io/google-oauth-i.

EA took over Origin and deleted it. Now patch does not work and cannot run Yuri2. any fix? Thanks.

hi. Nice video and web page. I tryed to play YR cnCnet but it says that I could be cheatring and the maps doesnt load so they kicked me out everytime .

Im kinda also having the last problem I have my ps4 controller connect via BT opened x360ce it directed my controller and i even remapped and saved th.

February 13, 2023 — Poopyswerls

Our website uses cookies to improve your experience. By choosing I Accept, you consent to our use of cookies. Read about the cookies we use.

Источник

Оцените статью
Adblock
detector