Raspberry Pi as a audio Transmitter to a Bluetooth Speaker - audio

i wanted to ask you guys, if it is possible to use the Raspberry Pi as a transmitter from a audio source, lets say a TV for example.
I want to send the sound from the TV to the Raspberry Pi via audio Jack and then send the sound via Bluetooth to a wireless speaker. So the Rasberry should act like a bridge between TV and the speaker.
It should look like this in the end:
TV --Sound via audio jack--> Raspberry Pi ~~Sound via Bluetooth~~>
speaker
So, if there is a way, how can i do this ? Thanks in advance

RPi doen't have audio input. You need one of these adapter like this (http://raspberry-projects.com/pi/pi-hardware/audio-input) and connect input to TV and RPi output to wireless / bluetooth speakers. I haven't tried it yet. Let me your feedback.

Since a web search might bring others here as it did me, here's how I did this connecting my record player through a Raspberry Pi 3 to a Bose Portable Home/Smart Speaker.
Get an audio input into the Pi
I used a cheap USB soundcard bought on Adafruit
Identify your new PulseAudio input/source and note name
This can be done by calling pactl list sources (mine was identifiable from its name and description)
$ pactl list sources
...
Source #2
State: RUNNING
Name: alsa_input.usb-GeneralPlus_USB_Audio_Device-00.mono-fallback
Description: USB Audio Device Mono
...
Connect your Pi to your bluetooth speaker
Run sudo bluetoothctl (running this without sudo resulted in settings being forgotten upon reboot) and enter the commands below
(Optional) Give your Pi an alias when connecting over bluetooth: [bluetooth]# system-alias 'Your New BT Alias'
Enter scanning mode [bluetooth]# scan on
Put your speaker in pairing mode and wait for it to be listed in the rolling output. E.g.
[NEW] Device AA:AA:AA:AA:AA:AA AA-AA-AA-AA-AA-AA
[NEW] Device BB:BB:BB:BB:BB:BB BB-BB-BB-BB-BB-BB
[NEW] Device CC:CC:CC:CC:CC:CC My speaker's name
Pair with it referencing its address:
[bluetooth]# pair CC:CC:CC:CC:CC:CC
Attempting to pair with CC:CC:CC:CC:CC:CC
[CHG] Device CC:CC:CC:CC:CC:CC Connected: yes
Request confirmation
[agent] Confirm passkey 123456 (yes/no): yes
Connect to the speaker now
[bluetooth]# connect CC:CC:CC:CC:CC:CC
Attempting to connect to CC:CC:CC:CC:CC:CC
[CHG] Device CC:CC:CC:CC:CC:CC Connected: yes
Connection successful
Trust the speaker so it is automatically connected to when available
[My speaker's name]# trust CC:CC:CC:CC:CC:CC
[CHG] Device CC:CC:CC:CC:CC:CC Trusted: yes
Changing CC:CC:CC:CC:CC:CC trust succeeded
Note your bluetooth speaker's associated PulseAudio output/sink name
This can be done by calling pactl list sinks (again, should be identifiable by name and description)
$ pactl list sinks
...
Sink #2
State: RUNNING
Name: bluez_sink.CC_CC_CC_CC_CC_CC.a2dp_sink
Description: My speaker's name
...
Set up PulseAudio defaults
Identify a good volume level for your input so distortion is minimal. E.g.
pactl set-source-volume alsa_input.usb-GeneralPlus_USB_Audio_Device-00.mono-fallback 16000
Add your version of the following lines to /etc/pulse/default.pa to set up an audio loopback and ensure the correct devices (based on the names you noted above) are used by default:
### Make some devices default
set-default-sink bluez_sink.60_AB_D2_57_42_A9.a2dp_sink
set-default-source alsa_input.usb-GeneralPlus_USB_Audio_Device-00.mono-fallback
# Set up loopback
load-module module-loopback latency_msec=1
# Set input volume
set-source-volume alsa_input.usb-GeneralPlus_USB_Audio_Device-00.mono-fallback 16000

Related

No sound after connecting to Bluetooth device wf-1000xm3

Bluetoothctl shows my WF-1000xm3 ear phones connected. But, the earphones do not give the accoustic feedback 'bluetooth connected' and also sound does not work.
Below is the output of bluetoothctl.
$ bluetoothctl connect 14:3F:A6:81:00:38
Attempting to connect to 14:3F:A6:81:00:38
[CHG] Device 14:3F:A6:81:00:38 RSSI: -56
[CHG] Device 14:3F:A6:81:00:38 Connected: yes
Connection successful
I use EndeavourOS and installed PipeWire. The troubleshooting section of the Arch's PipeWire Wiki (https://wiki.archlinux.org/title/PipeWire), covers the problem "No sound after connecting to Bluetooth device". It refers to a udev script (https://gist.github.com/tinywrkb/04e7fd644afa9b92d33a3a99ab07ee9e), from which I copied this terminal comand
(pactl list sinks|grep Name|grep 'bluez.*.a2dp.sink'|sed 's/Name: //'|sed 's/\s//')
Which did not show any available devices.
Any idea, what the issue might be?

Bluetooth gamepad doesn't create /dev/input/event

I want to use a Gamesir T1d gamepad (Bluetooth) to read it's commands with Python, on a Raspberry Pi 3 B+ (Buster).
I am able to connect the gamepad via Bluetooth:
[CHG] Device C6:86:A1:04:BB:53 RSSI: -78
[bluetooth]# connect C6:86:A1:04:BB:53
Attempting to connect to C6:86:A1:04:BB:53
[CHG] Device C6:86:A1:04:BB:53 Connected: yes
Connection successful
[CHG] Device C6:86:A1:04:BB:53 ServicesResolved: yes
[Gamesir-T1d-BB53]# pair C6:86:A1:04:BB:53
Attempting to pair with C6:86:A1:04:BB:53
[CHG] Device C6:86:A1:04:BB:53 Paired: yes
Pairing successful
[Gamesir-T1d-BB53]# info
Device C6:86:A1:04:BB:53 (random)
Name: Gamesir-T1d-BB53
Alias: Gamesir-T1d-BB53
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: Device Information (0000180a-0000-1000-8000-00805f9b34fb)
UUID: Unknown (00008650-0000-1000-8000-00805f9b34fb)
Modalias: bluetooth:v000Dp0000d0110
RSSI: -78
[Gamesir-T1d-BB53]#
However, there is no event created under
/dev/input/
which I would need to read and map the gamepad's commands into Python.
When connecting a Bluetooth mouse, I can see events being created, so this seems to be a gamepad specific issue.
I was already trying xboxdrv, but without success, probably since the gamesir is not listed as supported device? Also, I have no glue if this is just a missing driver issue, or if there is a generic driver which could work, or if this is a driver issue at all.
What I am missing here?

[RPi3][Bluez] Managed to connect to a BLE device but can't list GATT attributes

I am doing a project where I need to create communication between two Raspberry Pi 3 on stretch (RPi) wirelessly with callback functionalities using C++ code. The first is supposed to send data to the second one. I decided to create a bluetooth connexion between the two using the on-board bluetooth-chips.
So first I decided to compile Linux Bluetooth Stack: Bluez on both RPi from source, version 5.50. Following this tutorial : https://learn.adafruit.com/install-bluez-on-the-raspberry-pi/installation on Adafruit. I managed to send a message from one pi to another using these codes :https://people.csail.mit.edu/albert/bluez-intro/x502.html. But to read a message sent by the client, I have to call the function "read(client, buf, sizeof(buf))" as shown in the server code which is a bit restrictive. I want to be notified whenever a message is received so that a callback function can be called. I saw it could be done by enabling notifications on the GATT Characteristics used for the communication.
This level of specification is not really shown on the C++ codes I got from https://people.csail.mit.edu/albert/bluez-intro/x502.html. After having improved my knowledge on GATT with this : https://www.novelbits.io/bluetooth-gatt-services-characteristics/ , I decided to follow Tony D's youtube tutorial on how to use Bluez APi
https://www.youtube.com/watch?v=5fQR2PHMDWE.
To make it easier, I decided to left one RPi aside and tried to connect a Bluetooth audio headset JBL T450BT which use Bluetooth 4.0, so it is supposed to support Bluetooth Low Energy.
On bluetoothctl here's the problem, I manage to power on the controller, scan on and detect the headset. I then trust, pair and connect. In GATT menu, I enter the command : list-attributes [dev address]. Bluetoothctl prints no error but returns nothing and is ready to receive other command lines.
sudo bluetoothctl
[bluetooth]# show
Controller XX:XX:XX:XX:XX:XX (public)
Name: VoitureRPi
Alias: VoitureRPi
Class: 0x004c0000
Powered: yes
Discoverable: no
Pairable: yes
UUID: Headset AG (00001112-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb)
UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)
UUID: Handsfree Audio Gateway (0000111f-0000-1000-8000-00805f9b34fb)
Modalias: usb:v1D6Bp0246d0532
Discovering: no
[bluetooth]# scan on
Device 78:44:05:BC:12:0C JBL T450BT
[bluetooth]# trust 78:44:05:BC:12:0C
[CHG] Device 78:44:05:BC:12:0C Trusted: yes
Changing 78:44:05:BC:12:0C trust succeeded
[bluetooth]# pair 78:44:05:BC:12:0C
Attempting to pair with 78:44:05:BC:12:0C
[CHG] Device 78:44:05:BC:12:0C Connected: yes
[CHG] Device 78:44:05:BC:12:0C UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C ServicesResolved: yes
[CHG] Device 78:44:05:BC:12:0C Paired: yes
Pairing successful
[CHG] Device 78:44:05:BC:12:0C ServicesResolved: no
[CHG] Device 78:44:05:BC:12:0C Connected: no
[bluetooth]# connect 78:44:05:BC:12:0C
Attempting to connect to 78:44:05:BC:12:0C
[CHG] Device 78:44:05:BC:12:0C Connected: yes
Connection successful
[CHG] Device 78:44:05:BC:12:0C ServicesResolved: yes
[JBL T450BT]# menu gatt
[JBL T450BT]# list-attributes 78:44:05:BC:12:0C
[JBL T450BT]#
From there I get no answer from bluetoothctl but no error as well, as I told you. I am not able to discover services/characteristics.
On the youtube tuto I followed,it was told that the GATT services and Characteristics discovery was done during the pairing/first connexion. I assume that the Pi intends to do it but fails. That's maybe why I get the sequence :
connected: yes, ServicesResolved: yes Paired successfully and then ServicesResolved: no, connected no. Nothing like : [NEW] XXX Service or Characteristcs is shown.
I don't think the problem comes from the headset because it does the same thing on other devices I connect to. I have both pulseaudio and bluealsa packages installed on the RPi.
As mentionned in this tuto
Here the bluetooth status :
systemctl status bluetooth
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2018-11-08 11:29:38 CET; 27min ago
Docs: man:bluetoothd(8)
Main PID: 2646 (bluetoothd)
Status: "Running"
CGroup: /system.slice/bluetooth.service
└─2646 /usr/local/libexec/bluetooth/bluetoothd --experimental
Here's what hciconfig gives :
hciconfig -a
hci0: Type: Primary Bus: UART
BD Address: B8:27:EB:A8:0C:20 ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING
RX bytes:11205 acl:76 sco:0 events:520 errors:0
TX bytes:219869 acl:433 sco:0 commands:150 errors:0
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH SNIFF
Link mode: SLAVE ACCEPT
Name: 'VoitureRPi'
Class: 0x4c0000
Service Classes: Rendering, Capturing, Telephony
Device Class: Miscellaneous,
HCI Version: 4.1 (0x7) Revision: 0x168
LMP Version: 4.1 (0x7) Subversion: 0x2209
Manufacturer: Broadcom Corporation (15)
Here's also what the D-Bus introspection tool returns :
busctl tree org.bluez
└─/org
└─/org/bluez
└─/org/bluez/hci0
└─/org/bluez/hci0/dev_78_44_05_BC_12_0C
├─/org/bluez/hci0/dev_78_44_05_BC_12_0C/fd1
└─/org/bluez/hci0/dev_78_44_05_BC_12_0C/player0
For people who got problems with pairing and connecting, this source was a huge help :https://www.sigmdel.ca/michel/ha/rpi/bluetooth_02_en.html
Anyway so that's my problem. I want to access Characteristics and their UUID's to be able to modify their permission or to create a new service with its own characteristics suited to my project.
To this point I think this is the only way to implement a notifier with a callback in a bluetooth communication. Maybe I'm wrong. Do you have any clue whatsoever ? :)
Thanks to A.Baur, the "--experimental" option was the last missing thing.
My system:Debian 10 + KDE
Installed:
- bluez-*
- bluetooth
- pulseaudio-module-bluetooth
Steps:
1. stop bluetooth service: >sudo systemctl stop bluetooth
2. modify: /etc/init.d/bluetooth ; by adding to the line:
SSD_OPTIONS="**--experimental** --oknodo --quiet --exec $DAEMON -- $NOPLUGIN_OPTION"
3. start bluetooth service: >sudo systemctl start bluetooth
4. connect to Bose QC35 II by bluetoothctl or other GUI tool.
I got it working in RPi with python examples of advertisement and gatt server from bluez-5.50. I used nRF tool to test it.

