blue bee with xbee shield connected to arduino problem

Bluetooth, XBee, RF......

blue bee with xbee shield connected to arduino problem

Postby eugen25 » Tue Jun 03, 2014 3:34 pm

hi, i try to test a sample code from http://www.instructables.com/id/Modify- ... mand-Mode/

I have modified it to use it for bluebee. The purpose of project is to get the mac address and rssi signal of other device. However, when i enter command 'AT', there is no output in the series monitor. The picture of the hardware and output of series monitor and the sample code are attached.

CODE: SELECT_ALL_CODE
#include <SoftwareSerial.h>

SoftwareSerial BTSerial(2, 3); // RX | TX

void setup()
{
  Serial.begin(38400);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);  // bluebee default speed in AT command more
}

void loop()
{

  // Keep reading from xbww and send to Arduino Serial Monitor
  if (BTSerial.available())
    Serial.write(BTSerial.read());

  // Keep reading from Arduino Serial Monitor and send to xbee
  if (Serial.available())
    BTSerial.write(Serial.read());
}
Attachments
Output of series monitor.JPG
hardware.jpg
eugen25
Fledgling
 
Posts: 1
Joined: Tue Jun 03, 2014 2:34 pm

Re: blue bee with xbee shield connected to arduino problem

Postby ober » Tue Jun 03, 2014 5:16 pm

Any modification made on the Xbee Shield? As far as I understand Xbee shield provide UART communication on pin 0 and pin 1 of Arduino with Xbee/BlueBee, but your code wanted to communicate with BlueBee using pin 2 and pin 3 using BTSerial function.

But the hardware is not connected. Without correct hardware, communication cannot happen even with correct code. You need to hack the XBee Shield for that.

Or get yourself the latest Xbee Shield from Cytron.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: blue bee with xbee shield connected to arduino problem

Postby ckb » Thu Jun 05, 2014 4:38 am

How about this xbee shield http://www.cytron.com.my/viewProduct.php?pcode=SHIELD-XBEE3 ? This was the xbee shield that use in this project. Is it not compatible to bluebee or arduino uno?

If we set the Rx and Tx to pin 0 and pin 1 of arduino uno, the series monitor will give output as shown in the picture below when the xbee shield was set to run-xbee mode.

CODE: SELECT_ALL_CODE
#include <SoftwareSerial.h>

SoftwareSerial BTSerial(0, 1); // RX | TX

void setup()
{
  Serial.begin(38400);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);  // bluebee default speed in AT command more
}

void loop()
{

  // Keep reading from xbww and send to Arduino Serial Monitor
  if (BTSerial.available())
    Serial.write(BTSerial.read());

  // Keep reading from Arduino Serial Monitor and send to xbee
  if (Serial.available())
    BTSerial.write(Serial.read());
}
Attachments
Output of series monitor.JPG
ckb
Greenhorn
 
Posts: 2
Joined: Thu Jun 05, 2014 4:13 am

Re: blue bee with xbee shield connected to arduino problem

Postby ober » Thu Jun 05, 2014 8:57 am

There are a few things you need to be clear :)

1. Study the tutorial that you shared and wanted to do. It does not uses Xbee shield to connect the Arduino main board to the Bluetooth module, so it can choose which ever pins to communicate with Bluetooth module via Software Serial. It the tutorial case, it uses pin 10 and 11 (original), but the code you share uses pin 2 and 3 instead.
2. Why he uses pin 10 and 11? Because pin 0 and 1 is the hardware UART which are always connected to USB to UART chip on the Arduino main board. And he need the hardware UART to send to computer to show the result on serial monitor, that is the easiest way to show result.
3. The XBee ShieldXBee shield is compatible with Xbee/BlueBee and Arduino main board, but it is not designed for your project. It is designed for BlueBee/XBee to communicate with Arduino main board only. However, in your case, Arduino main board need to communicate with laptop (via the USB to UART) and also BlueBee in the same time with the same setup. Hope you understand this.

In simple words: Xbee Shield (the one you have) provides:
Arduino UNO ----pin 0 and 1 ---- XBee Shield -------- Xbee/BlueBee - This allow Arduino to communicate with XBee/BlueBee only, it cannot offers communication with computer and BlueBee at the same time.

The tutorial that you intended to do:
Laptop ------ USB ------ USB to UART on Arduino ----- pin 0 and 1 ------ Arduino ------- pin 2 and 3 ---- Xbee shield --- BlueBee - This setup allows communication with computer and BlueBee at the same time.

But as I said earlier, the communication pins on XBee Shield (the one you have) is pin 0 and 1. In the latest code you shared, Serial and BTserial is using same pins. What ever you send to Serial.print is send to computer and BlueBee, same as what ever you send using BTserial.write, it is send to both computer and BlueBee. That is the reason you get the response of "Error", because BlueBee does not recognize "Enter AT commands" and later "Error", and it keep return "Error" because it keep receiving "Error".

That is the reason why we design improved version of XBee shield where you can choose the pins you wanted to use for Xbee/BlueBee communication.

My advise, get familiar with UART communication first. Study the nature or this communication, play with it :)
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: blue bee with xbee shield connected to arduino problem

Postby ckb » Sun Jul 13, 2014 10:22 pm

Hi, after change the xbee shield, i was able to get the bluetooth mac address and rssi signal of the surrounding bluetooth device. However, i still face some problems when trying to get the device name. I have written some code to get the bluetooth device name, mac address and rssi signal as shown below. The problem that i faced is: The program will stop halfway after i run the program for certain times by entering the input 'D' . It means that the bluebee give no response and there is no ouput anymore in the series monitor although the program was just run halfway. The problem will only occurred when i try to get the device name.

