Go Down

Topic: [URGENT] Arduino BT and Seeedstudio Bluetooth Shield - Master/Slave Config (Read 3812 times) previous topic - next topic

seanli

Hi all,

I'm having issues pairing Arduino BT (http://arduino.cc/en/Main/ArduinoBoardBluetooth) as MASTER with an Seeedstudio Bluetooth Shield (http://www.seeedstudio.com/wiki/index.php?title=Bluetooth_Shield) as a SLAVE. I used below code for MASTER but pairing just doesn't happen...

Master's code (Arduino BT):
Code: [Select]

/* Arduino BT Configuration File  Feb 05 2007
* ------------------
* Upload and run this file <<once>> to configure the name or other variables of your BT module.
* Don't forget to reset your module so that the new commands are executed.
* ------------------
* Massimo Banzi
*/

int LED = 8;                                     // select the pin for the LED
int RESET = 7;                                    // BT module uses pin 7 for reset
int TEST = 13;
int connectOK = 0;
char recvChar;
String recvBuf;
boolean isloop=true;

void setup() {
  pinMode(LED,OUTPUT);                            // declare the LED and BT RESET pins as output
  pinMode(RESET,OUTPUT); 
  pinMode(TEST,OUTPUT);
  Serial.begin(115200);  // connect to the serial port
  setupBT();

  digitalWrite(RESET, HIGH); 
  delay(10);
  digitalWrite(RESET, LOW);
  delay(2000);
}
                                                 
void setupBT()
{                                                 
                                                 
                                                   // the following "SET BT" commands are one-time commands
                                                   // that only need to be uploaded to your BT module and run
                                                   // when you want to change the BlueGiga's configuration.

    Serial.println("SET BT NAME Arduino_BT");      // you can change the name of your module here.
                                                   // No spaces allowed in the name; names can be up to 256 charcters.


  //Serial.println("SET BT AUTH * 0000");         // 12345 == 0 to 16 digit Bluetooth passkey/PIN code

//  Serial.println("SET BT AUTH * 987654321");     // example

                                                   // And now the tricky configuration commands.
                                                   // Change these only if you know what you're doing.
                                                   // See the IWRAP manual for details.

  Serial.println("SET BT PAGEMODE 0 2000 2");      // 0 == Set device to master
                                                   // 2000 == 5120ms timeout
                                                   // 1 == iWRAP is connectable every 1.28 sec

  //Serial.println("SET BT PAIR 00:13:EF:12:0D:DD");
  delay(1000);

  Serial.println("SET BT ROLE 0 f 7d00");          // 0 == allows master-slave switch when calling;
 
  delay(1000);                                                 // f == enable sniff, park, hold and role switch modes;
                                                   // 7d00 == keep connection  alive 20 seconds
  //Serial.println("SET CONTROL AUTOCALL 1101");     // The device starts sending to find a paired device.
 

  Serial.println("SET CONTROL BAUD 115200,8n1");   // set the BT module serial rate to 115200. Don't change this.

  //Serial.println("SET CONTROL CD 80 0");
 
// Serial.println("SET BT SNIFF 2 2");              // This enables sniff power saving mode, but when used with minimum
                                                   // parameters it actually reduces the latency down to ~10ms.

  Serial.println("SET CONTROL ECHO 0");            // don't echo back module commands

  //Serial.println("SET CONTROL ESCAPE - 00 1");     // - == character to escape from comand mode to data mode;
                                                   // 00 == DTR bitmask; 1 == return to command mode when DTR dropped
  Serial.println("SET CONTROL ESCAPE 43 00 1"); 

 
 
  int connectOK = 0;
  int counter=0;
  //connecting the slave till they are connected
  do{
    Serial.println("SET BT PAIR 00:13:EF:12:0D:DD");//send connection command
    recvBuf = "";
    while(1){
     // if(Serial.available()){
        digitalWrite(LED,HIGH);
        recvChar = Serial.read();
recvBuf += recvChar;
if(recvBuf.indexOf("OK") != -1){
          connectOK = 1;
  digitalWrite(LED,LOW);
// blueToothSerial.print("Connected!");
  break;
}else if(recvBuf.indexOf("FAIL") != -1){
  //Serial.println("Connect again!");
          digitalWrite(LED,LOW);
  break;
}
         else{
          digitalWrite(LED,LOW);
          digitalWrite(TEST,HIGH);
          digitalWrite(TEST,LOW);
          break;
         }
     // }
    }
  }while(0 == connectOK);


                                                   // and now a few blinks of the  LED,
                                                   // so that we know the program is running.

void loop () {                                   
  digitalWrite(LED, HIGH);
  delay(100);
  digitalWrite(LED, LOW);
  delay(100);
}


I'm not gonna post Slave's code for now, since I'm pretty sure it's okay (it worked with other Seeedstudio BT devices before).
I know Arduino BT uses iWrap for programming and its syntax and whatnot are different from Seeedstudio's BT products. The iWrap commands I used in the above code should be fine according to other internet sources (btw I commented out the ones that I think are unnecessary).

It's really hard to debug since Arduino's only serial channel is occupied by BT and therefore I haven't figured out a way to monitor the serial communication yet. Anyways, this is part of my school project and the schedule is Really tight. I'm desperate to get it working, any help is appreciated!! THANK YOU!!


Nick Gammon


It's really hard to debug since Arduino's only serial channel is occupied by BT ...


Better get debugging happening:

http://www.gammon.com.au/forum/?id=11329
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

seanli



It's really hard to debug since Arduino's only serial channel is occupied by BT ...


Better get debugging happening:

http://www.gammon.com.au/forum/?id=11329



Thanks for the reply Nick! I'm just wondering will this program simply replay any serial communication happening on the master to the slave through I2C/SPI? I'm not sure what's the debugging example you listed for...

Nick Gammon

That's the idea. If you can't use serial prints for debugging you shove them out I2C/SPI and let the second Arduino echo them.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

kxheka

Try using 4 numbers (ex : 1234 ) as pairing code. I think that the shield can't handle bigger pairing codes.

Go Up