当前位置:   article > 正文

OrangePi zero puls H5 开启蓝牙

全志h5 蓝牙

OrangePI蓝牙使用


前言

我使用的板子是OrangePI zero Plus2,基于全志H5。我在上面安装好了armbian系统。我现在要使用蓝牙功能,对接我的蓝牙耳机。

安装Bluez

linux上的蓝牙官方协议即为Bluez。所以需要先安装Bluez:

root@H5:~# apt-get install bluez bluez-tools

安装完成后可以观察到系统上多出了几个工具:

  1. root@H5:~# hci
  2. hciattach hciconfig hcitool

使用工具:

  1. root@H5:~# hciconfig
  2. root@H5:~#

发现并没有蓝牙设备。

开启蓝牙设备

接下来我在网络上寻找解决方法。找到armbian论坛中的这个帖子,其中thc013网友描述到:

enable overlay uart 1 and add param_uart1_rtscts=1 to armbianenv.txt and adjust /etc/init.d/ap6212-bluetooth so it looks like this
sh # Start patching rfkill unblock all echo "0" > /sys/class/rfkill/rfkill0/state echo "1" > /sys/class/rfkill/rfkill0/state echo " " > /dev/$PORT devmem2 0x1f00060 b 1 echo 10 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio10/direction echo 0 > /sys/class/gpio/gpio10/value echo 1 > /sys/class/gpio/gpio10/value sleep 0.1 hciattach /dev/$PORT bcm43xx 115200 flow bdaddr $MAC_OPTIONS hciconfig hci0 up
and reboot
oh you might need to install devmem2

当然我要尝试使用这个方法了。

  1. 首先使能覆盖串口1
    根据描述这个应该是在armbianEnv.txt中,我当即去寻找这个文件,这文件应该是在启动分区中的,所以我想将启动分区mount后去修改。

    1. root@H5:~# mount /dev/mmcblk2boot1 /mnt
    2. mount: /dev/mmcblk2boot1 is write-protected, mounting read-only
    3. mount: wrong fs type, bad option, bad superblock on /dev/mmcblk2boot1,
    4. missing codepage or helper program, or other error
    5. In some cases useful info is found in syslog - try
    6. dmesg | tail or so.

    然后我发现这个armbian系统和一般的系统不太一样。boot相关文件不需要挂载直接可以查看:

    1. root@H5:~# cd /boot/
    2. root@H5:/boot# ls
    3. armbianEnv.txt dtb-4.16.0-sunxi64
    4. armbian_first_run.txt.template Image
    5. boot.bmp initrd.img-4.16.0-sunxi64
    6. boot.cmd System.map-4.16.0-sunxi64
    7. boot-desktop.png uInitrd
    8. boot.scr uInitrd-4.16.0-sunxi64
    9. config-4.16.0-sunxi64 vmlinuz-4.16.0-sunxi64
    10. dtb
    11. root@H5:/boot# vi armbianEnv.txt
    在overlays后添加上了uart1,以及又添加了一行param_uart1_rtscts=1
  2. 调整/etc/init.d/ap6212-bluetooth
    编辑这个文件

    root@H5:~# vi /etc/init.d/ap6212-bluetooth
    根据上面的帖子去修改这个文件。
  3. 安装devmem2
    这是一个内核调试实用的工具,需要安装的话使用这个链接
    将软件包传入板子内安装:

    1. root@H5:~# dpkg -i devmem2_0.0-0ubuntu1_arm64.deb
    2. Selecting previously unselected package devmem2.
    3. (Reading database ... 31834 files and directories currently installed.)
    4. Preparing to unpack devmem2_0.0-0ubuntu1_arm64.deb ...
    5. Unpacking devmem2 (0.0-0ubuntu1) ...
    6. Setting up devmem2 (0.0-0ubuntu1) ...
    7. Processing triggers for man-db (2.7.6.1-2) ...
    安装完成重启测试蓝牙功能。
  4. 失败
    我发现这个方法并不可行,我现在对这个方法有所了解了。他其实是使用这个方式开启蓝牙:

    1. root@H5:~# /etc/init.d/ap6212-bluetooth start
    2. [....] Starting ap6212-bluetooth (via systemctl): ap6212-bluetooth.serviceWarning: ap6212-bluetooth.service changed on disk. Run 'systemctl daemon-reload' to reload units.
    3. Job for ap6212-bluetooth.service failed because the control process exited with error code.
    4. See "systemctl status ap6212-bluetooth.service" and "journalctl -xe" for details.
    5. failed!
    6. root@H5:~# systemctl status ap6212-bluetooth.service
    7. ● ap6212-bluetooth.service - LSB: Patch firmware for ap6212 adapter
    8. Loaded: loaded (/etc/init.d/ap6212-bluetooth; generated; vendor preset: enabled)
    9. Active: failed (Result: exit-code) since Sun 2018-05-27 06:20:39 UTC; 2min 16s ago
    10. Docs: man:systemd-sysv-generator(8)
    11. Process: 2164 ExecStart=/etc/init.d/ap6212-bluetooth start (code=exited, status=1/FAILURE)
    12. May 27 06:20:29 H5 ap6212-bluetooth[2164]: Value at address 0x1F00060 (0xffff97239060): 0x1
    13. May 27 06:20:29 H5 ap6212-bluetooth[2164]: Written 0x1; readback 0x1
    14. May 27 06:20:29 H5 ap6212-bluetooth[2164]: sh: echo: I/O error
    15. May 27 06:20:39 H5 ap6212-bluetooth[2164]: Initialization timed out.
    16. May 27 06:20:39 H5 ap6212-bluetooth[2164]: bcm43xx_init
    17. May 27 06:20:39 H5 ap6212-bluetooth[2164]: Can't get device info: No such device
    18. May 27 06:20:39 H5 systemd[1]: ap6212-bluetooth.service: Control process exited, code=exited status=1
    19. May 27 06:20:39 H5 systemd[1]: Failed to start LSB: Patch firmware for ap6212 adapter.
    20. May 27 06:20:39 H5 systemd[1]: ap6212-bluetooth.service: Unit entered failed state.
    21. May 27 06:20:39 H5 systemd[1]: ap6212-bluetooth.service: Failed with result 'exit-code'.
    22. Warning: ap6212-bluetooth.service changed on disk. Run 'systemctl daemon-reload' to reload units.

    尝试别的解决方法

