Hi,
I have a very strange situation.
I own an Arduino UNO and this Bluetooth module:
I have written an Android App to communicate with my Arduino, pairing etc.
works nicely.
But if I send as example the String "testtest" from my Android Smartphone,
the Arduino recieves "t¬. ¹º", the number of characters is right, but only the first one is
correct.
I can confirm this behaviour with different transmitted data.
This is how i initialize my Bluetooth module:
#include <SoftwareSerial.h>
SoftwareSerial btConnection(8,9);
int pin = 1234;
char* name = "Arduino";
[snip]
void setupBTConnection()
{
Serial.println("Init BT");
btConnection.begin(9600);
delay(cmdDelay);
btConnection.print("AT");
delay(cmdDelay);
btConnection.print("AT+PIN");
btConnection.print(pin);
delay(cmdDelay);
btConnection.print("AT+NAME");
btConnection.print(name);
delay(cmdDelay);
btConnection.print("AT+BAUD8");
delay(2000);
btConnection.flush();
btConnection.begin(115200);
delay(2000);
btConnection.flush();
Serial.println("BT ready");
}
And this is how I read the data:
String inData="";
void loop()
{
while(btConnection.available() > 0)
{
char aChar = btConnection.read();
Serial.println("recieved ");
Serial.println(aChar);
if(aChar == '\n')
{
Serial.println("Ended");
// recieved whole data, do something
inData="";
}
else
{
inData+=(char)aChar;
}
}
}
The strange thing is, that it also never goes inside the
if(aChar == '\n') block.
The first char received is always right, and if I just send one char commands via bluetooth
everything works as expected. But I need to send more data.
First thought was that the bps are wrong, but all internet resources confirm that 115200 is the right one for bluetooth.
If i set it lower I only receive garbage, not even one char correct.
So is there something wrong in how I read the incomming data?
If I connect from CoolTerm on OSX to the Arduino over Bluetooth
with the following settings: baudrate 115200, data bits 8, parity none, stop bits 1
everything works.
So I am currently not sure where the issue is (Arduino or Android), but since
this subforum is about Networking i thought someone already tried to connect
from an Android device.
In Java (Android) I just do:
byte[] send = "testtest".getBytes();
mChatService.write(send);
where mChatService holts the BluetoothSocket and writes the data on the OutputStream.
Basically it consists of the Android Sample App "BluetoothChat" modified a bit.
Basically I do createInsecureRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); to connect to the Arduino.
Any ideas what to try out next?