Go Down

Topic: Cannot configure HC-06 module (Read 370 times) previous topic - next topic

lesept

Sep 22, 2018, 11:47 pm Last Edit: Sep 22, 2018, 11:49 pm by lesept
Hi
I have an HC-06 module that I'd like to configure, mainly to change the baud rate and possibly its name. I know that it works because I have successfully paired it with my cell phone using Bluetooth Electronics.

However, everything I tried to configure it using a Arduino nano did not work. It is correctly wired (VCC to 5V, GND, Rx to D2 with a resistance bridge, Tx to D3).

I tried several Arduino sketches such as
Code: [Select]
/* HC-06 Config est un programme qui permet de configurer le module Bluetooth*/

// Création d'une liaison série sur les broches 2 et 3
#include <SoftwareSerial.h>   // appel de la bibliothèque
SoftwareSerial HC06(2, 3);    // RX, TX

void setup()
{
  HC06.begin(9600); 
  Serial.begin(9600);
  Serial.println("Entrer la commande AT:");
}

void loop()
{
  // si le HC-06 transmet, on écrit le message dans le moniteur série
  if (HC06.available()) Serial.write(HC06.read());
  // si on écrit dans le moniteur série, on transmet le message au module HC-06
  if (Serial.available()) HC06.write(Serial.read());
}
but nothing works. When typing AT or any other AT command, there is no answer. The serial console does not display any answer. What's wrong ?

I bought it in China

If nothing works, I just need to know its baudrate to use it. How can I know it ?
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

Nick_Pyner

It is correctly wired (VCC to 5V, GND, Rx to D2 with a resistance bridge, Tx to D3).
Code: [Select]

SoftwareSerial HC06(2, 3);    // RX, TX

I bought it China
I just need to know its baudrate to use it. How can I know it ?
No, it isn't correctly wired. You appear to have Rx/Tx the wrong way round, and succesfully pairing it with your phone does not prove the communications wiring is kosher. There is probably nothing wrong with the code, and the fact that you bought it from China is irrelevant, they all come from China. The baud rate is 9600 by default. If that is all you need to know, you probably don't need to configure it, as they work fine out of the box.

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

lesept

#2
Sep 23, 2018, 12:58 pm Last Edit: Sep 23, 2018, 02:15 pm by lesept
You're right, it was Rx to D3 using bridge, and Tx to D2

The ino sketch you point to seems to work : each time I enter a character it gets repeated (only the last character when typing several). But it's not communicating with the bluetooth device (or maybe I don't understand correctly)

Code: [Select]
/* This is a simple test for two way traffic via bluetooth
   but you can try it first using the USB cable to the serial
   monitor without the bluetooth module connected.
   
   Note that some bluetooth modules come set to a different baud rate.
   This means you need to alter the command
                Serial.begin(9600) accordingly
   Same goes for the setting in the bottom right corner on the
   serial monitor */
String readString;
char c;
void setup()
{
    pinMode(0, INPUT_PULLUP);// only needed for  JY-MCUY v1.06?
    Serial.begin(9600);
    Serial.println("OK then, you first, say something.....");
    Serial.println("Go on, type something in the space above");
    Serial.println(" and hit Send or Enter,");
    Serial.println("then I will repeat it!");
    Serial.println("");
}

void loop() {
    while (Serial.available())
  {
    delay(3); 
    c = Serial.read();
    readString += c;
  }// end while
  if (readString.length() >0)
  { 
    Serial.write(c); 
   readString=""; 
  } // end if
}


EDIT : Yes, I didn't understand correctly. Now I have connected Rx from BT to Tx from Nano, and vice versa. It doesn't work : I get the "welcome message" but when I enter a character, there is no answer.

I just want to change the baud rate.
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

Nick_Pyner

Maybe I haven't explained it well enough. The code is for comms between Arduino and phone via bluetooth. You can have serial monitor on but just to look. Initial message comes up on phone after pressing rest button on Arduino. All it does is prove the point. If you get anything at all, the wiring and procedures are OK.  The notes have more than one example of config for HC-06. If they are obscure, try the Martyn Currey site. Do not confuse HC-06 and HC-05 config. procedure.

lesept

#4
Sep 23, 2018, 08:01 pm Last Edit: Sep 23, 2018, 08:04 pm by lesept
Thank you. Let's see if I understand correctly:
  • I upload and run your sketch
  • I open the BT console on my Android device, discover the HC06 module and connect to it.
  • Up to now, ok: the console (Android) says "connected", the red led on the BT module changes rate (2 blnks in a second, then nothing for 5 seconds or so)
  • Then I type "hello" in the Android console and send it: nothing appears on the Arduino console.
  • If I type "Hello" in the Arduino console nothing appears on the Android console.

Is there anything I didn't do well? Or is it coming from the BT module?
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

Nick_Pyner

See items 6,7. Phone only talks to Bluetooth, and you are doing that OK.

lesept

I guess you refer to this:
Quote
1. Ensure current serial.print in your code is the default 9600
2. Connect bluetooth as shown in diagram in section 4. LED flashes 2Hz.
3. Run programme
4. Power up device and get bluetooth to scan for Arduino's bluetooth
5. Default password is 1234, or maybe 0000 to pair it. LED still flashes 2Hz
6. Run terminal programme in device and make Bluetooth connection from there
7. LED flash rate changes, may even be solid.
8. See data stream in terminal
Yes, 6 and 7 are ok, but I don't see any data stream anywhere
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

Nick_Pyner

No, I am referring to items 6, on p7, and 7, on p8. Also note diagram on p4, and summary, item 15.
Do not use Arduino serial monitor.

lesept

OK, I did everything like you said and it works as expected. But...

I'd like to change the baudrate, increase it if possible up to 115200. I tried Martin Currey's sketch, select 9600 and 'no NL+CR' on the serial monitor, but I only get the message "Enter AT commands:". When I type AT, I expect OK as an answer, but nothing is displayed on the serial monitor.

I do the same connexions:
the only difference is that I use 1.2k and 1.8k resistors.

What is going wrong?
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

Nick_Pyner

IF you are getting two-way communication as I have described, it proves that your code, components, procedure, and wiring are all kosher. And I'm sure that includes the voltage divider, which should be the least of your problems.

The message "Enter AT commands:" comes from Arduino and doesn't prove anything about Bluetooth.

I'm afraid I am at a loss to explain this, but it can only be procedural, and I can only offer two wild longshots.

!. You are trying to configure via bluetooth, i.e. the phone. You can only do it via serial.

2. It's not an HC-06, it's an HC-05. I say this only in the light of recent thread on this forum, where it was pretty clear that was the case. The module was on a GW-040 breakout board, ahd four pins, and identified itself as "HC-06".  A genuine HC-06 identifies as "LINVOR".



lesept

Quote
It's not an HC-06, it's an HC-05. I say this only in the light of recent thread on this forum, where it was pretty clear that was the case. The module was on a GW-040 breakout board, had four pins, and identified itself as "HC-06".  A genuine HC-06 identifies as "LINVOR".
This describes the situation. What can I do in this case?
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

Nick_Pyner

#11
Sep 25, 2018, 04:29 pm Last Edit: Oct 15, 2018, 01:58 am by Nick_Pyner
Not having seen a GW-040, the following are guesses.

1. If the board has a button by the KEY pin, try holding it down as you apply power. If the LED flashes at a much slower cycle, you are in AT mode.  You only need top hold the button down momentarily. Arduino<>Bluetooth serial must be set at 38400 for config.

2.  If there is a button but no joy, solder a new pin into the vacant KEY point, connect that to 5v, and try again.

3. If there is no button, you might apply 3.3v to pin 34, thereby bypassing whatever circuitry there is, or isn't, for this purpose. This can probably be done using a probe, rather than soldering a wire.


You might also reconsider whether you really need to use 115200, you probably don't and you already know that it works fine at 9600 but, if you do any of the above tricks, some feedback will be appreciated.

I believe you can verify this module is an HC-05 by checking voltage on pin 31, which is the LED. This pin is not connected on a kosher HC-06.

Go Up