我找了一天,刷了十几个镜像,这次使用Orange PI官方的镜像:ubuntu_xenial_zeroplus2_H5_V0_3.img。
我首先安装上了这个镜像,进入了root账户。

  1. 升级软件包
    这里升级软件包时出现了一些错误,使用我这个命令将其修复。

    1. root@Orangepi:~# apt-get update
    2. Hit:1 http://ports.ubuntu.com xenial InRelease
    3. Hit:2 http://ports.ubuntu.com xenial-updates InRelease
    4. Hit:3 http://ports.ubuntu.com xenial-security InRelease
    5. Hit:4 http://ports.ubuntu.com xenial-backports InRelease
    6. Hit:5 http://ports.ubuntu.com/ubuntu-ports xenial-proposed InRelease
    7. Reading package lists... Error!
    8. E: Unable to parse package file /var/lib/dpkg/status (1)
    9. W: You may want to run apt-get update to correct these problems
    10. E: The package cache file is corrupted
    11. root@Orangepi:~# cp /var/lib/dpkg/status-old /var/lib/dpkg/status
    12. root@Orangepi:~# aptitude update
    13. Hit http://ports.ubuntu.com xenial InRelease
    14. Hit http://ports.ubuntu.com xenial-updates InRelease
    15. Hit http://ports.ubuntu.com xenial-security InRelease
    16. Hit http://ports.ubuntu.com xenial-backports InRelease
    17. Hit http://ports.ubuntu.com/ubuntu-ports xenial-proposed InRelease
  2. 安装bulez

    1. root@Orangepi:~# apt-get install bluez
    2. Reading package lists... Done
    3. Building dependency tree
    4. Reading state information... Done
    5. The following NEW packages will be installed:
    6. bluez
    7. 0 upgraded, 1 newly installed, 0 to remove and 393 not upgraded.
    8. Need to get 713 kB of archives.
    9. After this operation, 3902 kB of additional disk space will be used.
    10. Get:1 http://ports.ubuntu.com/ubuntu-ports xenial-proposed/main arm64 bluez arm64 5.37-0ubuntu5.2 [713 kB]
    11. Fetched 713 kB in 5s (121 kB/s)
    12. Selecting previously unselected package bluez.
    13. (Reading database ... 125410 files and directories currently installed.)
    14. Preparing to unpack .../bluez_5.37-0ubuntu5.2_arm64.deb ...
    15. Unpacking bluez (5.37-0ubuntu5.2) ...
    16. Processing triggers for dbus (1.10.6-1ubuntu3.1) ...
    17. Processing triggers for man-db (2.7.5-1) ...
    18. Processing triggers for systemd (229-4ubuntu12) ...
    19. Setting up bluez (5.37-0ubuntu5.2) ...
    20. Processing triggers for dbus (1.10.6-1ubuntu3.1) ...
    21. Processing triggers for systemd (229-4ubuntu12) ...

    安装好之后查看蓝牙设备,当然不出我所料是没有蓝牙设备的,因为我在这个文件系统的/etc/init.d/下没有看到和蓝牙启动相关的脚本。

    1. root@Orangepi:~# hciconfig hci0
    2. Can't get device info: No such device
  3. 启动蓝牙
    我根据之前的启动蓝牙方法,尝试了如下命令:

    1. rfkill unblock all
    2. echo "0" > /sys/class/rfkill/rfkill0/state
    3. echo "1" > /sys/class/rfkill/rfkill0/state
    4. echo " " > /dev/ttyS1
    5. sleep 0.1
    6. hciattach /dev/ttyS1 bcm43xx 115200 flow bdaddr 43:29:B1:55:01:01

    执行结果(这里是前面的命令都执行了一遍):

    1. root@Orangepi:~# hciattach /dev/ttyS1 bcm43xx 115200 flow bdaddr 43:29:B1:55:01:01
    2. bcm43xx_init
    3. Patch not found, continue anyway
    4. Set BDADDR UART: 43:29:B1:55:01:01
    5. Set Controller UART speed to 115200 bit/s
    6. Device setup complete
    7. root@Orangepi:~# hciconfig
    8. hci0: Type: BR/EDR Bus: UART
    9. BD Address: 43:29:B1:55:01:01 ACL MTU: 1021:8 SCO MTU: 64:1
    10. UP RUNNING PSCAN
    11. RX bytes:689 acl:0 sco:0 events:42 errors:0
    12. TX bytes:2730 acl:0 sco:0 commands:42 errors:0
    13. root@Orangepi:~# hcitool scan
    14. Scanning ...
    15. 22:22:B8:95:DE:DC X800+

    总结

