WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Howto: RPi4 built-in bluetooth  (Read 3320 times)

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14799
Howto: RPi4 built-in bluetooth
« on: May 23, 2020, 04:13:54 AM »
Using piCore-11.x

Add the following to /mnt/mmcblk0p1/config.txt:
Code: [Select]
[PI4]                   
dtoverlay=miniuart-bt
..and reboot.

Next load the required extensions:
Code: [Select]
$ tce-load -i firmware-rpi-bt bluez

$ sudo modprobe hci_uart
$ lsmod
Module                  Size  Used by    Not tainted
hci_uart               40960  0
btbcm                  16384  1 hci_uart
bluetooth             397312  2 hci_uart,btbcm
rfkill                 32768  1 bluetooth
ecdh_generic           28672  1 bluetooth
serdev                 20480  1 hci_uart
...

$ dmesg
...
[  340.413932] Bluetooth: Core ver 2.22
[  340.413970] NET: Registered protocol family 31
[  340.413974] Bluetooth: HCI device and connection manager initialized
[  340.413985] Bluetooth: HCI socket layer initialized
[  340.413992] Bluetooth: L2CAP socket layer initialized
[  340.414012] Bluetooth: SCO socket layer initialized
[  340.415635] Bluetooth: HCI UART driver ver 2.3
[  340.415640] Bluetooth: HCI UART protocol H4 registered
[  340.415675] Bluetooth: HCI UART protocol Three-wire (H5) registered
[  340.415773] Bluetooth: HCI UART protocol Broadcom registered

Start the daemons and assign the output device:
Code: [Select]
$ sudo /usr/local/etc/init.d/dbus start
$ sudo /usr/local/etc/init.d/bluez start
$ hciattach /dev/ttyS0 bcm43xx 921600 noflow
bcm43xx_init
Flash firmware /lib/firmware/brcm/BCM4345C0.hcd
Set Controller UART speed to 921600 bit/s
Device setup complete

At this point either the built-in bluez commands can be used:
Code: [Select]
$ bluetoothctl
Agent registered
[CHG] Controller DC:A6:32:67:B2:F3 Pairable: yes

[bluetooth]# power on
Changing power on succeeded
[CHG] Controller DC:A6:32:67:B2:F3 Powered: yes
[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller DC:A6:32:67:B2:F3 Discoverable: yes
[bluetooth]# pairable on
Changing pairable on succeeded
[bluetooth]# scan on
Discovery started
[CHG] Controller DC:A6:32:67:B2:F3 Discovering: yes
[NEW] Device 82:E8:2C:5C:67:B7 82-E8-2C-5C-67-B7
[NEW] Device 49:E9:25:F7:9C:91 49-E9-25-F7-9C-91
...
[bluetooth]# pair 00:1B:66:00:31:88
Attempting to pair with 00:1B:66:00:31:88
[CHG] Device 00:1B:66:00:31:88 Connected: yes
[bluetooth]# pair off
Device off not available

..or the blueman extension can be used - in testing using xmms-pulse, I was able to play music from the RPi4 to bluetooth headphones without problems.

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1243
Re: Howto: RPi4 built-in bluetooth
« Reply #1 on: May 28, 2020, 11:10:21 PM »
The miniuart has much lower data rates, and no flow control, but it does work.   But here is the "official" catchall startup script.

https://github.com/RPi-Distro/pi-bluetooth/blob/master/usr/bin/btuart


Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14799
Re: Howto: RPi4 built-in bluetooth
« Reply #2 on: May 29, 2020, 03:46:52 AM »
Ah - thanks for that, I was thinking that 460800, 921600 and 3000000 had not been pulled out of thin air, but couldn't find where they originated.

So far, I've not been able to get bluetooth working on my RPi4 without using the minuart, but I might have more luck now...

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1243
Re: Howto: RPi4 built-in bluetooth
« Reply #3 on: May 29, 2020, 06:36:23 AM »
I don’t have my image right now, but make sure you are not setting up and starting a serial console on the main uart.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14799
Re: Howto: RPi4 built-in bluetooth
« Reply #4 on: May 29, 2020, 07:27:29 AM »
I'm using the default piCore-11.x config.txt with/without "dtoverlay=miniuart-bt" - I've also tried commenting out "enable_uart=1", but I can still only get the miniuart to work.

I see the btuart script doesn't work, but doing things manually does:
Code: [Select]
$ /mnt/mmcblk0p2/scripts/btuart.sh
Can't open serial port: No such file or directory
Can't initialize device: No such file or directory
$ hciattach /dev/ttyS0 bcm43xx 460800 noflow
bcm43xx_init
Flash firmware /lib/firmware/brcm/BCM4345C0.hcd
Set Controller UART speed to 460800 bit/s
Device setup complete

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1243
Re: Howto: RPi4 built-in bluetooth
« Reply #5 on: May 29, 2020, 08:14:23 AM »
Check the kernel command line,  make sure there is not a console enabled on the serial port.

Comment out the enable_uart

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14799
Re: Howto: RPi4 built-in bluetooth
« Reply #6 on: May 29, 2020, 09:56:47 AM »
Nope, removing "console=ttyS0,115200 console=tty1" from cmdline3.txt does not help.

Thanks for the suggestions, I'll leave this for now.