Close

Configuring the HC-06 Bluetooth Serial Module

A project log for Train Your Brain with NeuroFeedback

Brain hacking!!! Improve your focus and concentration by training your brain using NeuroFeedback.

tom-meehanTom Meehan 10/03/2016 at 04:062 Comments
Some REALLY BASIC! Background on Bluetooth Communication

Being very, very new to working with Bluetooth, myself, I decided to include some additional information so that others can hopefully avoid making the same mistakes that I've made:

Slave vs Master

Pairing

Profiles (devices need to support the same profile to communicate - "communication profiles") – this is not an exhaustive list

- A little note on profiles and their importance: I have an older android smartphone (Bluetooth and WiFi capable), an IPhone 5 and a Kindle Fire. It turns out that none of them support the Bluetooth Serial Port Profile and as a result the only way I can use the Bluetooth connection is with my laptop and a Bluetooth USB dongle. So, if you are planning to use this with a specific device make sure to check if it supports SPP (Serial Port Profile) Bluetooth Profile. If your device does not Bluetooth SPP (turned out that none of the devices I have support it) then you'll need a USB Bluetooth dongle that supports SPP (around $5).

Bluetooth Modules (again: really basic!)

Be sure to ca

AT Commands

You can find these on the datasheets for the Bluetooth Serial Modules (you can find them online - none of the ones I ordered included the datasheet). AT commands apply to both the HC-05 and HC-06 boards. These are the ones we need to setup the HC-06 breakout:

Setting up the HC-06 Bluetooth Slave Module (SPP – Serial Port Profile)

Configuring the Bluetooth Slave Module for 57600 baud rate (most modules seem to be configured for 9600 baud rate as the default setting) **This step should be done with the Bluetooth Module alone (not connected to the TGAM1 board)**

Wiring the HC-06 and configuring using an Arduino

Bluetooth TX goes thru level shifter to Arduino TX (Pin 3). Bluetooth RX goes thru level shifter to Arduino RX (Pin 4).

Arduino Code:

/*
HC-06 Bluetooth simple setup sketch

*** Important. If you change the HC-06 baud rate, you must change the "myserial" baud to match what was just set. 
* Steps:

Changing default 9600 baud to 57600 baud needed to communicate raw data from TGAM1 chip
1) uncomment (remove the double backslash) the line:  //btSerial.begin(9600); 
2) uncomment the line:  //btSerial.print("AT+BAUD7"); // Set baudrate to 57600
3) run the sketch.  This will set the baud to 57600.  However, you may not see the response OK. 
4) comment out (add double backslash back) the line btSerial.begin(9600);
5) uncomment the line //btSerial.begin(57600); and compile and load the sketch again - this sets "btSerial" to the new setting.
6) open the serial monitor from the Arduino IDE - this will restart the sketch.  Be sure that the communication speed 
on the serial monitor is set to 57600.  If all is well you should see a secomd line after "Hello Bluetooth"
that will show the BT module responding to the change.
7) you can verify the connection by typing "AT" in the serial terminal and sending.  You should recieve "OK" back


*/
#include <SoftwareSerial.h>

SoftwareSerial btSerial(3, 4);      // RX, TX

void setup()
{
pinMode(3, INPUT_PULLUP);
//Serial.begin(9600);                 //Step one - Comment out after setting tp 57600
Serial.begin(57600);
Serial.println("Hello Bluetooth");  //prints in serial monitor when it is opened
//btSerial.begin(9600);               //Step one - Comment out after setting to 57600
btSerial.begin(57600);            //Un-Comment - after setting baud to 57600
//delay(1000);
//btSerial.println("AT+RESET");
delay(1000);

btSerial.print("AT");               //pings the HC-06 - should send back OK to serial monitor
delay(1000);
btSerial.print("AT+PIN1234");       //Set pin to 1234
delay(1000);
btSerial.print("AT+NAMEBrain");   //Set the name to Brain
//delay(1000);
//btSerial.print("AT+BAUD4");       //Set baudrate to 9600
btSerial.print("AT+BAUD7");       //Set baudrate to 57600
Serial.write(btSerial.read());
delay(1000);
}

void loop()                         //run over and over
{
if (btSerial.available())
Serial.write(btSerial.read());
//Serial.println(btSerial.read());
if (Serial.available())
btSerial.write(Serial.read());
}
I'll post this code in the Documents Section and on the GitHub Repository.

If you followed the directions in the Arduino code (above) then your module is ready to connect to the TGAM1 board.

Discussions

mbonea daniel wrote 04/04/2018 at 07:33 point

Please write a little more on the profiles and how to configure the Bluetooth modules to those profiles

  Are you sure? yes | no

Németh Csaba wrote 12/17/2017 at 13:46 point

Great tutorial!

I think it will be very useful for me :)

I would like to use HFP and PBAP protocolls.

  Are you sure? yes | no