Bluetooth Shield

From Wiki

Jump to: navigation, search

Contents

Introduction

Bluetooth Shield a serial port Bluetooth module (Master/Slave) breakout board. You can choose ARDUINO's Digital PIN D0->D7 as Software UART to communicate with Bluetooth Shield(and D0,D1 also is Hardware UART).

There is a HC-05 on the board and it's an easy to use Bluetooth SPP module designed for transparent wireless serial connection setup.

It can be configured to Master, Slave or Loopback three different modes, and it will connect to or be connected by other devices that support SPP protocol per configuration, and it is a suitable substitute for most applications.

Model:SHD18


BT Shield 03.jpg

Feature

Application Ideas

Cautions

  • Only between master device and slave device can be paired with each other. Between Master and Master devices or Slave and Slave devices can't be paired each other. The Slave mode could be paired with PDA, PC etc.
  • Make sure your main board IO is 3.3V

Schematic

Note: The switch is not for 3.3V/5V power supply, but be used with jumper cap for HC-05 to enter AT mode. Three kinds of match:

Case 1: The cap jump to 'SW'(switch) and switch at 'H' side that means input high level to the Bluetooth HC-05's PIN34. Then the module will enter to AT mode.

Case 2: The cap jump to 'SW'(switch) and switch at 'L' side that means quit AT mode.

Case 3: The cap jump to 'I/O' and whatever switch side, that means you can control the level of PIN34 by Arduino's D6 pin and control when enter AT mode.

BT Shield 06.jpg


BT Shield 11.jpg

Usage

How could I sent the command to Blueooth Shield module ?

First, you need enter AT mode in accordance with the above method. Then, there are three ways use Serial port send command to Bluetooth Shield. Detail option please reference my post Communication between Android and Arduino with Bluetooth(2).

BT Shield 08.jpg

BT Shield 09.jpg

BT Shield 10.jpg


Programming

Usually we used software Serialport library to control and communication with Bluetooth Module. The Preparation steps:

Step One: Hardware connect

Use the Case 3 connection. And we jumper cap to SW side and set switch to H side. Then use Software Serial library to define D2 and D3(Of course others) as a virtual serial port TX and RX. By this way, you can use Arduino’s Serial Monitor to Monitor operation of the code.


Step two: Software control

First of all, you need a software library. There we used NewSoftSerial library. Get it from here

Put the library to : ...\your_ArduinoIDE_Path\arduino-0022\libraries

Copy below demo code and run. This just a sample code for your reference and you can modified and change it whatever you want.


Step Three: AT command

Now, You can send AT commanD from Serial port to control and setting the Bluetooth module. And you can set the module to Master or Slave......

You can play with Master mode to send paired require to others Bluetooth devices or Slave mode to wait others Bluetooth devices discover.

The AT command please reference Bluetooth Bee AT Command(HC-05).


Includes important code snippet. Demo code like :

BT Shield 04.jpg

/*********************************************************************
 **  Description:                                                    **
 **  This file is a sample code for your reference.                  **
 **                                                                  **
 **  Copyright (C) 2011 ElecFreaks Corp.                             **
 **  Created by ElecFreaks Robi.W /29 Sep 2011                      **
 **                                                                  **
 **  http://www.elecfreaks.com                                       **
 *********************************************************************/
#include <NewSoftSerial.h>
#include <TimerOne.h>

#define rxPin 2
#define txPin 3

NewSoftSerial mySerial(rxPin, txPin);
 
void Callback()
{
   Serial.println("------->  Callback Send AT");
   mySerial.print("AT\r\n");
}
 
void setup()
{
   // define pin modes for tx, rx pins:
   pinMode(rxPin, INPUT);
   pinMode(txPin, OUTPUT);
   mySerial.begin(38400);
   Serial.begin(38400);
 
   //Timer1.initialize(2000000);             // setting callback is 2s
   //Timer1.attachInterrupt(Callback); 
}
 