经过以上尝试,我觉得他们官方的镜像应该都可以。

  1. 我觉得这个ubuntu xenial太过臃肿,我想用ubuntu server版,但是没有尝试,因为刷镜像太过烦恼。。。
  2. 我之前的那个方法不行,应该是因为我使用的armbian基于4.16内核的镜像。但是我这个板子他不支持armbian 4.14内核的镜像,会无限重启。后来我下载了Armbian源代码,自行编译出Armbian_5.45_Orangepizeroplus2-h5_Debian_stretch_next_4.14.44.img这个镜像。这个也值得一试,毕竟armbian是定制的镜像,效率会高很多,发热量也很小。
  3. 当然我觉得也可以在armbian上直接使用Orange Pi官方的wifi驱动,因为蓝牙不能用大概率是因为内核驱动的问题。

后记

我试了Armbian_5.45_Orangepizeroplus2-h5_Debian_stretch_next_4.14.44.img的镜像,然后进行了以下两步:

  1. 使能uart1

    root@H5:/# vi /boot/armbianEnv.txt

    修改如下:

    1. verbosity=1
    2. console=both
    3. overlay_prefix=sun50i-h5
    4. + overlays=usbhost2 usbhost3 uart1
    5. rootdev=UUID=73662019-22c8-4039-a605-680b57d0fb1c
    6. rootfstype=ext4
    7. + param_uart1_rtscts=1
    8. usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u
  2. 修改蓝牙服务

    root@H5:/# vi /etc/init.d/ap6212-bluetooth

    修改如下

    1. # Start patching
    2. rfkill unblock all
    3. echo "0" > /sys/class/rfkill/rfkill0/state
    4. echo "1" > /sys/class/rfkill/rfkill0/state
    5. echo " " > /dev/$PORT
    6. +devmem2 0x1f00060 b 1
    7. #on orangepi win following command never ends on first try... force to run with a timeout...
    8. -timeout 5s echo " " > /dev/$PORT
    9. -if [ $? != 0 ]; then
    10. - #timed out... retry
    11. - echo " " > /dev/$PORT
    12. -fi
    13. hciattach /dev/$PORT bcm43xx 115200 flow bdaddr $MAC_OPTIONS
    14. hciconfig hci0 up
  3. 启动蓝牙

    1. root@H5:/# /etc/init.d/ap6212-bluetooth start
    2. [....] Starting ap6212-bluetooth (via systemctl): ap6212-bluetooth.serviceWarning: ap6212-bluetooth.ser.
    3. . ok
    4. root@H5:/# hciconfig
    5. hci0: Type: Primary Bus: UART
    6. BD Address: 43:29:B1:55:01:01 ACL MTU: 1021:8 SCO MTU: 64:1
    7. DOWN
    8. RX bytes:696 acl:0 sco:0 events:42 errors:0
    9. TX bytes:2214 acl:0 sco:0 commands:42 errors:0

    启动成功

转载于:https://www.cnblogs.com/ZQQH/p/9104530.html

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号