Hi everybody
I am not able to get readable text from an HC 05 module which connects an android device.
An app (built from MIT AppInventor) does the simple task of sending text from user to HC 05 and displaying received text on screen. But neither the app nor the serial monitor displays any readable text.
The app simply displays question marks and the serial window displays x followed by some rectangles. The HC 05 is connected to my Mega 2560 on the Serial1 pins 18 & 19.
The code is as follows
void setup() {
 Serial.begin(9600);
 Serial1.begin(38400);
}
void loop() {
 if (Serial1.available()) {
  int inByte = Serial1.read();
  Serial.write(inByte);
 }
 if (Serial.available()) {
  int inByte = Serial.read();
  Serial1.write(inByte);
 }
}
And the Serial output is as in the image attached.
!. Confirm that HC-05 is configured to run at 38400. I probably isn't and, if not, changing all your serial1 commands to the default 9600 might give you a result.
take the app inventor stuff out of the game, and use a standard bluetooth terminal.
!. Confirm that HC-05 is configured to run at 38400. I probably isn't and, if not, changing all your serial1 commands to the default 9600 might give you a result.
THANKS A LOT!!!!!
Your solution of configuring Serial1 baud to 9600 is working magically, but it would be better if you would explain why the Bluetooth module couldn't communicate with the Mega through Serial1 on 38400 baud when the typical baud rate for HC 05 is 38400....
Saarthak_Sabharwal:
Your solution of configuring Serial1 baud to 9600 is working magically, but it would be better if you would explain why the Bluetooth module couldn't communicate with the Mega through Serial1 on 38400 baud when the typical baud rate for HC 05 is 38400....
Maybe whoever sold it to you set it up for 9600baud ?
Saarthak_Sabharwal:
Your solution of configuring Serial1 baud to 9600 is working magically, but it would be better if you would explain why the Bluetooth module couldn't communicate with the Mega through Serial1 on 38400 baud when the typical baud rate for HC 05 is 38400....
You misunderstand what configuration means. The solution was not in configuring serial1 but to simply match serial1 to the baud rate to which HC-05 is configured. The Arduino serial commands must always match the rate at which Bluetooth is configured.
The default, i.e. typical, baud rate for HC-05 communications is 9600 not 38400. This can be changed by re-configuring the device while in AT mode, most commonly to 115200, using the appropriate procedures. The baud rate used for AT mode IS 38400, and this cannot be changed.
You might find the following background notes useful.