HC-05 + Android ( Wrong echos )

So I am facing a problem from a while now . Any suggestion would be good.
First I used my code to receive data from arduino , then I used the bluetoothChat and changed the uuid , I can pair , everything is good , but if I send an entire string from arduino to android I get only parts of that string.
If I use bluetooth terminal from google play everything is ok, and on the description it says it is made from the bluetooth Chat sample .

Code Arduino

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 9); //RX,TX

void setup(){
  Serial.begin(9600);
  mySerial.begin(9600);
}
void loop(){
  mySerial.println("Message to be sent!");
  delay(5000);
}

Android code : Bluetooth Chat Sample

Exemple of message received on Android:

Message to be sent!

age
s
t
essa
to be

I used AT command of HC-05 to see the baud rate , is 9600.

HC-05 includes an idle timeout of 5 seconds. When there is none data input from the MCU's side into the BT module, it switches itself into a sleep mode (w/ only 2mA current). The waking up from the sleep (from MCU side - when sending the data) takes some time and you loose some chars.
There is none such effect when you waking up the BT module from the PC side (via air), as the PC (or Android) manages the traffic somehow by repeating the packets when not answered properly.

So, a possible workaround is: you have to keep the BT busy (from MCU side) to avoid BT sleeping.. :sleeping:
PS: in your case use ie. 2secs delay instead of 5secs :slight_smile:

thanks for the reply , but then why with bluetooth Terminal ( https://play.google.com/store/apps/details?id=Qwerty.BluetoothTerminal ) I receive the correct data every time ?

Maybe your bluetooth terminal somehow pings the BT module so it keeps it awake..
Try it with 1sec delay in your loop, what happens..

void loop(){
  mySerial.println("Message to be sent!");
  delay(1000);
}

pito:
Maybe your bluetooth terminal somehow pings the BT module so it keeps it awake..
Try it with 1sec delay in your loop, what happens..

void loop(){

mySerial.println("Message to be sent!");
 delay(1000);
}

Same , but what I also see is that after I pair I get first all the messages from the buffer , I think the HC-05 does not release them . If I restart my Arduino same , I have to power off and power on the HC-05 to get rid of the previous messages , Other then that I get every second not complet messages.

Edit : I had the same problem with a hc-06 module .

Try to send something you may identify where the data come from - from BT buffer (I doubt) or from Android's BT subsystem.
For example:

void setup(){
  Serial.begin(9600);
  mySerial.begin(9600);
  long  int i = 0;
}

void loop(){
  mySerial.print("This is a message n. ");
  mySerial.println( i );
   i++;
  delay(100);
}

So first messages I think are waiting while the module is paired .
because every time I get .

is is a message n. 466
This is a message n.467
.
. ( here I get correct messages )
.
This is a message n.470
message n. 495
.
.
and after the first messages I get messages like
ssage n.534
t
essage n.m
essage n.
535

( I neved again get an entire message )

Remove the

Serial.begin(9600);

from your code..

pito:
Remove the

Serial.begin(9600);

from your code..

same.

I've been using HC-05 (several of it) with XP and Teraterm or Hyperterminal - no such issues seen yet.
I do not have android handy so I cannot help much at this stage..

I used to have an external bluetooth module for my pc , can't seem to find it now .
But I think I tested with that too and a terminal and the messages were correct .
I don't know what or maybe to to change something else on the code for bluetooth chat to receive a good message , I tested again now to see if I receive the entire message with the bluetooth terminal ( the app ) and it works , I don't get any strange messages.

new help?