Bluetooth HC-06 AT responds only to ONE command


hello, bought hc-06 adapter. want change it's baud rate. searched entire web , nothing works. command can work at+namexxx. answer oksetname, expected. at, at+version, at+baudx, at+pinxxxx, nothing returns message. i'm using sketch. i'm using softwareserial, voltage divider. bought today second module, nothing changed.

code: [select]
// basic bluetooth sketch hc‐06_01
// connect hc‐06 module , communicate using serial monitor
//
// hc‐06 defaults @ mode when first powered on.
// default baud rate 9600
// hc‐06 requires @ commands in uppercase. nl+cr should not added command string
//
#include <softwareserial.h>
softwareserial btserial(2, 4); // rx | tx
// connect hc‐06 tx arduino rx on pin 2.
// connect hc‐06 rx arduino tx on pin 3 through voltage divider.
//
void setup()
{
serial.begin(9600);
serial.println("enter @ commands:");
// hc‐06 default serial speed 9600
btserial.begin(9600);
}
void loop()
{
// keep reading hc‐06 , send arduino serial monitor
if (btserial.available())
{
serial.write(btserial.read());
}
// keep reading arduino serial monitor , send hc‐06
if (serial.available())
{
btserial.write(serial.read());
}
}

this makes no sense. if 1 command works, should. i'm guessing timing problem. code below might fix that. uses wiring , 1 shot - no hands.
code: [select]
/*
 one shot
 kudos marguskohv - sowed seed....
serial monitor aide memoire
 */
#include <softwareserial.h>
softwareserial serial1(2, 4); // rx | tx
string command = ""; // stores response hc-06

void setup() {
  // put setup code here, run once:
  serial.begin(9600);       //monitor
  serial1.begin(9600);      //bluetooth

  serial.print("at      "); 
  serial1.print("at");                  //ping
  if (serial1.available()) {
    while(serial1.available()) { // while there more read, keep reading.
    delay(3);
    char c = serial1.read();
      command += c;   
    }
  }
  delay(2000);
  serial.println(command);
  command = ""; // no repeats

  serial.print("at+namefosters      ");
  serial1.print("at+namefosters");        //change name
  if (serial1.available()) {
    while(serial1.available()) { // while there more read, keep reading.
        delay(3);
      command += (char)serial1.read(); 
    }
  }
  delay(2000);
  serial.println(command);
  command = ""; // no repeats

  serial.println("at+pin1234");
  serial1.print("at+pin1234");        //change password
  if (serial1.available()) {
    while(serial1.available()) { // while there more read, keep reading.
        delay(3);
      command += (char)serial1.read(); 
    }
  }
  delay(2000);   
  serial.println(command);
  command = ""; // no repeats

  serial.print("at+baud8      "); 
  serial1.print("at+baud8");               //change speed 115k
  if (serial1.available()) {
    while(serial1.available()) { // while there more read, keep reading.
      command += (char)serial1.read();   
    }
  }
delay(2000);       
serial.println(command);
}

void loop(){
}   //one-shot - nothing here


Arduino Forum > Using Arduino > Programming Questions > Bluetooth HC-06 AT responds only to ONE command


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???