Baudrate problem with bluethooth HC-06 device

Hello,
I'am working on communication between a quadricopter and a phone or computer, and i want to evaluate rate and reliability of bluetooth protocol. I'am using the module HC-06. Default baudrate is 9600. I've successfully exchange datas between arduino and my computer using Processing (running Ubuntu, with HC-06 binded on rfcomm port).

I can have about 350 Hz but some datas are lost. When i send a number list (for instance 1,2, .... n), i read on processing 1,2, 5, 6, 12 ... Some numbers are lost during high rate exchange. Are there solutions for this problem ?

I've then try to change bautrate with AT commands (AT+BAUD8), and the module had answered "OK115200"
Result ... datas received are wrong :frowning: See on this screenshot :

With this arduino code :

void loop(){
  c++;
  BT.println(c);
  BT.println("AT");
  delay(100);
  
}

Received on processing (see terminal which write all datas received) :

Processing have calculated 20 Hz and not 10 because 2 lines are writtens into each loop ...
But data received is just bullshit. And it's same thing with all baudrates (in processing, see line 16 on screenshot).
However, bluetooth can be appaired with processing only if specified baudrate in arduino code is 115200 !
In setup :

void setup(){
  pinMode(BTX, INPUT);
  pinMode(BRX, OUTPUT);
    
  BT.begin(115200);                              //connexion avec le HC06 (BlueThooth en 9600 bauds)
  BT.println("Hello from Arduino");

}

The big problem is ... AT commands doesnt work any more ! I think it's because data exchanged are loss or modified such as on this example. This is code for AT commands (it works first time when i've modified baudrate). So ... Have i really lose my module ? Have you an idea to reset baudrate or fix this problem ?

       #include <SoftwareSerial.h>

              SoftwareSerial hc06(10,11);

              void setup(){

                Serial.begin(115200);
                Serial.println("ENTER AT Commands:");
                hc06.begin(115200);
                
              }

              void loop(){

                if (hc06.available()){
                  Serial.write(hc06.read());
                }

                if (Serial.available()){
                  hc06.write(Serial.read());
                }  

              }

I've try this code with all baudrate available and no answer from arduino ...

Thank you very much !

Dom49:
However, bluetooth can be appaired with processing only if specified baudrate in arduino code is 115200 !
In setup :

void setup(){

pinMode(BTX, INPUT);
  pinMode(BRX, OUTPUT);
   
  BT.begin(115200);                              //connexion avec le HC06 (BlueThooth en 9600 bauds)
  BT.println("Hello from Arduino");

}

If this is true, which I doubt, then you should use hardware serial at 115200. Your incomplete code implies you are using software serial. Software serial is never a good idea and is risky above 19200. If you configured the HC-06 once you should be able to do it again. The speed in AT mode is always 9600.

Indeed, i didn't know that > 192000 bauds was a bad idea using software serial ... I will not do it again ^^

I will look about this subject, thanks for information.

The speed in AT mode is always 9600

Ah, good news ... I will try as soon as i can, thanks.

Hi,
I've read about SofwtareSerial and it seem that SoftwareSerial is not reliable over 9600 bps ...
However i've finally see that internal communication into hc-06 (for AT commands) is always 9600 bps, such you was saying.

Unfortunately, my module doesn't respond any more ... I've tried with 2000 ms delay or 200 but nothing ...

#include "SoftwareSerial.h"

int BRX = 11, BTX = 10; 
SoftwareSerial Serial1(BTX,BRX); 
int c=0;

void setup(){
    Serial.begin(9600);
    Serial1.begin(9600);  
}
void loop(){
    String command = "";

    //Serial.println("AT");
    Serial1.print("AT");
    delay(200);
    if (Serial1.available()) {
         while(Serial1.available()) { // While there is more to be read, keep reading.
            delay(3);
            command += (char)Serial1.read();
       }
       Serial.print("Answer : ");
       Serial.println(command);
    }else{
           Serial.println("unavailable ..."); 
    }
    delay(200);
    
}

And it always responding "unavailable" (or a blank answer if i force read ...)

Just try this, I'm afraid it is a work in progress, as I have had no chance to use it..........

/* 
 This is for UNO etc with only one hardware serial. Use any of the Uno's digital pins for this, but check for the other stuff.
 
HC-06 only responds to 9600 internally.  Even if you set the baud rate to 115200, you don’t need to know that, and you can reprogramme  the module again with 9600.
 
 The circuit:
 * RX is digital pin 2 (connect to TX of other device)
 * TX is digital pin 3 (connect to RX of other device)

 JY-MCU board pins
 RX       - 3  Tx       
 TX       - 2   Rx      
 GND   - GND         
 VCC   - 5v              
 
Serial monitor is just aide memoire
 */

#include "SoftwareSerial.h"

SoftwareSerial Serial1(2,3); 

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);       //monitor
  Serial1.begin(9600);      //bluetooth 

  Serial.println("AT");  
  Serial1.print("AT");                  //PING
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
    delay(3);
    char c = Serial1.read();
      command += c;    
    }
  }

  delay(2000);
  Serial.println(command);
  command = ""; // No repeats
  Serial.println("AT+NAMEFosters"); 
  Serial1.print("AT+NAMEFosters");        //CHANGE NAME
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
        delay(3);
      command += (char)Serial1.read();  
    }
  }

  delay(2000);
  Serial.println(command);
  command = ""; // No repeats
  Serial.println("AT+PIN1234");
  Serial1.print("AT+PIN1234");        //CHANGE PASSWORD
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
        delay(3);
      command += (char)Serial1.read();  
    }
  }

  delay(2000);   
  Serial.println(command);
  command = ""; // No repeats
  Serial.println("AT+BAUD8");  
  Serial1.print("AT+BAUD8");               //CHANGE SPEED TO 115K
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
      command += (char)Serial1.read();    
      delay(2000); 
      Serial.println(command);
    } 
  } 
}

void loop(){
}   //one-shot - nothing here