Android + Arduino + RN 42 bluetooth

Hi there,

I am new to android and arduino programming, but I have a little experience in action script (adobe flash). I have managed to connect to arduino duemilanove 328 using the bluetooth from my htc hero running android 2.1. In eclipse debug window I can see that android successfully connects to arduino and writes byte message.

But on the arduino side I have no response. I am using an RN 42 bluetooth module. (Sorry cannot post links yet, but you can google search RN 42 bluetooth module for data sheet). Connected through rx, tx 3V3 and ground.

This is code am using on the arduino side

int ledPin =  13;
int val = 0;

void config_bt()
{ 
   Serial.print("BT CONFIG \n");
   Serial.println("SET CONTROL BAUD 115200, 8n1");
} 

void setup ()
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(115200); 
}

void loop()
{
    if( Serial.available() )
    {
        val = Serial.read();
        Serial.println("ENTER");
    }
   
    
    if( val == 'H' )
    {
        digitalWrite(ledPin, LOW);
    }
    else
    {
        digitalWrite(ledPin, HIGH);
    }
}

any help would be much appreciated.

Cheers

Anything to do with baud rate?

I've used an RN-41 with an arduino. I haven't tried your code but one thing I remember from my experiments was that it's important to get the rx and tx pins round the right way for what you are doing - if you are using the arduino to monitor what the bluetooth module is receiving through the FDTI serial-USB chip on the arduino the connection is the opposite way round to if you are trying to get the bluetooth module to control the atmega chip on the arduino.

So basically you might need to swap the tx and rx pins.

Hi mate thanks a lot for your reply it works :), i would have never figured that out.

Now I have an other problem since I swapped the rx and tx on the arduino board am unable to upload any script. error

avrdude: stk500_getsync(): not in sync: res=0x00

I have to remove the rx tx, upload the script and then reconnect the wires for it to work.

so I jumped to SoftwareSerial and connected the rx tx from bluetooth to pins 2 and 3 but am unable to get any serial print form mySerail.

//mySerial being
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
mySerial.begin(9600);
Serail.begin(115200);

//in loop
int val = mySerial.read();
mySerial.print(val); //this never works even with serial output window set to 9600

//Serial.print(val); // this outputs some weird characters

please help

SoftwareSerial is obsolete. Try NewSoftSerial, instead.

Thanks for your quick reply will try it out this evening. Could anyone please direct me to the latest rxtx dll please.