Siri remote (ATV4) with raspberry pi 3 bluetooth

I have a raspberry pi 3 and a 4th generation apple tv remote.
I don't understand why I am unable to see the remote when I scan with the raspberry pi using "hcitool scan" command.
I have to say that I can see other bluetooth device during the scan but never the remote.
I can see the remote when I scan with my iPhone.
My ATV4 is unplugged and i have put the remote on pair mode (menu + volume up)
What is wrong ? Thanks
I've been looking into this for a little while, and my conclusion so far is that there may be something a bit non-standard or unusual about the bluetooth in the Siri Remote / 4th generation Apple TV remote. Certainly it manages to upset LightBlue on my Mac and iPhone in slightly different ways.
If I use bluetoothctl, the remote does show up and I can connect to it (at least if I hold menu+volumeup for 5 seconds whilst bluetoothctl has discovery enabled):
root#raspberrypi:/home/pi# bluetoothctl
[NEW] Controller B8:27:EB:6C:15:98 raspberrypi [default]
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:6C:15:98 Discovering: yes
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
[NEW] Device 78:9F:70:5E:A3:14 DJ7Q6MZ9GQQT
[NEW] Device 67:8F:99:BC:EE:C5 67-8F-99-BC-EE-C5
[CHG] Device 67:8F:99:BC:EE:C5 RSSI: -64
[CHG] Device 67:8F:99:BC:EE:C5 RSSI: -44
[CHG] Device 67:8F:99:BC:EE:C5 RSSI: -64
[CHG] Device 67:8F:99:BC:EE:C5 RSSI: -44
[bluetooth]# connect 78:9F:70:5E:A3:14
Attempting to connect to 78:9F:70:5E:A3:14
[CHG] Device 78:9F:70:5E:A3:14 Connected: yes
Connection successful
[CHG] Device 78:9F:70:5E:A3:14 UUIDs:
00001800-0000-1000-8000-00805f9b34fb
00001801-0000-1000-8000-00805f9b34fb
0000180a-0000-1000-8000-00805f9b34fb
0000180f-0000-1000-8000-00805f9b34fb
00001812-0000-1000-8000-00805f9b34fb
0000181e-0000-1000-8000-00805f9b34fb
8341f2b4-c013-4f04-8197-c4cdb42e26dc
[CHG] Device 78:9F:70:5E:A3:14 Appearance: 0x03c0
[CHG] Device 78:9F:70:5E:A3:14 Modalias: bluetooth:v004Cp0266d0000

