我對這一切都有點新,所以請耐心等待 - 我真的很感謝您的幫助。將Android Nexus One與Arduino + BlueSmirf接口
我在嘗試將Android Nexus One與連接到BlueSmirf的arduino(Duemilanove)鏈接。我有一個程序,只是輸出字符串「你好藍牙」到任何設備BlueSmirf連接到。這裏是Arduino程序:
void setup(){ Serial.begin(115200); int i; }
void loop(){Serial.print(「Hello Bluetooth!」); 延遲(1000); }
一臺我的電腦BT終端我可以看到消息並連接沒有問題。麻煩是我的android代碼。我可以使用android連接到設備,但是當我查看日誌時,它不顯示「Hello Bluetooth」。下面是調試日誌:
04-09 16:27:49.022:ERROR/BTArduino(17288):螢火蟲-2583連接
04-09 16:27:49.022:ERROR/BTArduino(17288):在開始以連接所述插座
04-09 16:27:55.705:ERROR/BTArduino(17288):接收時間:16
04-09 16:27:56.702:ERROR/BTArduino(17288):接收時間:1
04- 09 16:27:56.712:錯誤/ BTArduino(17288):收到:15
04-09 16:27:57.702:錯誤/ BTArduino(17288):收到:1
04-09 16:27:57.702:錯誤/ BTArduino(17288):收到:15
04-09 16:27:58.704:ERROR/BTArduino(17288):接收時間:1
04-09 16:27:58.704:ERROR/BTArduino(17288):接收時間:15
等...
下面是代碼,我想只是把相關代碼,但如果你需要更多信息,請讓我知道:
private class ConnectThread extends Thread {
private final BluetoothSocket mySocket;
private final BluetoothDevice myDevice;
public ConnectThread(BluetoothDevice device) {
myDevice = device;
BluetoothSocket tmp = null;
try {
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) {
Log.e(TAG, "CONNECTION IN THREAD DIDNT WORK");
}
mySocket = tmp;
}
public void run() {
Log.e(TAG, "STARTING TO CONNECT THE SOCKET");
InputStream inStream = null;
boolean run = false;
//...More Connection code here...
的多個相對代碼是在這裏:
byte[] buffer = new byte[1024];
int bytes;
// handle Connection
try {
inStream = mySocket.getInputStream();
while (run) {
try {
bytes = inStream.read(buffer);
Log.e(TAG, "Received: " + bytes);
} catch (IOException e3) {
Log.e(TAG, "disconnected");
}
}
我正在讀取bytes = inStream.read(buffer)。我知道字節是一個整數,所以我嘗試通過藍牙發送整數,因爲「字節」是一個整數,但它仍然沒有意義。
它幾乎看起來是發送不正確的波特率。這是真的嗎?
任何幫助,將不勝感激。非常感謝你。
改爲使用writeln/readln組合。 – 2010-04-21 06:03:29