android to arduino communication

Hello all,

I’m trying to set up communication between my android phone and arduino over bluetooth. Using a modified version of googles bluetooth chat sample I am able to connect to my arduino mega outfitted with a RN42 Bluetooth chip.

Using the following code I am able to send messages to the phone but the phone is unable to send to the arduino.

#include <SoftwareSerial.h>

int bluetoothTx = 2;
int bluetoothRx = 3;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  //Setup usb serial connection to computer
  Serial.begin(9600);

  //Setup Bluetooth serial connection to android
  bluetooth.begin(115200);
  bluetooth.print("$$");
  delay(100);
  bluetooth.println("U,9600,N");
  bluetooth.begin(9600);
}

void loop()
{
  //Read from bluetooth and write to usb serial
  if(bluetooth.available())
  {
    char toSend = (char)bluetooth.read();
    Serial.print(toSend);
  }

  //Read from usb serial to bluetooth
  if(Serial.available())
  {
    char toSend = (char)Serial.read();
    bluetooth.print(toSend);
  }
}

As far as I can tell (not great with arduino) its looking for a char to print not a string?
Can i convert char to string?

Thanks

As far as I can tell (not great with arduino) its looking for a char to print not a string?

It? What is "it" that is looking for a char to print?

Using the following code I am able to send messages to the phone

So, that means that the bluetooth device is properly connected, and that it is properly configured, and is paired with the phone.

but the phone is unable to send to the arduino.

Sounds like a problem with the app on the phone, rather than an Arduino problem.

Thank you for the reply

I've since loaded the app onto another phone and was able to send messages both ways on them

android to android works great android to arduino works only one way as described

This makes me believe that its something on the arduino side

char toSend = (char)bluetooth.read(); Serial.print(toSend);

does this snippit mean that toSend is a char and that it is printing that char to the serial monitor?

does this snippit mean that toSend is a char

Yes.

and that it is printing that char to the serial monitor?

No. It is sending that character to the serial port. There may any number of things on the other end of the serial port - one of which might be the serial monitor.