Raspberry pi bluetooth receiver

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.

Scripts, tools and documentation for creating a bluetooth receiver with raspberry pi

License

sandreas/raspberry-bluetooth-receiver

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

This repository contains scripts, tools and documentation for creating a bluetooth receiver with raspberry pi zero w or raspberry pi 3.

The repository is designed for the following hardware (links to amazon):

Raspberry PI 3 (alternative)

  • Smallest possible homebrew bluetooth receiver
  • Controllable via buttons / touch screen (Play, Pause, Next, Previous, Volume, etc.)
  • Auto reconnect the last connected bluetooth device
  • TODO: Airplay Support (bluetooth and airplay cannot be used together*)
  • TODO: USB Port for Playing MP3
  • TODO: FM Transmitter via GPIO
  • Raspberry pi zero w or raspberry pi 3 have a single chip for bluetooth and wifi. Unfortunately at the moment it is not possible to get bluetooth audio and wifi work together without problems (bluetooth audio works, but with bad quality and lags — I’m not sure if this is a driver or hardware issue).

PHAT DAC is a higher quality audio hat for raspberry pi zero, that is relatively cheap, but worth the money. In order save space and use the case mentioned in the hardware recommendations, you could solder the PHAT DAC directly on the pins:

Now drill a hole for the audio jack in the top of the case and see, if everything fits.

Читайте также:  Диагностика авто тойота елм 327 блютуз

Soldering Adafruit 12-Key Capacitive Touch Sensor

