Showing posts with label HC-05. Show all posts
Showing posts with label HC-05. Show all posts

Thursday, April 14, 2016

Config HC-05(s) as paired Master and Slave

This post show how to set a HC-05 as Master, and bind to another Slave HC-05. By default, HC-05 is set as Slave (ROLE=0), UART=9600,0,0 and PSWD="1,2,3,4", what we have to do on Slave is to copy the ADDR used to bind in Master. In Master side, what we have to do is set as Master (ROLE=1), make sure same UART and PSWD,  BIND to Slave's ADDR, and set CMODE=0, such that the Master will connect the assigned Slave only. Once set, the Master/Slave pair will auto-connect when power-up in range.



In my setup, a FTDI USB-to-Serial adapter is used to check/set the HC-05(s), Arduino Software's Serial Monitor is used to enter AT command to HC-05, all FTDI adapter, both HC-05 are set working on 3.3V.



Check the config of Slave HC-05:

Connection:
FTDI Tx - Slave HC-05 Rx
FTDI Rx - Slave HC-05 Tx
FTDI GND - Slave HC-05 GND

Conenct USB to FTDI, and open  Arduino Serial Monitor, set baud rate to 38400, "Both NL & CR".

Press the on-board button of Slave HC-05 and apply power to Slave HC-05.


Make sure ROLE=0, UART=9600,0,0, PSWD="1234" by entering AT Commands:
AT+ROLE?
AT+UART?
AT+PSWD?

Copy the ADDR:
AT+ADDR?

In my case, ADDR is 2014:12:20016

Power-off and disconnect the Slave HC-05.


Set the config of Master HC-05:

Connection:
FTDI Tx - Master HC-05 Rx
FTDI Rx - Master HC-05 Tx
FTDI GND - Master HC-05 GND

Press the on-board button of  Master HC-05 and apply power to Master HC-05.



Make suew UART and PSWD match with Slave side:
AT+UART?
AT+PSWD?

Change ROLE to Master
AT+ROLE=1

Bind to the ADDR of Slave. In my case Slave's ADDR is 2014:12:20016, replace ':' by ',', enter:
AT+BIND=2014,12,20016

And set CMODE=0:
AT+CMODE=0

Power-off the Master HC-05.


Auto connect:

Keep FTDI connect to Master HC-05. Connect TXD and RXD of Slave HC-05 together, to echo the received data back to sender.

Power-up both Master and Slave HC-05, don't press the on-board button.

Change baud rate of Arduino Serial Monitor to 9600 (match with the UART in HC-05), keep using "Both NL & CR".


Notice the blinking pattern of the on-board LED of HC-05(s), they will auto-connect once power-up.

Enter anything in Arduino Serial Monitor, it will be send to Master HC-05, and send to paired Slave HC-05 and echo back via Bluetooth,


Reference:
Elastic Sheep - Serial Bluetooth module – Master/Slave connection
iteadstudio - Serial Port Bluetooth Module (Master/Slave) : HC-05
AT Command mode of HC-05

Monday, April 11, 2016

Android BluetoothChat connect to Arduino Uno + HC-05

Last example show "Android BluetoothChat example link with HC-05 Bluetooth", to connect to PC via FTDI adapter. Here is another example - Arduino UNO + HC-05 to echo received data back to the sender.

For my on-hand HC-05 sample, it set as slave role and 9600, 0, 0, PIN="1234" by default. So it can be used in this example without any extra setting.


Connection between UNO and HC-05
HC-05 Rx - Uno Tx (1)
HC-05 Tx - Uno Rx (0)
HC-05 GND - Uno GND
HC-05 VCC - Uno 5V
(My HC-05 marked "Power: 3.6V-6V", refer here, make sure your HC-05 can work on 5V.)

Uno_Serial_echo.ino
/*
Arduino Uno + HC-05 (Bluetooth) - echo bluetooth data

Serial (Tx/Rx) communicate to HC-05
HC-05 Rx - Uno Tx (1)
HC-05 Tx - Uno Rx (0)
HC-05 GND - Uno GND
HC-05 VCC - Uno 5V

*/

void setup()
{
  delay(1000);
  Serial.begin(9600);
}

void loop()
{
  while(Serial.available())
  {
    char data = Serial.read();
    Serial.write(data);
  }
}

This video show how Android BluetoothChat example link with Arduino UNO + HC-05. For the Android BluetoothChat example, refer last post.


Related:
Connect Arduino Due with HC-06 (Bluetooth Module)





