I'm trying to use a bluetooth module with multiwii but I've run into a problem when trying to change the baud rate to 115200. I'm using the JY-MCU board (similar to the HC-05 board). This is the code I'm using to change the baud rate:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup()
{
Serial.begin(9600);
Serial.println("Enter AT commands:");
BTSerial.begin(9600); //gets changed to 115200 when the module is changed
}
void loop()
{
if (BTSerial.available())
Serial.write(BTSerial.read());
if (Serial.available())
BTSerial.write(Serial.read());
}
Everything works fine at 9600 and all other baud rates less than 115200. Typing AT, then AT+BAUD8 returns:
Enter AT commands:
OKOK115200
but when the baud rate is at 115200 and send, AT then AT+VERSION, It returns things like this:
Enter AT commands:
OéO)+¹vo¹«L þ
I need 115200 baud rate to work with multiwii but I don't know why it isn't working.
1 Like
If it says 115200OK, you have succeeded in changing it.
Get rid of the software serial library and use hardware serial on pins 0,1. You may require software serial to configure, but that does not oblige you to use it for work.
JY-MCU is not the module, it's the breakout board and is common to HC-05, HC-06, and probably others. I believe you are using an HC-06 and you need to run at 9600 to send AT commands i.e. AT mode speed is not the same as comms mode speed.
Nick_Pyner:
you need to run at 9600 to send AT commands
From what I've been doing, sending AT commands at baud rates like 57600 and below with the code I'm using work fine, its just 115200 which I need that isn't working.
115200 Is unreliable with software serial. Get rid of it and use hardware serial. If you get any better than 38400 with Software serial, you are just being lucky and it probably won't last.
You still have not indicated which version of bluetooth you are using. As far as I'm aware all HC-06 have four pins and all HC-05 six pins.
On HC-05, the baud rate for AT mode is 38400. If you think you are sending AT commands at anything other than the proper speed, you are probably just kidding yourself.
The HC-06 default rate for AT mode is 9600, and the same applies.
If you have succeeded in setting bluetooth to 115200, then future programmes unsurprisingly need to reflect that with the command Serial.begin(115200);
Thanks, the problem was with using software serial.