Sunday, June 18, 2023

HC-05 - Configuring for AT

 If you have an HC05 Bluetooth transceiver and you would like to change its name or password, or go from Mode0 ('slave') to Mode1 ('master'), then you will have to get it into AT mode.

Here are two wiring configurations. Which to use depends on whether you have a device with a pushbutton (ckt on the right) or not (ckt on the left).



Upload the following sketch. 
[ It's Martyn Currey's, basically, but he used a single letter variable ('c', which I changed to 'ch') and I like 19200 bps for Serial. ]

 #include <SoftwareSerial.h>
SoftwareSerial BTserial(8, 9); // RX | TX
const long baudRate = 38400; 
char ch =' ';
boolean NL = true;
void setup() 
{
    Serial.begin(19200);
    Serial.print("Sketch:   ");   Serial.println(__FILE__);
    Serial.print("Uploaded: ");   Serial.println(__DATE__);
    Serial.println(" ");
    BTserial.begin(baudRate);  
    Serial.print("BTserial started at "); Serial.println(baudRate);
    Serial.println(" ");
}
void loop()
{
   // Read from the Bluetooth module and send to the Arduino Serial Monitor
   if (BTserial.available())
  {
     ch = BTserial.read();
     Serial.write(ch);
  }
  // Read from the Serial Monitor and send to the Bluetooth module
  if (Serial.available())
  {
     ch = Serial.read();
     BTserial.write(ch);   
     // Echo the user input to the main window. The ">" character indicates the user entered text.
     if (NL) 
    { 
       Serial.print(">");  
       NL = false; 
    }
    Serial.write(ch);
    if (ch == 10) 
    { 
       NL = true; 
    }
  }
}

The connection to +5V should be open at first. Assuming SerMon is ready, connect 5V. You are now in AT mode. (You may like to click Reset after Uploading.)

Type AT in the text to send window, then press ENTER. The HC05 should respond with 'OK'.

To check the version, type AT+VERSION?,  then press ENTER. The HC05 should respond with '+VERSION (the number)'

To change the Name, type AT+NAME=the_name_you_like,  then press ENTER. Confirm that by Sending AT+NAME?

Find all the commands and other gorey details --

HC0305 AT manual

I'm not absolutely certain that these configs get absolute full access to the complete AT everything. I found RNAME was ignored in one instance (not thoroughly investigated). It may be that Pin34 has something more (or RNAME didn't have a purpose in re. the version I tried that on).