Thursday, April 7, 2016

Android BluetoothChat example link with HC-05 Bluetooth

This example show to import and modify Android BluetoothChat example, to link with low-cost Bluetooth HC-05.

reference:
First test HC-05 Bluetooth Module
AT Command mode of HC-05

We need a FTDI USB-to-Serial adapter to connect PC/USB and HC-05 Bluetooth, and use Arduino IDE's Serial Monitor as terminal, to talk with Android running modified BluetoothChat example.


This video show how to import BluetoothChat example in Android Studio, and edit BluetoothChatService.java to change MY_UUID_SECURE to UUID.fromString("00001101-0000-1000-8000-00805F9B34FB").

~ reference http://developer.android.com/reference/android/bluetooth/BluetoothDevice.htmlIf you are connecting to a Bluetooth serial board then try using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.


This video show how it run on Android device, and talk to PC running Arduino IDE's Serial Monitor, via FTDI + HC-05.

In my on-hand HC-05 sample, it set as slave role and 9600, 0, 0, PIN="1234" by default, I have not change any setting.


Cross-post with Android-er

Next:
Android BluetoothChat connect to Arduino Uno + HC-05

Wednesday, April 6, 2016

AT Command mode of HC-05

HC-05 Bluetooth Module support both Master and Slave roles. We can set it in AT Command mode. There are a number of variant of HC-05, and different ways to enter AT Command mode. For my samples, there is a button on the lower-right, above EN pin. It's used to enter AT Command mode when power-on.



This video show how to connect PC to HC-05, via FTDI USB-to-Serial adapter, power-on HC-05 in AT Command mode, and enter AT Command using Arduino Serial Monitor to check setting of HC-05.


Please notice both FTDI USB-to-Serial adapter and HC-05 have to work on the same voltage, both 3.3V or both 5V.

- Connect FTDI and HC-05
FTDI Tx - HC-05 Rx
FTDI Rx - HC-05 Tx
FTDI GND - HC-05 GND
(no power apply to HC-05 now)

- Connect FTDI to PC using USB cable.
- You can check the COM port connect to FTDI in Deviec Manager.
- Start Arduino IDE, and run Tools > Serial Monitor.
- Set baud rate 38400 and select "both NL & CR".

- Press the on-board button of HC-05.
- Apply power to HC-05.
- The on-board LED of HC-05 will blink slowly.
- Now it's in AT Command mode.

- You can type AT command in Arduino Serial Monitor to check or set the setting of HC-05.

Some useful command:
AT : return OK if connect correctly.
AT+NAME : get/set name of the device. Nothing return in my sample.
AT+ADDR : display default address
AT+VERSION : display firmware version
AT+UART : get/set serial communication setting; such as baud, number of stop bit, and parity.
AT+ROLE: get/see role of bt module(1=master/0=slave)
AT+RESET : Reset and exit AT mode
AT+ORGL : Restore factory settings
AT+PSWD: get/set default PIN

reference:
iteadstudio: Serial Port Bluetooth Module (Master/Slave) : HC-05
- HC-03/05 Embedded Bluetooth Serial Communication Module
AT command set



Tuesday, April 5, 2016

First test HC-05 Bluetooth Module


This video show my first test of HC-05 Bluetooth Module. Connect a FTDI USB-to-Serial adapter to HC-05. And try communication between Arduino Serial Monitor > FTDI > HC-05 and PC (running Windows 10) Bluetooth (PuTTY).


By default, HC-05 work as slave, and have name and pin of "HC-05" and "1234".

Connection between FTDI and HC-05
FTDI Tx - HC-05 Rx
FTDI Rx - HC-05 Tx
FTDI GND - HC-05 GND
HC-05 VCC - separated 3.3V


Next:
AT Command mode of HC-05
Android BluetoothChat example link with HC-05 Bluetooth
Android BluetoothChat connect to Arduino Uno + HC-05
Config HC-05(s) as paired Master and Slave

Monday, December 8, 2014

HC-05 Serial Port Bluetooth Module (Master/Slave)

HC-05 module is an easy to use Bluetooth SPP (Serial Port Protocol) module, designed for transparent wireless serial connection setup.


Serial port Bluetooth module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps Modulation with complete 2.4GHz radio transceiver and baseband. It uses CSR Bluecore 04-External single chip Bluetooth system with CMOS technology and with AFH(Adaptive Frequency Hopping Feature). It has the footprint as small as 12.7mmx27mm. Hope it will simplify your overall design/development cycle.