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.
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)
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;
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.