python蓝牙编程代码_以编程方式通过python将蓝牙设备绑定到rfcomm

本文介绍了一种通过Python脚本实现M5Stack Stick C与树莓派之间的蓝牙串行通信的方法。首先,展示了如何在树莓派上初始化串行端口并进行数据处理。然后,探讨了如何通过Python自动连接到已知MAC地址的M5Stack Stick-C,避免手动绑定。最后,提供了使用Python标准库和Bluedot库进行连接的示例代码。
摘要由CSDN通过智能技术生成

我用python编写了一个脚本,用于M5Stack Stick C(如raduino)与树莓派之间的串行通信。一切正常。我可以将树莓派中的“ X”,“ Y”或“ Z”发送到棍子,他将把值(G-Force)返回给raspi!到现在为止还挺好

代码:

在raspy上使用Python:

import serial

import time

import threading

ser = serial.Serial('/dev/rfcomm5') #init serial port

input_line = []#init input char array

def process_data(_data):

#called every time a sream is terminated by \n

#and the command string is ready to use

command = convert(_data)

print(command)

def convert(s): #convert the char list in a string

new = "" #init string to append all chars from char array

for x in s: # traverse in the string

new += str(x)

return new # return string

def processIncomingByte(inByte):#adding incoming chars to input_line

global input_line# globalize

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值