Download the latest release of Raspian Lite (https://www.raspberrypi.org/downloads/raspbian/) and flash it to your sd card. Before removing the card, be sure to enable ssh and wifi:

Open the /boot partition of the sd card and create an empty file named ssh . That’s it, ssh should be enabled on first boot.

Open the /boot partition of the sd card and create a file named wpa_supplicant.conf with following content: country= ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network=< >

Enable overclocking (optional)

For raspberry pi zero (w) you could use following overclocking settings to improve performance, if you use at least passive cpu cooling.

Open the /boot partition of the sd card and append following to your config.txt :

arm_freq=1000 gpu_freq=500 core_freq=500 sdram_freq=500 sdram_schmoo=0x02000020 over_voltage=2 sdram_over_voltage=2 

First boot and initial setup

Unmount your sd card and insert it into the raspberry pi, then power on First boot should resize the partitions, second boot should provide you a login prompt.

Use following credentials (if you are not using ssh, note that the y in raspberry sometimes can be a z depending on the used keyboard layout):

Username: pi Password: raspberry 

To install the PHAT DAC and disable internal audio, just run this command

curl https://get.pimoroni.com/phatdac | bash 

and follow the instructions. To test, if your audio is working, plugin a headphone or speaker and run

speaker-test -c2 --test=wav -w /usr/share/sounds/alsa/Front_Center.wav 

You should hear a voice saying «Front — Center». Press CTRL+C to quit the test.

apt install -y git cd /home/pi git clone https://github.com/sandreas/raspberry-bluetooth-receiver 

Bluetooth on Linux is tricky — especially when using audio. So, before you begin, you should know some things about the raspberry pi, bluetooth and audio:

  • bluetooth audio and wifi won’t work together — see Features for details
  • to use bluetooth with audio, you will need bluez (linux bluetooth stack), pulseaudio (linux sound server) and alsa (Advanced Linux Sound Architecture) to work together
  • bluez / pulseaudio is unter heavy development — api is kind of limited and changes are likely, so this docs might be out of date soon
  • to manage, connect and trust devices, you could use bluetoothctl , but beware — most of the commands are used async, automation and shell usage is tricky
  • pulseaudio can be configured for high quality audio, but raspberry pi zero w does not perform well enough to provide best quality — see audio qualiy

So the principle is simple:

  • Pair and trust a bluetooth device
  • Let pulseaudio/alsa create an extra audio sink for the bluetooth device
  • Create a loopback device for redirecting the input from the bluetooth audio sink to the audio jack (via dbus rule)
  • Remove the loopback device when disconnecting the bluetooth device
Читайте также:  Pioneer deh p55bt пароль от блютуза

The performance of the raspberry pi zero w is very limited. Therefore you cannot use the best audio quality settings possible — but you can improve the quality by using this settings (gets most of PulseAudio):

# /etc/pulse/daemon.conf resample-method = ffmpeg enable-remixing = no enable-lfe-remixing = no default-sample-format = s32le default-sample-rate = 192000 alternate-sample-rate = 176000 default-sample-channels = 2 
# Install BlueZ-5 and PulseAudio-5 with Bluetooth support: apt --no-install-recommends install pulseaudio pulseaudio-module-bluetooth bluez bluez-firmware 
# granting permissions adduser root pulse-access adduser pi pulse-access 
# Authorize PulseAudio run as user pulse use BlueZ D-BUS cat /etc/dbus-1/system.d/pulseaudio-bluetooth.conf     EOF 
# Load Bluetooth discover module in SYSTEM MODE cat > /etc/pulse/system.pa # ### Bluetooth Support .ifexists module-bluetooth-discover.so load-module module-bluetooth-discover .endif EOF 
# Create a systemd service for running pulseaudio in System Mode as user "pulse". cat /etc/systemd/system/pulseaudio.service [Unit] Description=Pulse Audio [Service] Type=simple ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm --exit-idle-time=-1 [Install] WantedBy=multi-user.target EOF 
# reload daemons systemctl daemon-reload systemctl enable pulseaudio.service 
# start pulseaudio service systemctl start pulseaudio.service 

Connecting a bluetooth audio device

# restart bluetooth service systemctl restart bluetooth # to pair a bluetooth device, run bluetoothctl, which opens an extra command shell # don't forget to take a look at the pairing status of your device bluetoothctl [bluetooth]# power on [bluetooth]# agent on [bluetooth]# default-agent [bluetooth]# scan on [bluetooth]# pair [bluetooth]# trust [bluetooth]# connect [bluetooth]# exit 

Adding a udev rule for auto loopback

Before you add a udev rule, there is an issue, you should know about. On current raspbian releases, udev does not accept rules because of using a readonly filesystem, that is caused by udev not recognizing the rw-state of the filesystem. This can be fixed by adding following to you /etc/rc.local :

# /etc/rc.local - bottom # added service udev restart exit 0 # this line should already exist 

Now add a rule that runs a script everytime a bluetooth device gets connected

# /etc/udev/rules.d/99-com.rules SUBSYSTEM=="input", GROUP="input", MODE="0660" #added KERNEL=="input1*", RUN+="/home/pi/raspberry-bluetooth-receiver/scripts/udev-bluetooth" SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660" 

to connect last device on startup, add a reboot cronjob as root

sudo -s crontab -e #added @reboot /home/pi/raspberry-bluetooth-receiver/scripts/autoconnect-bluetooth > /home/pi/raspberry-bluetooth-receiver/logs/autoconnect-bluetooth.log 2>&1 & 
  • USB Audio: https://gist.github.com/oleq/24e09112b07464acbda1
  • bluez5 (current): https://github.com/davidedg/NAS-mod-config/blob/master/bt-sound/bt-sound-Bluez5_PulseAudio5.txt
  • bluez4 (old): https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=68779
  • All-in-one-script: https://github.com/BaReinhard/Super-Simple-Raspberry-Pi-Audio-Receiver-Install (did not work for me, but it is a nice resource for ideas)

About

Scripts, tools and documentation for creating a bluetooth receiver with raspberry pi

Источник

ericbolo / rpi-bluletooth-receiver.md

This walks you through setting up your Raspberry PI 3 (Raspbian Jessie) as a bluetooth audio receiver.

Credits https://www.raspberrypi.org/forums/viewtopic.php?t=68779. Parts of this tutorial did not work for me, so I’m noting my fixes here. Also, I added instructions for setting up a custom USB sound card for better quality.

Set up USB sound card on Raspberry PI

This will list the available audio devices. In my case:

**** List of PLAYBACK Hardware Devices **** card 1: Set [C-Media USB Headphone Set], device 0: USB Audio [USB Audio] Subdevices: 0/1 Subdevice #0: subdevice #0 card 2: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA] Subdevices: 8/8 Subdevice #0: subdevice #0 Subdevice #1: subdevice #1 Subdevice #2: subdevice #2 Subdevice #3: subdevice #3 Subdevice #4: subdevice #4 Subdevice #5: subdevice #5 Subdevice #6: subdevice #6 Subdevice #7: subdevice #7 card 2: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI] Subdevices: 1/1 Subdevice #0: subdevice #0 

We need to tell ALSA (Advanced Linux Sound Architecture) to use the USB sound card.

sudo nano /usr/share/alsa/alsa.conf 
sudo apt-get update sudo apt-get install bluez pulseaudio-module-bluetooth python-gobject python-gobject-2 

Note: bluez is used to manage bluetooth and pulse-audio is used for sound-management.

Читайте также:  Bluetooth цап bt 30 brzhifi

Change audio default settings

Add «pi» user (or whichever is your user) to the lp group to allow it to manage bluetooth

Change the default bluetooth audio settings

The original tutorial says to edit sudo nano /etc/bluetooth/audio.conf, but no such file in latest RPI. Instead, edit /etc/bluetooth/main.conf.

Add complete the following line in the [General] section:

Enable=Source,Sink,Media,Socket 

Configure pulse-audio resampling algorithms

sudo nano /etc/pulse/daemon.conf 

Add or edit the following line:

Pair with your bluetooth device

The RPI 3 comes with bluetooth.

I used the GUI and followed these steps:

1. Right click the bluetooth systeay icon at the top right and click "Make discoverable" 2. Right click the bluetooth systray icon at the top right. Add device , then select the appropriate device from the scanned list, and connect. This will ask to confirm a code on both the RPI and the bluetooth device. Confirm on both sides. 3. Connect via the Bluetooth manager: Menu > Preferences > Bluetooth Manager, right click on the device and click "Connect" 

Note: I found the above process to work for me, but not sure I need to connect twice.

The device needs to be paired and trusted.

Connect bluetooth source with local sink with pulse-audio

Make sure pulseaudio daemon is running

List pulse-audio controller sources

In the list you should see something like bluez_source.AA_AA_AA_AA_AA_AA where AA_AA_AA_AA_AA_AA is the MAC address of your bluetooth device.

List pulse-audio controller sinks

Note: you must change the name of the sink and source to the names of your own bluetooth device and sink:

pactl load-module module-loopback source=bluez_source.AA_AA_AA_AA_AA_AA sink=alsa_output.usb-0d8c_C-Media_USB_Headphone_Set-00-Set.analog-stereo

You can test by playing a youtube video, music file, etc. on your bluetooth-connected phone.

TODO: add instructions for automating connection and sink/source coupling. Haven’t gotten to that part yet.

Источник

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