views:

632

answers:

5

I'm a bit new to all of this, so bear with me - I'd really appreciate your help.

I am trying to link the Android Nexus One with an arduino (Duemilanove) that is connected to a BlueSmirf. I have a program that is simply outputting the string "Hello Bluetooth" to whatever device the BlueSmirf is connected to. Here is the Arduino program:

void setup(){ Serial.begin(115200); int i; }

void loop(){Serial.print("Hello Bluetooth!"); delay(1000); }

One my computer BT terminal I can see the message and connect no problem. The trouble is with my android code. I can connect to the device with android, but when I look at the log it is not displaying "Hello Bluetooth". Here is the debug log:


04-09 16:27:49.022: ERROR/BTArduino(17288): FireFly-2583 connected
04-09 16:27:49.022: ERROR/BTArduino(17288): STARTING TO CONNECT THE SOCKET
04-09 16:27:55.705: ERROR/BTArduino(17288): Received: 16
04-09 16:27:56.702: ERROR/BTArduino(17288): Received: 1
04-09 16:27:56.712: ERROR/BTArduino(17288): Received: 15
04-09 16:27:57.702: ERROR/BTArduino(17288): Received: 1
04-09 16:27:57.702: ERROR/BTArduino(17288): Received: 15
04-09 16:27:58.704: ERROR/BTArduino(17288): Received: 1
04-09 16:27:58.704: ERROR/BTArduino(17288): Received: 15

ect...

Here is the code, I'm trying to put only the relative code but if you need more please let me know:

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...

The more relative code is 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");
                }
            }

I am reading bytes = inStream.read(buffer). I know bytes is an integer, so I tried sending integers over bluetooth because "bytes" was an integer but it still didn't make sense.

It almost appears that is sending incorrect baud rate. Could this be true?

Any help would be appreciated. Thank you very much.

A: 

Hi, I am trying to solve the same problem. If you like we could work in team to solve the problem. Do you have in any URL the android project?

My personal email: bren [at] juanantonio [dot] info

Esmetaman
+1  A: 

Did you see this project? http://code.google.com/p/android-arduino/

Cheers

Esmetaman
A: 

read() returns the number of bytes it successfully read into the buffer. Therefore, in this line of code:

bytes = inStream.read(buffer);

…your message will be found in the first bytes bytes of buffer (assuming everything else is correct). You can convert those to a String like so:

String message = new String(buffer, 0, bytes);

I'm glossing over a number of things here (encoding, concatenating multiple buffers, etc) but this should get you started.

dsandler
A: 

Hi, Manage to receive data however i cant display on the screen. my post is here...http://www.anddev.org/networking-database-problems-f29/serial-data-transfer-via-bluetooth-handler-t15004.html

want to work together?

mybmy