2013-07-04 197 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