0
\$\begingroup\$

Short explanation: data sent over the bluetooth serial does not arrive correctly to the Arduino.

Yesterday I connected a JY-MCU bluetooth module to my Arduino UNO R3 to test it. I connected the TXD and RXD pins to Arduino pins 10 and 11 respectively and used SoftSerial to communicate. I first tried some AT commands that I found online. After AT returned OK, I ran the code found here and got this output:

Starting config
OK
OKlinvorV1.6


OK57600
Done!

So the name and pin changed failed, but I (supposedly) changed the baud rate successfully. However, any further attempt to run any AT command failed (no output), even when I set the new baud rate (57600) in the soft modem. I then tried to pair it with my PC and used the following code to test:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11);

void setup() {
  Serial.begin(9600);
  mySerial.begin(57600);
  delay(1000);
}

void waitForResponse() {
    if (mySerial.available()) {
      while (mySerial.available()) {
        int a = mySerial.read();
        Serial.println(a);
      }
      Serial.write("\n");
    }
}

void loop() {
  waitForResponse();
  delay(2000);
}

In short, I wait for the module to receive something and then print the value of every byte. What's strange is that the data I send (using cutecom on the PC) is simply not correct - for example, sending the letter A (either lowercase or uppercase) outputs the number 161. However, sending two letters A outputs the numbers 161 and 176 despite the fact they are the same letter. I have very little experience with serial communication, but this looks like the baud rate is not correct. However, if this is the case, I don't know how to change the baud rate back to 9600 since I can no longer send AT commands to the module.

Any help on how to get the module to work properly or at least an explanation on what is happening here is more than appreciated.

\$\endgroup\$
  • 1
    \$\begingroup\$ I would suggest connecting the HC-06 direct to your PC through an FT232 / PL2303 etc cable for configuring and testing. Don't faff with Arduino's SoftwareSerial - SS is never a good idea unless you really have no other choice; especially at higher baud rates. Also note that the HC-06 will only respond to AT commands when not paired with your PC. \$\endgroup\$ – Majenko Oct 11 '14 at 11:36
4
\$\begingroup\$

The baud rate 57600 is a pretty marginal on an AVR (the microcontroller used) at 16 MHz, normally OK with only a bit over 2% error but some modules can be picky. The site WormFood's AVR Baud Rate Calculator shows some good tables on error percentages for various clock / baud rate combinations.

Also I just noticed Majenko's comment and he's quite right the software serial you're using will be worse at that speed so for a start try it using a hardware UART.

That Arduino runs at 5 V logic levels so if you're not using a voltage divider to drop the transmit line to 3.3 V that might be worth try first. I've read a few mixed things about whether the HC modules are 5 V tolerant on the serial lines or not and it certainly won't do any harm trying it first to see if it resolves it.

But if neither of those steps work I'd recommend getting a USB to TTL serial converter, it seems for that module you should look for one with a 3.3 V logic level like this one for Sparkfun. They are also useful for a host of other things so are generally useful to have at your disposal.

\$\endgroup\$
  • \$\begingroup\$ Thank you - a USB to TTL worked fine and I managed to return the baud rate back to 9600 so it works fine now. However, just to be safe, I'd like to drop the voltage on the Arduino ouput. I know how to put together a voltage divider, but what should the resistance be? I assume it should be high since the load for output is probably very low, but I don't know how to determine the actual resistance? \$\endgroup\$ – fstanis Oct 15 '14 at 19:35

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.