الأربعاء، 1 يوليو 2015

Test HC-06 Bluetooth Module with Android BluetoothChat

HC-06 is a low cost bluetooth module (slave mode only). This post show how to test it using the Android code sample of BluetoothChat.


Connection on HC-06 Bluetooth module:
VCC - connect to 3.3V
GND - connect to GND
RXD connect to TXD, to make it in loop-back mode.

In Android side, we will use the Android code sample of BluetoothChat. To make it work with HC-06, we have to modify the UUID. Refer to Android document 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. Open file file com.example.android.bluetoothchat.BluetoothChatService.java in Android Studio, replace the code:
    private static final UUID MY_UUID_SECURE =
UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66");

to:
    private static final UUID MY_UUID_SECURE =
UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");



Then re-build, install and test it.

Test HC-06 Bluetooth Module with Android BluetoothChat
- Power on HC-06 (*caution 3.3V), the HC-06 LED will blink, to show it is not connected.
- Turn on Bluetooth on Android, pair with HC-06 with default password "1234". After paired, the LED on HC-06 still blink.
- Run the BluetoothChat example on Android, connect to HC-06. After connected, the LED stop blinking.
- Now you can enter text to test the bluetooth connection.
- Anything HC-06 received will echo back to Android. But in my test, sometimes the first character will be incorrect.


Next:
- Android example to communicate with Bluetooth device, HC-06 Bluetooth Module

ليست هناك تعليقات:

إرسال تعليق