Pages: [1]   Go Down
Author Topic: sending data between 2 arduinos using xbee  (Read 892 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am having the following:

2 arduinos and 2 xbees. I want to send data from the one to another. The xbees communicate because I have the proposes test (connect one xbee with the arduino and the other to the PC, write from the one, watch the other in the other terminal).

Now I want to send data from the one to another:

These are my 2 scripts:

for sending: 9which is tested in the former test that sends all the letters)
Code:
    #include <SoftwareSerial.h>
   
    SoftwareSerial xbee(2, 3); // RX, TX
    char c = 'A';
    int  pingPong = 1;
   
    void setup()
    {
     Serial.begin(9600);
     
     Serial.println( "Arduino started sending bytes via XBee" );
     
       // set the data rate for the SoftwareSerial port
       xbee.begin(9600);
    }
   
    void loop()  {
      // send character via XBee to other XBee connected to Mac
      // via USB cable
      xbee.write( c );
     
      //--- display the character just sent on console ---
      Serial.println( c );
     
      //--- get the next letter in the alphabet, and reset to ---
      //--- 'A' once we have reached 'Z'.
      c = c + 1;
      if ( c>'Z' )
           c = 'A';
     
      //--- switch LED on Arduino board every character sent---
      if ( pingPong == 0 )
        digitalWrite(13, LOW);
      else
        digitalWrite(13, HIGH);
      pingPong = 1 - pingPong;
      delay( 1000 );
    }
Problem is when connected an arduino to receive data from the other XBee.

Here is my code:

 
Code:
  #include <SoftwareSerial.h>
   
    SoftwareSerial xbee(2, 3); // RX, TX
   
   
    void setup()
    {
     Serial.begin(9600);
     
     Serial.println( "Arduino started receiving bytes via XBee" );
     
       // set the data rate for the SoftwareSerial port
       xbee.begin(9600);
    }
   
    void loop()  {
     int temp=xbee.read();
   
     Serial.print("Character received:");
     Serial.println(temp);
     delay(1000);
    }
Output is always:

   
Code:
Character received: -1.

If I change the temp from int to byte I see
Code:
Character received: (a non-ascii symbol)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
2 arduinos and 2 xbees.
What kind of XBees? How are they configured?

Quote
connect one xbee with the arduino
With duct tape? HOW?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

XBee series 1.

they are configured through X-CTU, based on the one tutorial found on ladyada.net.

Then I connected XBee to arduino (TX to pin 3, RX to 2, vcc and gnd respectively) and the other XBee to pc through FTDI cable.
I was able to send characters from the arduino and see them in the serial monitof of the X-CTU. Does this mean that they are configured correclty?

Then I wanted to connect an arduino to my receiver. You can see the code above. I am always getting no available data.

Returned -1 means that there is no data in the serial.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Returned -1 means that there is no data in the serial.
What is supposed to be sending serial data to the Arduino?

If one XBee is on the Arduino, and the other is on the USB Explorer connected to the PC, what, on the PC is sending data?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Both XBees are connected to different arduino.

the one does xbee.write() where xbee is a new software serial

and the other one does xbee.read().

XBees are correclty configured since I tested it (I think I done it correctly).

I am missing something, though.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
they are configured through X-CTU, based on the one tutorial found on ladyada.net.
Configured how? What did you set/change?

You should have set PAN ID, MY, and DL. What values does each one have?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If they are working with FTDI, doesn't that mean that they are working correclty?

I have seet PAN ID of both to 2001.
also set ATDH to be the common high bits of xbee.

And ATDL is the bottom bits of the destination. Since A wants to send to B, ATDL of A has the bottom bits of B and vice versa.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If they are working with FTDI, doesn't that mean that they are working correclty?
Usually. But I have no problems communicating when I set PAN ID, MY, and DL.

Post screen shots of X-CTU showing how you have configured both XBees.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you help me on what is MY? DL is the destination Low bits right?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
DL is the destination Low bits right?
Yes.

Quote
Can you help me on what is MY?
Have you even fired up X-CTU?
Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 16
Posts: 906
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I took a quick look at the receiving XBee code and it appears that you read a character in a loop without checking to see if there is a character there to read.  You need to put a

if (xbee.available){
     whatevervariable = xbee.read;

in there.  See, there are no characters available so read returns a -1 and you get the error you're seeing.

Or, did I miss something obvious?
Logged

Trying to keep my house under control http://www.desert-home.com/

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
DL is the destination Low bits right?
Yes.

Quote
Can you help me on what is MY?
Have you even fired up X-CTU?

Yes I had. But so far I had configured DL,DH, and PAN ID. And I told you through FTDI it plays.

 So can you help me on that? What MY stands for?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What MY stands for?
It does not stand for anything. MY is the name (numeric value only) of the XBee. It is the value that the other XBee uses as DL.
Logged

Pages: [1]   Go Up
Jump to: