AT COMMANDS to HC-06

Hello to everybody;
I use the following sketch in order to send, through IDE serial interface, the AT commands to my HC-06 bluetooth module:

#include <SoftwareSerial.h>
int times;
int rxPin = 3;
int txPin = 2;
SoftwareSerial hc06(rxPin, txPin);

String message; //string that stores the incoming message
char ch;
void setup()
{
 Serial.begin(9600); //set baud rate
 hc06.begin(9600); //set baud rate
}

void loop() {
 // put your main code here, to run repeatedly:
 if(Serial.available())
 {
   ch = Serial.read();
   hc06.write(ch);  
   Serial.write(ch);
 }
if(hc06.available())
 {
   Serial.write(hc06.read());  
 }
}

And it works fine, but I am not able to see, in the serial interface (Putty or others) any reply from it.
For example if I try to send the following AT command
AT+NAMESopwithCamel
Then the HC-06 module is now seen, by my mobile for example, like as ‘SopwithCamel’ but any replies appears in my serial interface, nor OK nor ‘SopwithCamel’ appear if now I try to send the AT Command
AT+NAME.
I tried the same sketch to an HC-05 module and it works fine instaed.
Could someone help me ?
Thanks to everybody will reply me.

see if HC-06 hc01.comV2.0 | Martyn Currey helps you

si la version du firmware est 3.0-2017 alors la commande pour changer le nom et le code pin sont les suivants:
AT+NAME:votre_nom
AT+PSWD:"0000"
la différence dans la nouvelle version est qu'il faut ajouter ":" pour NAME
pour PIN, la nouvelle commande est devenue PSWD et il faut toujours ajouter ":" et mettre le code entre ""
tester et voir si ça marche (votre problème n'a aucun rapport avec le sketch, ni avec le pin KEY, ni l'alimentation 3.3 ou 5v)

Yes!!!
This new HC-06 module version is such a pain! Got it from Ebay, VERSION:3.0-20170609

It doesn't respond to "old" commands.

Set speed to 9600 baud,N,8,1 and make sure to send CR/LF after each line.
The commands that surely work:

Change name:
AT+NAME:DesiredName

Change speed to 115200:
AT+UART=115200,0,0

Change pin:
AT+PSWD:"0000"

Check version of your module

I had the same problem on Arduino UNO but solved it this way:

byte RX = 3, TX = 6; // Replace as needed for you wiring
SoftwareSerial bluetooth(RX, TX); //RX, TX

bluetooth.begin(57600); //Common: 9600 or 38400. Mine is set at 57600

bluetooth.write("A"); delay(50);
bluetooth.write("T"); delay(50);
delay(500);
Serial.print("AT response: ");
while (bluetooth.available())
{
Serial.write(bluetooth.read());
}
Serial.println();
delay(500);

bluetooth.write("A"); delay(50);
bluetooth.write("T"); delay(50);
bluetooth.write("+"); delay(50);
bluetooth.write("N"); delay(50);
bluetooth.write("A"); delay(50);
bluetooth.write("M"); delay(50);
bluetooth.write("E"); delay(50);
bluetooth.write("m"); delay(50);
bluetooth.write("y"); delay(50);
bluetooth.write("_"); delay(50);
bluetooth.write("B"); delay(50);
bluetooth.write("T"); delay(50);
delay(500);
Serial.print("Name change response: ");
while (bluetooth.available())
{
Serial.write(bluetooth.read());
}
Serial.println();
delay(500);

You get the idea... It's about sending charachter one by one with 50 ms delay in between.

Link above can useful for you.

The problem is character “\r”, “\n” while you enter command.

Code

#include <SoftwareSerial.h>

#define RX 2
#define TX 3

SoftwareSerial BT(RX, TX);

void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
BT.begin(57600); // Can try from 9600 to 115200 find true baudrate
while(!Serial);
while(Serial.available())
Serial.read();
Serial.println("—Config module HC-06 new version—"); // hc01.comV2.0
Serial.println("Enter a command: ");
}

void loop() {
// put your main code here, to run repeatedly:

while(Serial.available()) {
byte b = Serial.read();
if (b == ‘\n’) {
Serial.write("\r\n");
continue;

}
if (b != ‘\r’) {
BT.write(b);
}
}

while(BT.available()) {
Serial.write(BT.read());
}
}

Source: HC-06 Bluetooth module setup | Luigi Di Fraia's e-Footsteps

Using the direct TX/RX lines on an Uno (not using software serial), I could get the serial monitor window example to work for sending commands and seeing responses, but I couldn't get a baud change command to work on startup via a script.

Splitting up the baud command string into individual writes and adding delays between characters made no difference. I noted that the manual says it enters AT command mode if it "need not pair", but it doesn't specify a duration for the module to make that determination. I added a delay before trying to talk to the module and voila! A 2 second delay before attempting to configure seems to do the trick.

The function below works to change a paired HC-06 from 9600 baud to 57600 baud. I have it near the start of my script before I start writing data out from the Arduino to the HC-06. I'm doing this check and switch every time at startup in case the module ever defaults back to 9600 for whatever reason, and so I don't have to manually switch new modules that use the same script.

void setupHC06()
{
Serial1.begin(9600);

delay(2000);
while(Serial1.available()) { //clear the read buffer after the delay
byte b = Serial1.read();
}

Serial1.write("AT+BAUD7");
delay(500); //standard response delay for AT command

Serial1.begin(57600);
while(Serial1.available()) { //clear the read buffer again before continuing
byte b = Serial1.read();
}
}

moczyj:
Using the direct TX/RX lines on an Uno (not using software serial),

The function below works to change a paired HC-06 from 9600 baud to 57600 baud.

void setupHC06()
{
Serial1.begin(9600);

It is quite legitimate to send a string of prepared AT commands in setup in a one-shot configuration programme, but I don't think there is any sense in what you are doing, and there is no point in it either. Clearly you haven't done any damage, but it is just wasted memory space. I don't think there is any proof that what you are doing works, and it looks like code written for a Mega or a Leonardo, rather than Uno. If you really need to change the rate from 9600, I wonder why you bother with 57600.