将Android Nexus One与Arduino + BlueSmirf连接

efg*_*mez 11 android bluetooth arduino bluesmirf

我对这一切都有点新意,所以请耐心等待 - 我非常感谢你的帮助.

我正在尝试将Android Nexus One与连接到BlueSmirf的arduino(Duemilanove)相关联.我有一个程序只是将字符串"Hello Bluetooth"输出到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):FireFly-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:ERROR/BTArduino(17288):收到:15
04- 09 16:27:57.702:ERROR/BTArduino(17288):收到:1
04-09 16:27:57.702:ERROR/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...
Run Code Online (Sandbox Code Playgroud)

这里的相关代码越多:

        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");
                }
            }
Run Code Online (Sandbox Code Playgroud)

我正在读bytes = inStream.read(缓冲区).我知道字节是一个整数,所以我尝试通过蓝牙发送整数,因为"字节"是一个整数,但它仍然没有意义.

几乎看起来发送的波特率不正确.这可能是真的吗?

任何帮助,将不胜感激.非常感谢你.

jab*_*ena 1

你看到这个项目了吗? http://code.google.com/p/android-arduino/

干杯