You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

树莓派蓝牙连接MicroPython乐高EV3失败,报RFCOMM/GDBus错误求助

解决乐高EV3(MicroPython)与树莓派蓝牙RFCOMM连接问题

步骤1:修复BlueZ配置以启用RFCOMM兼容模式

默认BlueZ可能禁用了RFCOMM的兼容模式,导致连接被拒。编辑蓝牙服务配置文件:

sudo nano /etc/systemd/system/dbus-org.bluez.service

找到ExecStart行,修改为:

ExecStart=/usr/lib/bluetooth/bluetoothd --compat --noplugin=sap

保存后重启蓝牙服务:

sudo systemctl daemon-reload
sudo systemctl restart bluetooth

步骤2:绑定RFCOMM端口

先手动绑定EV3的蓝牙地址到树莓派的hci0端口1:

sudo rfcomm bind hci0 <你的EV3蓝牙地址> 1

检查绑定状态:

rfcomm list

如果显示hci0: <EV3地址> channel 1 bound,说明绑定成功。

步骤3:调整用户权限

确保当前用户拥有蓝牙操作权限,避免后续连接因权限失败:

sudo usermod -aG bluetooth $USER

执行后注销并重新登录系统,使权限生效。

步骤4:EV3端MicroPython连接代码修正

确保EV3上的MicroPython代码使用正确的RFCOMM端口(默认是1),示例代码:

import bluetooth

# 树莓派蓝牙地址
rp_address = "<树莓派蓝牙地址>"
port = 1

sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
try:
    sock.connect((rp_address, port))
    print("连接成功")
    # 后续通信逻辑
except Exception as e:
    print(f"连接失败: {e}")
    sock.close()

步骤5:排除blueman冲突

blueman的自动管理可能干扰RFCOMM连接,暂时停止blueman服务:

sudo systemctl stop blueman-mechanism
sudo systemctl disable blueman-mechanism

额外检查点

  • 确认EV3和树莓派的蓝牙配对状态:在树莓派上执行bluetoothctl,输入paired-devices查看EV3是否在列表中,若不在重新配对(默认PIN码1234)。
  • 检查蓝牙服务状态:sudo systemctl status bluetooth,确保服务无报错且正常运行。

内容的提问来源于stack exchange,提问作者oleg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 19:58:19