Pages: [1] 2   Go Down
Author Topic: Bluetooth and Xbee working together  (Read 2417 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey

Im doing a school project where i have an arduino mega, with a bees shield (http://www.seeedstudio.com/wiki/Bees_Shield). On this shield i have the bluetooth bee (http://www.seeedstudio.com/wiki/Bluetooth_Bee) and a XBee 2.5. They are plugged directly onto the bees shield, with no other wiring.

I have gotten the xbee to work on 9600 baud rate, and the bluetooth to work on a 38400 baud rate, but thats seperatly. How do get them to work, so that i can connect to the bluetooth with my phone, and then have the xbee send commands?

I have written some code, where i tried, but can you help me out to see what the problem might be? When i use this code none of them work, i cant see it on bluetooth, and the xbee won't receive commands.

Code:
//long DATARATE = 38400;
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte1;      // a variable to read incoming serial data into
int incomingByte2;

void setup()
{
  Serial1.begin(9600);
  Serial2.begin(38400);
 
  pinMode(ledPin, OUTPUT);
 
  //------BLUETOOTH SETUP-------
  Serial2.print("\r\n+STWMOD=0\r\n");     // set to slave
  delay(1000);
  Serial2.print("\r\n+STNA=HomeAutoDroid\r\n");     // DSC = digital setting circles
  delay(1000);
  Serial2.print("\r\n+STAUTO=0\r\n");     // don't permit auto-connect
  delay(1000);
  Serial2.print("\r\n+STOAUT=1\r\n");     // existing default
  delay(1000);
  Serial2.print("\r\n +STPIN=0000\r\n");  // existing default
  delay(2000);  // required

  // initiate BTBee connection
  Serial2.print("\r\n+INQ=1\r\n");
  delay(2000);   // wait for pairing
  //----------------------------
}

void loop()
{
  if (Serial2.available() > 0) {
    incomingByte2 = Serial.read();
   
    if (incomingByte2 == 'X') {
      Serial.println("-----------Menu------------");
      Serial.println(" T - TEST    ");
      Serial.println(" T - TEST   ");
      Serial.println(" H - TEST        ");
      Serial.println(" D - TEST        ");
      Serial.println("---------------------------");
    }
    if (incomingByte2 == 'H') {
      digitalWrite(ledPin, HIGH);
      Serial.println("LED ON");
    }
    if (incomingByte2 == 'L') {
      digitalWrite(ledPin, LOW);
      Serial.println("LED OFF");
    }
   
  }
 
  if (Serial1.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte1 = Serial.read();
   
   
    if (incomingByte1 == 'X') {
      Serial.println("-----------Menu------------");
      Serial.println(" T - TEST    ");
      Serial.println(" T - TEST   ");
      Serial.println(" H - TEST        ");
      Serial.println(" D - TEST        ");
      Serial.println("---------------------------");
    }
    if (incomingByte1 == 'H') {
      digitalWrite(ledPin, HIGH);
      Serial.println("LED ON");
    }
    if (incomingByte1 == 'L') {
      digitalWrite(ledPin, LOW);
      Serial.println("LED OFF");
    }

  }
 
   
  }
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50924
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First, what is the XBee talking to?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First, what is the XBee talking to?

Well i have the Arduino Mega with the bluetooth bee and the xbee.
And then i have a 2nd Arduino with an xbee shield on it and an xbee of course.

So it goes like this: Phone (Bluetooth) -> Arduino Mega (Bluetooth) -> same Arduino Mega (XBee) -> Arduino Uno (XBee).
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50924
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are the jumpers on that board set correctly so that the bluetooth device IS connected to Serial2? Are the jumpers on that board set correctly so that the XBee is connected to Serial1? That board is not designed for a Mega, so you must be running wires to the Serial1 and Serial2 pins.

What serial output are you seeing?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are the jumpers on that board set correctly so that the bluetooth device IS connected to Serial2? Are the jumpers on that board set correctly so that the XBee is connected to Serial1? That board is not designed for a Mega, so you must be running wires to the Serial1 and Serial2 pins.

What serial output are you seeing?

i tried to run 2 wires from the 2 holes where it says "Bee 2 RX and TX", i ran them to the TX1 and RX2.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just took a picture of the arduino mega with the bees shield, bluetooth bee and xbee.

Black wire goes to TX, and red wire goes to RX

http://boinq.net/amega.jpg
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50924
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I just took a picture of the arduino mega with the bees shield, bluetooth bee and xbee.
I can't see that picture while at work. When I get home, I'll look at it.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I just took a picture of the arduino mega with the bees shield, bluetooth bee and xbee.
I can't see that picture while at work. When I get home, I'll look at it.

sounds good, i appreciate it smiley
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50924
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't see through the board. I can't see where the other ends of the black and red wires go. There should be 4 of them, since the blue tooth and the XBee are bidirectional devices.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't see through the board. I can't see where the other ends of the black and red wires go. There should be 4 of them, since the blue tooth and the XBee are bidirectional devices.

The wires are coming from the 2 solderings just above the atmega/usb switch on the shield, from the RX and TX for bee2

The jumpers are for bee1 are in port 11 and 12.
« Last Edit: April 13, 2012, 02:13:59 am by BoinQ » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50924
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The wires are coming from the 2 solderings just above the atmega/usb switch on the shield, from the RX and TX for bee2
I can't see the picture again. There need to be 4 wires - two for the bluetooth device and two for the XBee. The 2 from the blue tooth device go to TXn/RXn, and the two from the XBee go to TXm/RXm. Use Serialn to talk to the bluetooth, and Serialm to talk to the XBee.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The wires are coming from the 2 solderings just above the atmega/usb switch on the shield, from the RX and TX for bee2
I can't see the picture again. There need to be 4 wires - two for the bluetooth device and two for the XBee. The 2 from the blue tooth device go to TXn/RXn, and the two from the XBee go to TXm/RXm. Use Serialn to talk to the bluetooth, and Serialm to talk to the XBee.

Serialm and serialn? like the serial1 and serial2 in my code?
Can you tell me what is needed in the code to have multiple serial in- and outputs? should i define tx1, rx1, tx2 and rx2 to the ports they are in?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50924
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Serialm and serialn? like the serial1 and serial2 in my code?
Yes.

Quote
Can you tell me what is needed in the code to have multiple serial in- and outputs? should i define tx1, rx1, tx2 and rx2 to the ports they are in?
Yes, no, and maybe. As of the last picture you posted, you don't have the hardware connected properly, so no amount of software diddling is going to work.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Serialm and serialn? like the serial1 and serial2 in my code?
Yes.

Quote
Can you tell me what is needed in the code to have multiple serial in- and outputs? should i define tx1, rx1, tx2 and rx2 to the ports they are in?
Yes, no, and maybe. As of the last picture you posted, you don't have the hardware connected properly, so no amount of software diddling is going to work.

Now that the bluetooth bee is wired to rx2 and tx2. I need to write the code, so that it can read bluetooth bee on 38400 baudrate and the xbee on baudrate 9600.

I need to send these codes through the serial on baudrate 38400
Code:
//------BLUETOOTH SETUP-------
  Serial2.print("\r\n+STWMOD=0\r\n");     // set to slave
  delay(1000);
  Serial2.print("\r\n+STNA=HomeAutoDroid\r\n");     // DSC = digital setting circles
  delay(1000);
  Serial2.print("\r\n+STAUTO=0\r\n");     // don't permit auto-connect
  delay(1000);
  Serial2.print("\r\n+STOAUT=1\r\n");     // existing default
  delay(1000);
  Serial2.print("\r\n +STPIN=0000\r\n");  // existing default
  delay(2000);  // required

  // initiate BTBee connection
  Serial2.print("\r\n+INQ=1\r\n");
  delay(2000);   // wait for pairing
  //----------------------------
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i made some code where i can get it to connect to my bluetooth bee, but it wont read my commands:
Code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(51, 50); // RX, TX

char inChar = 0;
int  LED = 13;

void setup() 
{
  Serial.begin(9600);
  Serial.println("Goodnight moon!");

//------BLUETOOTH SETUP-------
  Serial.print("\r\n+STWMOD=0\r\n");     // set to slave
  delay(1000);
  Serial.print("\r\n+STNA=HomeAutoDroid\r\n");     // DSC = digital setting circles
  delay(1000);
  Serial.print("\r\n+STAUTO=0\r\n");     // don't permit auto-connect
  delay(1000);
  Serial.print("\r\n+STOAUT=1\r\n");     // existing default
  delay(1000);
  Serial.print("\r\n +STPIN=0000\r\n");  // existing default
  delay(2000);  // required

  // initiate BTBee connection
  Serial.print("\r\n+INQ=1\r\n");
  delay(2000);   // wait for pairing
  //----------------------------

  // set the data rate fovr the SoftwareSerial port
  mySerial.begin(38400);
 
  pinMode(LED, OUTPUT);
}

void loop() // run over and over
{
  if (mySerial.available()) {
    mySerial.write(Serial.read());
    inChar = mySerial.read();

    if (inChar == 'a') {
      Serial.print("connected");  // test return connection
    }
   
    if (inChar == 'h') {
      digitalWrite(LED, HIGH);   // on
    }

    if (inChar == 'l') {
      digitalWrite(LED, LOW);    // off
    }
   
  }
  if (Serial.available()) {
   
  }
}
Logged

Pages: [1] 2   Go Up
Jump to: