Couple of quick HC-06 bluetooth questions

Hi,

I think I have a defective HC-06 but thought I'd see if I could learn a bit more from the collective wisdom here :slight_smile:

Basically, using pins 12/13 as TX/RX connected via SoftwareSerial I can connect to the HC-06, write() to it in code, which then appears on my Windows 10 bluetooth serial console or on my Android BT serial console, but I never get any input. I've tried with no terminator, with LF and with CR/LF - all the same.

So just to check:

  1. Am I right that the fact that I can write() on the arduino to the BT device and see the messages on my devices means that I have the right baud rate and that the transmit side is working ?
  2. How is the baud rate negotiated when the BT connection is set up ? I realise the HC-06 is 9600 by default, but mine originally connected at 38400. However I can change this writing the relevant "AT+BAUDx" commands to the device and then using BT.begin(xxxx) where xxxx is the baud rate I've set.
  3. Does it sound like the RX line of my HC-06 is knackered ? I've checked out the cable, all fine, and tried a different arduino pin so I can't see any other possibilities. I've ordered another HC-06 so I should have a better idea on this tomorrow.

Thanks for any feedback,

David

  1. The short answer is "yes", but why don't you serial.print(data). It will probably lead to less surprises.

  2. It isn't. The baud rate is only relevant to Arduino<>Bluetooth comms, and it isn't negotiated. You decree it. Further, any connection at 38400 is very suss, and probably didn't happen.

  3. No. But it does sound rather like you don't know what you are doing, and the absence of code doesn't help in this matter. At a guess, you are simply not reading the input correctly.

You might find the following background notes useful.

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

and

http://forum.arduino.cc/index.php?topic=396450.0

If you truly have one-way traffic, things can't be serious.

Thanks, I started from scratch, popped in a new HC-06 with a voltage divider, double-checked the pins and my code worked.

I'll try the other device another time, as I'm sure it worked in a different robot, but I didn't use the voltage divider with it, maybe I just got lucky before.

Thanks for the other info and the code samples too, they're very helpful. Also the print() tip - I wasn't sure about delimiters etc. but now it's all working I understand how it all works.

dbdbdb:
I didn't use the voltage divider with it, maybe I just got lucky before.

It is clearly good practice to use the divider but I have never actually heard of a module failing due to its absence, and about half of the diagrams in Google images don't include it. Maybe you are the first, but there could be something else going on.

Turned out to be a board problem ... the BT sketch works 100% with my genuine Arduino Uno on both hardware and software serials, and software serial fails 100 times out of 100 on my Elgoo board where only the first character is received correctly and the rest are always randomly garbled. Hardware serial works 100% on the Elgoo.

When I add the BT code into the self-balancing code it only works at all at 38400 baud though this still crashes the robot once all the data has been read. At lower speeds it crashes - I think this is because the FIFO buffer on the MPU6050 overflows before it can be emptied, though this is still a working theory. I haven't tried higher speeds, I don't think the HC-06 even supports higher speeds than 38400.

Cheers,

David

I would put this all down to pilot error or user abuse before blaming any hardware. At a guess, it is all down to your insistance in using software serial.

Software serial is never a good idea - ever. I imagine your situation is about the worst possible arena for software serial and, if forward speed is your problem, engaging reverse is not a good idea.

Using software serial at 115200 is a sure recipe for disaster. I don't know anything about Elgoo, but the board is probably working normally. I'm betting you didn't get something useful on software serial at 115200 on the Uno, you just think you did, but, if that really was the case, you can put it down to good luck rather than good management, and don't expect it to be normal - no matter what serial device you may be using.

HC-06 will run just fine at 115200 - on hardware serial