0

I have paired 2 BT modules HC-05 and HC-06. When I write something through Serial Monitor and send it from HC-05 to HC-06, everything works well. But when I send continuous data through loop, HC-06 receives only specific amount and then just stops! Is it because of BT module, or there is something else? My code for HC-05:

#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); 
void setup() 
{
    Serial.begin(9600);
    BTserial.begin(38400);
}

void loop()
{
        BTserial.write('1');
}

Code for HC-06:

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3);
void setup() 
{
    Serial.begin(9600);
    BTSerial.begin(9600);
}
void loop()
{
if (BTSerial.available())
    Serial.write(BTSerial.read());
}

Baud rates are good. Thanks!

  • any chance you're sending more than the receiving end can cope with, given the 4x difference in baud rates? – Chris Combs Dec 27 '19 at 18:29
  • Well, firstly in HC05 baud rate was 9600, but the data was all corrupt. I changed the baud rate in AT+UART to 38400 and same left in setup, and only after that received data came correct. – Ieva Kriščiūnaitė Dec 27 '19 at 18:41
0

I think you have 2 problems:

  • First about the shown sketch: I don't think, that the Baud rates are good. In your HC-05 code (the sender) you are using BTserial.write('1'); without any delay or other code, thus this will run very fast, so the SoftwareSerial interface is almost completely busy. You sending almost at the maximum speed, that you can get with 38400 baud. On the receiving site you are using 9600 baud, which is significantly slower than 38400 baud. How should the HC-06 transmit all data, that it get's, to the Arduino, when you only use 9600 baud, but the data is coming with 38400 baud? That cannot work. You should configure the HC-05 and HC-06 to use the same baudrate, so that this cannot happen. Or - if you really don't want to - you can restrict the overall speed, that you are sending with, by just sending less data per time unit (sending the data slower, but on the same baudrate as before). This will prevent the HC-06 to get flooded by data. (Also there might be a limit on how fast you can send data over the HC-05, but I haven't tested this). All in all it mostly isn't a good idea, to do communication totally without any speed brake. That can get you into troubles, that you mostly don't want to think of.

  • Secondly: In your comment you wrote, that you tried to change the baudrate, but that gave you garbled data. Since you didn't describe more, we cannot say much about this. But garbled data is a normal symptom for wrong baudrate. So it seems, that you haven't changed the baudrate successfully. I would suggest, that you again look into this and that you try to change the baudrate successfully. It is possible and there are many tutorials and codes on the web, that show how it is done. (When you again have problems with this, you can ask a question about this specific problem, including all the relevant information)

  • Everywhere I changed baud rate to 9600. Swear to God, I tried that previously, it didn’t work :D But now I tried that again, also included delay(10) and everything works like a charm, thank you very much! – Ieva Kriščiūnaitė Dec 28 '19 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.