2013-07-04 137 views
0

我想让我的ardunio通过蓝牙与我的覆盆子pi进行通信。到目前为止,我已经让他们使用Minicomm进行通信,但我还没有成功使用pyserial。我已经尝试过无数次的事情,但是我无法完成它的工作; 有几件事情我肯定知道(从minicomm和其他的东西):蓝莓与覆盆子pi

  1. 有一个连接
  2. 串口它的/ dev/rfcomm0
  3. 上的Arduino的代码工作
  4. 该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() 
01码

你可以假设缩进是正确的......我不确定如何在这里修复它们 但是我的代码运行到line inputs = bluetooth.readline();那么它只是挂起 有没有人有这方面的经验?任何解决方案知道我可以使用的任何其他模块?

+0

我改正了缩进,我认为,用空格替换标签,请仔细检查我做对了,如果你有时间。 – dsolimano

回答

2

你确定Arduino方正在发送换行符(“\ n”)吗?该代码将挂起,除非它收到一个换行符。见的readline的pySerial文档(): pySerial API

阅读其终止端的行(EOL)字符(默认\ n)的,或者直到超时的线。

如果您确定Arduino正在发送换行符,请将代码从Arduino发布到此处。

+0

嗯,不好意思看看,截至目前它随机开始工作。我不知道为什么,但生病仍然复查 – jped