我正试图让我的 ardunio 通过蓝牙与我的树莓派通信。到目前为止,我已经让他们使用 Minicomm 进行通信,但我还没有成功使用 pyserial。我尝试了无数的事情,但我无法让它发挥作用;我肯定知道的几件事(来自 minicomm 和其他东西):
- 有联系
- 它的串口 /dev/rfcomm0
- arduino 上的代码正在运行
- BPS 为 9600
这是我在我的 pi 上的代码
import serial
import time
port="/dev/rfcomm0"
print('hello world')
bluetooth= serial.Serial(port,9600)
print ('hello world 2')
bluetooth.flushInput()
print ('hello world 3')
for i in range(100):
print("we are in the for loop",i)
inputs=bluetooth.readline()
print("we are in the inputs for loop",i)
inputasinteger= int(inputs)
if inputs:
print('we have inputs')
fileb= open("blue.txt",'wU')
fileb.write(inputasInteger*10)
time.sleep(.1)
print('sleeping')
fileb.close()
print('file has been closse')
exit()
你可以假设缩进是正确的......我不确定如何在这里修复它们但是我的代码一直运行到行 inputs=bluetooth.readline(); 然后它就挂了有没有人有这方面的经验?有什么解决办法吗?知道我可以使用的任何其他模块吗?