void loop()
{
  int i = 0;
  char someChar[32] = {0};
  // when characters arrive over the serial port...
  if(Serial.available()) {
    do{
      someChar[i++] = Serial.read();
      //As data trickles in from your serial port you are grabbing as much as you can, 
      //but then when it runs out (as it will after a few bytes because the processor 
      //is much faster than a 9600 baud device) you exit loop, which then restarts, 
      //and resets i to zero, and someChar to an empty array.So please be sure to keep this delay 
      delay(3);                  
 
    }while (Serial.available() > 0);
 
    mySerial.println(someChar);
    Serial.println(someChar);
  }
 
  while(mySerial.available()) 
      Serial.print((char)mySerial.read());    
}

BT Shield 07.jpg




If you used Arduino Mage1280/250 or Freaduino ADK there are some different.Please note the NewSoftSerial library about Mage2560 explanation in SoftwareSerial.cpp :


// Specifically for the Arduino Mega 2560 (or 1280 on the original Arduino Mega)
// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
// Only pins available for RECEIVE (TRANSMIT can be on any pin):
// (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me)
// Pins: 10, 11, 12, 13,  50, 51, 52, 53,  62, 63, 64, 65, 66, 67, 68, 69

That's mean the library do not support D0-D7 as receive pins, just could use pins:10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 for receive. So there are two way to resolve it, but all need external jumper wires.

First method: Change the define of rxPin and txPin. Jumper wires connect DOUT-D10, DIN-D11.

#define rxPin 10
#define txPin 11

Second method: Use the others Hardware Serialport because of Mage there are 4 hardware serialport. Jumper wires connect DOUT-RX1(D19) DIN-TX1(D18)

The below demo is second method:

BT Shield 05.jpg

/*********************************************************************
 **  Description:                                                    **
 **  This file is a sample code for your reference.                  **
 **                                                                  **
 **  Copyright (C) 2011 ElecFreaks Corp.                             **
 **  Created by ElecFreaks Robi.W /29 Sep 2011                      **
 **                                                                  **
 **  http://www.elecfreaks.com                                       **
 *********************************************************************/
void setup()
{
   Serial.begin(57600);
   Serial1.begin(38400);
 
}
 
void loop()
{
  int i = 0;
  char someChar[32] = {0};
  // when characters arrive over the serial port...
  if(Serial.available()) {
    Serial.print("------->  ");
    do{
      someChar[i++] = Serial.read();
      //As data trickles in from your serial port you are grabbing as much as you can, 
      //but then when it runs out (as it will after a few bytes because the processor 
      //is much faster than a 9600 baud device) you exit loop, which then restarts, 
      //and resets i to zero, and someChar to an empty array.So please be sure to keep this delay 
      delay(3);
    }while (Serial.available() > 0);
    Serial1.println(someChar);
    Serial.println(someChar);
  }
 
  while(Serial1.available())
      Serial.print((char)Serial1.read()); 
}

BT Shield 12.jpg

Bill of Materials (BOM) /parts list

All the components used to produce the product.

Version Tracker

Revision Descriptions Release
v1.0b Initial public release date

FAQ

when I selected 'HC-05' in pair list after search Bluetooth devices on APK, but not display pairing dialog and then APK quit 'AS Client' menu to Main menu.

So I check the Java APK and found the reason is paired failed. After then I reset pair list, I can pair successful and communication again.

The step is:

Then power down the Bluetooth Shield more then 2 minutes, beause of mostly of Android phone the default paire time is 2 minutes.

After more then 2 minutes, you can pair with Bluetooth Shield again, and this time there will show pairing dialog, input '1234' . Once you

paired successful, the led2 will light which near SWITCH.

AT-BTShield.jpg

Resources

How to buy

Click here to buy: http://www.elecfreaks.com/estore/bluetooth-shield-shd18.html

See Also

Other related products and resources.

Licensing

This documentation is licensed under the Creative Commons Attribution-ShareAlike License 3.0 Source code and libraries are

licensed under GPL/LGPL, see source code files for details.

External Links

Links to external webpages which provide more application ideas, documents/datasheet or software libraries

Personal tools
Namespaces
Variants
Actions
Navigation
Support
Toolbox