CODE: SELECT_ALL_CODE
#include <SoftwareSerial.h>

#define btRxPin 2
#define btTxPin 3

//#define maxColumns 10
//#define loopDelay 10000 // in millis

SoftwareSerial bluetoothSerial(btRxPin, btTxPin);

void setup() {
  Serial.begin(9600);
 
  // connect to bluetooth, and do initial setup
  bluetoothSerial.begin(38400);
  sendBluetoothCommand("AT");
  sendBluetoothCommand("AT+INIT");
  sendBluetoothCommand("AT+RMAAD");
  sendBluetoothCommand("AT+ORGL");
  sendBluetoothCommand("AT+ROLE=1");
  sendBluetoothCommand("AT+NAME=BluetoothAttendanceSystem");
  sendBluetoothCommand("AT+CLASS=0");
  sendBluetoothCommand("AT+INQM=1,25,10");
}

// read until OK or ERROR:, or if multilined, return | delimited
String sendBluetoothCommand(String command)
{
  bluetoothSerial.println(command);
 
  String response = ""; 
 
  if (bluetoothSerial.overflow())
  {
    Serial.println("SoftwareSerial overflow!");
  }
 
  // doing it this way to avoid softwareserial overflow   
  while (1)
  {
    String line = "";
   
    do {
      if (bluetoothSerial.available())
      {
        char c = bluetoothSerial.read();
        Serial.print(c);
        line += c;
      }
    } while (!line.endsWith("\r\n"));
    line.trim();
     
    if ((line == "OK") || line.startsWith("ERROR:") || (line == "FAIL"))  {
      Serial.println(command + " -> " + line );
      break;
    }
     
    response += line + " ";
  }
   
  return response;
}

unsigned int hexToDec(char hex) {
  unsigned int val; 
 
  if (hex >= '0' && hex <= '9') {
      val = hex - '0';
  }
  else {
    val = 10 + hex - 'A';
  }
   
  return val;
}

// assume 0xFF__
int twosComplement(String hex) {
  unsigned int val = 0;
  val = ~((~val << 8) | (hexToDec(hex[2]) << 4) | (hexToDec(hex[3])));

  int total = -val - 1;
  return total; 
}

char getChar()
{
  while(Serial.available() == 0);
  return((char)Serial.read());
}

void loop()
{
  if (Serial.available())
  {
    int inChar = getChar();
    if (inChar == 'D')
    {
      Serial.println("Starting...");;
      String response = sendBluetoothCommand("AT+INQ");
 
      String check,check2;
      String devices[15],device;
      String names[15],name;
      String rssiStr;
      int rssis[15];
      int pings[15];
      int j = 0, i = 0;
   
      int start = 1;
      int ends = response.length();
      //Serial.println(ends);
     
      int ClosingColon = 1;
      int ClosingComma = 1;
     
      while(ends > ClosingComma + 10)
      {
        ClosingColon = response.indexOf(':', ClosingComma);
        ClosingComma = response.indexOf(',', ClosingColon);
        String device = response.substring(ClosingColon+1, ClosingComma);
        ClosingComma = ClosingComma + 1;
        ClosingComma = response.indexOf(',', ClosingComma);
        String rssiStr = response.substring(ClosingComma+1, ClosingComma+5);

        boolean containsDevice = false;
        for (int j = 0; j <= i; j++)
        {
          if (device.equals(devices[j]))
          {
            containsDevice = true;
            pings[j] = pings[j] + 1;
            break;
          }
        }
   
        if (!containsDevice)
        {
          pings[i] = 1;
          rssis[i] = twosComplement(rssiStr);
          devices[i] = device;     
          i++;
        }
      }
     
      int columnRssi[10];
      for (int j = 0; j < 10; j++)
      {
        columnRssi[j] = -255;
      }
     
      //response=sendBluetoothCommand("AT+RMAAD");
      //Serial.println(response);
     
      for (int j = 0; j < i; j++)
      {
        //sendBluetoothCommand("AT+RESET");
        //String name = names[j];
        String device = devices[j];
        int rssi = rssis[j];

       
        Serial.print(", device = ");
        Serial.print(device);
        Serial.print(", rssi = ");   
        Serial.print(rssi);
        Serial.print(", ping = ");
        Serial.println(pings[j] );
       
        device.replace(":",",");
        //response = sendBluetoothCommand("AT+RNAME? " + device);
       
        bluetoothSerial.println("AT+RNAME? " + device);  //get device name
        String line = "";
       
        do //print device name
        {
          if (bluetoothSerial.available())
          {
            char c = bluetoothSerial.read();
            Serial.print(c);
            line += c;
          }
          //delay(100);
        } while (!line.endsWith("\r\n"));
        line.trim();
       
        do //print 'ok' for RNAME
        {
          if (bluetoothSerial.available())
          {
            char c = bluetoothSerial.read();
            Serial.print(c);
            line += c;
          }
          //delay(100);
        } while (!line.endsWith("\r\n"));
        line.trim();
       
        delay(100);
//        if ((line == "OK") || line.startsWith("ERROR:") || (line == "FAIL"))  {
//           Serial.println("AT+RNAME? " + device + " -> " + line );
//           break;
//        }
       
       
        //response = response.substring(7);
        //names[j] = response;
        //Serial.print("Name = ");
        //Serial.print(names[j]);
      }
      //Serial.println("Sleeping for 10 seconds...");
      //delay(loopDelay);
    }
  }
}




 
Attachments
Series monitor output.JPG
ckb
Greenhorn
 
Posts: 2
Joined: Thu Jun 05, 2014 4:13 am


Return to Wireless Device

Who is online

Users browsing this forum: No registered users and 12 guests

cron