树莓派板载蓝牙

安装依赖

sudo apt-get install libbluetooth-dev

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ -U pybluez

下载失败可以尝试直接git
如果没有安装git

sudo apt-get install git

直接从 PyBluez 的 GitHub 仓库安装最新代码

pip install git+https://github.com/pybluez/pybluez.git

网不好直接看我资源下载到目标位置

unzip pybluez-master.zip

解压后进入

cd pybluez-master

运行升级脚本

python setup.py install

2.代码编写
在树莓派中创建文件bt_test.py,写入以下代码

import bluetooth
bt_addr = ""
port = 1
def BlueToothInit():
    global sock
    sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
    sock.connect((bt_addr,port))
BlueToothInit()
sock.send('1')
sock.close()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值