[英]Bluetooth with raspberry pi
I am trying to get my ardunio to communicate with my raspberry pi through bluetooth. 我试图让我的ardunio通过蓝牙与我的覆盆子pi进行通信。 As of now I have gotten them to communicate using Minicomm, but I have not been successful with pyserial. 截至目前,我已经让他们使用Minicomm进行通信,但我没有成功使用pyserial。 I have tried countless things but I can not get it to work; 我尝试了无数的东西,但我无法让它发挥作用; A few things I know for sure (from minicomm and other stuff): 我肯定知道的一些事情(来自minicomm和其他东西):
Here is the code I have on my pi 这是我在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()
You could assume that the indents are correct... I am not to sure how to fix them here But my code runs till the line inputs=bluetooth.readline(); 你可以假设缩进是正确的...我不确定如何在这里修复它但我的代码运行直到行输入= bluetooth.readline(); then it just hangs Does anyone have any experience with this? 那它只是挂起有没有人有这方面的经验? Any solutions? 有解决方案吗 Know of any other modules I could use? 知道我可以使用的任何其他模块吗?
Are you sure that the Arduino side is sending a newline ("\\n") character? 你确定Arduino方面正在发送换行符(“\\ n”)吗? The code will hang unless it recieves a newline character. 代码将挂起,除非它收到换行符。 See the pySerial documentation for readline(): pySerial API 有关readline()的信息,请参阅pySerial文档: pySerial API
Read a line which is terminated with end-of-line (eol) character (\\n by default) or until timeout. 读取以行尾(eol)字符(默认为\\ n)或直到超时终止的行。
If you are sure the Arduino is sending a newline, post the code from the Arduino here. 如果您确定Arduino正在发送换行符,请在此处发布Arduino的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.