HC-06 Bluetooth module setup

Today I got the “Bluetooth JY-MCU HC-06 RS232 Serial Transceiver Module” I had ordered off eBay.

Wireless Bluetooth JY-MCU HC-06 RS232 Serial Transceiver Module

Wireless Bluetooth JY-MCU HC-06 RS232 Serial Transceiver Module

I had documented myself on the set-up process, yet I thought I’d leave some feedback for other people who might be just starting with embedded systems and the HC-06 Bluetooth module.

A few heads up:

  1. When I received the module, command mode (also referred to as “AT command mode”) was accessible at 9600 baud, while the module was not paired.
  2. The silkscreen suggests that VCC can be in range 3.6V-6V. That might be true for the working of the HC-06 core board but in practice, 4.1V did not seem enough when I tried. The module’s LEDs only started flashing into life once I ensured VCC was 5V. It might be related to the current provided through the supply circuit, so mind that as well.
  3. Commands don’t need any CR or LF terminator. The input is timed: you paste a command into the serial monitor and upon a timeout expiration the command is checked and executed. The timeout is about a second, or something like that, hence you’re better off pasting entire commands into the serial monitor rather than trying to type them char by char. That is unless your serial monitor buffers input, as the Arduino one does.

Here’s a dump of the few commands I tried:

ATOKAT+VERSIONhc01.comV2.0AT+BAUD8OK115200

Separating input from output we get:

Command: AT
Response: OK
Command: AT+VERSION
Response: hc01.comV2.0
Command: AT+BAUD8
Response: OK115200

After the baud change, command mode too was only accessible at 115200 baud, i.e. not just data mode.

I’ve put together an Arduino sketch to provide a friendly access console on a board with two serial ports, one of which is a USB serial one connected to a PC:

/*
 * This sketch was developed on a Leonardo board and demonstrates
 * access to the command mode interface for the HC-06 Bluetooth
 * transceiver.
 *
 * (C) 2016 Luigi Di Fraia
 */

void setup() {
  /* Put your setup code here, to run once */

  /* Initialize USB Serial */
  Serial.begin(115200);

  /* Initialize UART 1 used by the Bluetooth transceiver in command mode (i.e. when not paired) */
  Serial1.begin(9600);	/* My HC-06 module shipped for 9600 baud */

  /* Wait until the USB CDC serial connection is open */
  while (!Serial) ;

  /* Discard anything that was received */
  while (Serial.available() > 0)
    Serial.read();

  /* Show banner */
  Serial.println(F("AT Console for the HC-06 Bluetooth module by Luigi Di Fraia"));

  /* Remind user that a CR character suffices to terminate lines */
  Serial.println(F("Note: Ensure your terminal buffers input and ends lines just with a CR"));
}

void loop() {
  /* Put your main code here, to run repeatedly */

  while (Serial.available()) {
    byte b = Serial.read();
    if (b == '\n') continue;  /* Discard Line Feeds */
    if (b != '\r') {
      Serial1.write(b);
    } else {
      Serial.write("\r\n");
    }
  }

  while (Serial1.available())
    Serial.write(Serial1.read());
}

Here’s the output for a couple of commands I tried:

AT Console for the HC-06 Bluetooth module

AT Console for the HC-06 Bluetooth module

Input and output don’t get mixed, which should help those who are just starting with this stuff. That’s it folks.

This entry was posted in Technical and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s