Determine USB device file Path

How can i get USB device file path correctly in Linux.
I used command: find / -iname "usb" and got the result as below:
/dev/bus/usb
/sys/bus/usb
/sys/bus/usb/drivers/usb
/sys/kernel/debug/usb
Under /dev/bus/usb i see:
001 002 003 004 005 006
But I think they aren't files as i need.
Under /sys/bus/usb/devices/:
sh-3.2# ls /sys/bus/usb/devices/
1-0:1.0 1-1:1.0 3-0:1.0 5-0:1.0 usb1 usb3 usb5
1-1 2-0:1.0 4-0:1.0 6-0:1.0 usb2 usb4 usb6
And Under /sys/bus/scsi/devices/ when i pluged an USB i see:
2:0:0:0 host0 host2 target2:0:0
And when i removed USB i see:
sh-3.2# ls
host0
So which device file is used for USB? How can i indentify it? I need to make a C program with USB device file...
Further more, could you explain to me the number 1-1:1.0? What does it mean?
Thank you.
So which device file is used for USB? How can i indentify it?
What you see behind /sys/ is mainly configuration/information about devices. /dev/bus/usb is what you are looking for. I think that the following article can help you
http://www.linuxjournal.com/article/7466?page=0,0
Is quite old, but still it can help you. (In the article they speak about /proc/bus/usb, today we have /dev/bus/usb)
Further more, could you explain to me the number 1-1:1.0? What does it mean?
The generic form is
X-Y.Z:A.B
Each field identify the connection point of your device. The first two field are mandatory:
X is the USB bus of your motherboard where is connected the USB system.
Y is the port in use on the bus system
So the USB device identified with the string 3-3 is the device connected on the port 3 of the bus 3.
If you connect an USB hub, you are extending the connection capability of a single USB port. The Linux kernel identify this situation by appending the Z field.
Z is the port is use on an hub
So, the USB device identified with the string 1-2.5 is the device connected on the port 5 of the hub connected on the port 2 of the bus 1.
USB specification allow you to connect in cascade more then one USB hub, so the Linux kernel continue to append the port in use on the different hubs. So, the USB device identified with the string 1-2.1.1 is the device connected on the port 1 of the hub connected on the port 1 of the hub connected to the port 2 of the bus 1.
A fast way to retrieve these information is to read the kernel messages (if you can).
$ dmesg | grep usb
[... snip ...]
[ 2.047950] usb 4-1: new full-speed USB device number 2 using ohci_hcd
[ 2.202628] usb 4-1: New USB device found, idVendor=046d, idProduct=c318
[ 2.202638] usb 4-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2.202643] usb 4-1: Product: Logitech Illuminated Keyboard
[ 2.202648] usb 4-1: Manufacturer: Logitech
[... snip ...]
Then, the last two fields of the pattern (after colon) identify an internal section of an USB device :
A is the configuration number of the device
B is the interface number of a configuration
So, the string 4-1:1.1 means: the interface 1, on configuration 1 that is connected on the port 1 of the bus 4.
You can retrieve these information with the command lsusb.

Resources