Go Down

Topic: Connecting Xbees with Arduinos (Read 539 times) previous topic - next topic

ujjwalrathod007

I have Arduino Uno and Arduino nano, Both connected to Xbees. I have few questions.

1) I want to send data from Nano to Uno Via Xbees. I have make Xbee of nano as End device. And I have configured the Xbee of Uno as Cordinator.

Do I have to add libraries for sending data between these 2 devices? Here is my code for End device.

Quote
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.write(0x03);
  Serial.write(0x03);
  Serial.write(0x03);

}

Here is my code for cordinator/.

Quote
int incoming=0;
void setup() {
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available() > 0) {
                // read the incoming byte:
                incoming = Serial.read();

       }
}
2) I connect both Arduinos to my PC. Could that make problems?
3) I have used following video for my connectionshttps://www.youtube.com/watch?v=cf3RLBg4t5s&t=124s

which tells to connect Rx to Rx and Tx to Tx of Arduino and Xbees respectively. Whereas I saw otherway around in some cases. But for me this works well as the XCTU only detects those connections shown in video.

PaulS

Quote
Do I have to add libraries for sending data between these 2 devices?
No.

Quote
Here is my code for End device.
That code is not giving the XBee time to send the data and get an acknowledgement.

Quote
2) I connect both Arduinos to my PC. Could that make problems?
No.

You seem to have forgotten to tell us what problem(s) you are having.
The art of getting good answers lies in asking good questions.

ujjwalrathod007

The problem is the code is not getting uploaded to the device sometimes!! It uploads only when I do not bypass the Arduino Bootloader by sorting the pins RST and GND. Also, I keep the X-CTU open. Which gives me error that COM 5 is already in use. So I have to close that.

I dont see the data on Receiver side!! I open Serial monitor but there is no data.
Quote
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);
  Serial.write(0x03);
  delay(1000);
  Serial.write(0x03);
  delay(1000);
  Serial.write(0x03);
  delay(1000);
}

ujjwalrathod007

Adding on to my previous comments.

I am receiving data now, It is a Garbage value. Also when I power of the sending Arduino+Bee the serial monitor of receiver is showing some data Why so?

Also, for Finding the Xbees on XCTU I need to connect the (RX-Xbee to RX-Arduino)!! and not Tx to Rx!! What should be the reason? When I do it other way round the Xbees dont show up!!

 

ujjwalrathod007

I get the following error also when I do upload.
 

Quote
Binary sketch size: 2,000 bytes (of a 30,720 byte maximum)
avrdude: stk500_getsync(): not in sync: resp=0x00
but it tells me "Done Uploading". What does it mean? It got uploaded or not uploaded Or with errors?

CrossRoads

"Done Uploading" in this case means the IDE is done with it's attempts to transfer the .hex file into your card.
The not in sync response means the file didn't transfer.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

ujjwalrathod007

thank you, BTW I found the problem is with hardware connection. When I disconnect the RX pin to Xbee it uploads well. What can I do to avoid this problem?

Power_Broker

Easy, stop using the hardware serial port for XBee comms and use softwareserial.h instead.
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

ujjwalrathod007

hum.. I changed a programs but nothing seems to work with Arduinos.. It works in XCTU.

Here are the programs..
Quote
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  while(1)
  {
  delay(1000);
  mySerial.write(0x03);
  delay(1000);
  Serial.print('D');
  delay(1000);
  mySerial.print('F');
  delay(1000);
}
}

ujjwalrathod007

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11);
int incoming;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while(!Serial);{
}
}

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>0)
{

incoming= Serial.read();
Serial.print("I got it");
mySerial.print("hello all");
incoming= mySerial.read();
}
}

MarkDerbyshire

You need to add

mySerial.begin(baudrate) to setup() or else the Software Serial will not initialize

ujjwalrathod007

Hum, you mean everything else in the program is OK?

ujjwalrathod007

It is still not working let me post my updated code...
Quote
Transmitter code

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
mySerial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  while(1)
  {
  delay(1000);
  mySerial.write(0x03);
  delay(1000);
  Serial.print('D');
  delay(1000);
  Serial.write(0x31);
  mySerial.print('F');
  delay(1000);
}
}


And the Receiver code

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

int incoming=0;
void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available() > 0) {
                // read the incoming byte:
                delay(1000);
                incoming = Serial.read();
                delay(1000);
                Serial.print(incoming);
                delay(1000);
                incoming= mySerial.read();
                delay(1000);
                mySerial.print(incoming);
                delay(1000);
               

       }
}

MarkDerbyshire

What are your Xbee's baud rate set to?

Power_Broker

Get rid of those delay() calls in the receiver code.
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Go Up