其他分享
首页 > 其他分享> > 树莓派上开启和配置蓝牙

树莓派上开启和配置蓝牙

作者:互联网

  1. 更新系统软件包

    sudo apt update
    sudo apt upgrade
    
  2. 安装相关的软件包

    sudo apt install bluetooth pi-bluetooth bluez blueman mplayer
    
  3. 启动蓝牙命令行工具

    bluetoothctl
    
  4. 开启代理

    agent on
    
  5. 扫描设备

    scan on
    

    通过扫描设备,可以检索到对应设备的MAC地址,之后可以用该设备的MAC地址来与树莓派进行配对,扫描结果如下

    [bluetooth]# scan on
    Discovery started
    [CHG] Controller E4:5F:01:26:55:90 Discovering: yes
    [NEW] Device 4A:E4:8E:E3:BC:54 4A-E4-8E-E3-BC-54
    [CHG] Device 9C:19:C2:4D:88:DC Name: Redmi Buds 3
    
  6. 树莓派与蓝牙设备进行配对

    [bluetooth]# pair 9C:19:C2:4D:88:DC
    Attempting to pair with 9C:19:C2:4D:88:DC
    [CHG] Device 9C:19:C2:4D:88:DC Connected: yes
    

    配对成功(这里我使用树莓派与我的蓝牙耳机进行配对)

  7. 连接设备(第一次配对会自动连接,否则需要执行以下命令连接)

    [Redmi Buds 3]# connect 9C:19:C2:4D:88:DC
    Attempting to connect to 9C:19:C2:4D:88:DC
    [CHG] Device 9C:19:C2:4D:88:DC Connected: yes
    Connection successful
    

    连接成功(如需退出可输入quit退出蓝牙)

  8. 连接成功后另外开启一个终端,通过mplayer播放音乐

    pi@raspberrypi:~/Desktop $ mplayer music.mp3
    MPlayer 1.4 (Debian), built with gcc-10 (C) 2000-2019 MPlayer Team
    
    Playing music.mp3.
    libavformat version 58.45.100 (external)
    Audio only file format detected.
    Load subtitles in ./
    ==========================================================================
    Opening audio decoder: [mpg123] MPEG 1.0/2.0/2.5 layers I, II, III
    AUDIO: 44100 Hz, 2 ch, s16le, 320.0 kbit/22.68% (ratio: 40000->176400)
    Selected audio codec: [mpg123] afm: mpg123 (MPEG 1.0/2.0/2.5 layers I, II, III)
    ==========================================================================
    AO: [pulse] 44100Hz 2ch s16le (2 bytes per sample)
    Video: no video
    Starting playback...
    A:   5.9 (05.9) of 256.0 (04:16.0)  1.8%
    

    可以使用alsamixer命令来控制声音的大小

标签:树莓,19,9C,蓝牙,开启,DC,88,C2,4D
来源: https://www.cnblogs.com/blueberry-mint/p/16575252.html