Go Down

Topic: XBee to XBee (Read 518 times) previous topic - next topic

rev_ollie

Hi all!

I'm beginning my journey with XBee's and Arduino and have been making simple strides but wanted a hand to make sure what I'm doing is right...

I have 2 XBee series 2 connected to 2 XBee Arduino Shield's connected to 2 Arduino Uno's (R3 I believe). These are both hooked up to my PC.
I have configured the XBee's 1 as a coordinator and 1 as a router (Latest Zigbee firmware - PAN ID of 2001).
They seem to be hooked up ok and the associate lights are flashing etc.

I have uploaded 2 basic scripts to the Arduinos. 1 basically sends hello every 15 seconds while the other just monitors the line and prints what it finds.
I loaded up 2 putty terminals. The Router is currently on COM7 sending the "hello". The Coordinator is on COM8 listening.

On the COM7 session I can see the hello being printed - but on the COM8 the coordinator is just printing the letter y (well letter y with dots on top - ?). Is there something I need to do specifically to send the data correctly and have it print what I expect? I have a basic understanding of programming but only just starting out with C (work more within shell and Python).

Code below:

Sender
Code: [Select]
int incoming = 0;   // for incoming serial data

void setup()
{
 Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop()
{
 Serial.println("Hello");
 delay(15000);
}


Reciever
Code: [Select]
int incomingByte = 0; // for incoming serial data

void setup()
{
 Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop()
{
 Serial.write(Serial.read());
 delay(15000);
}


The other question I have - as both the XBee's/Arduinos are hooked up to the PC via a USB cable for power I presume the default will be for the data to go via the XBee and not through the shield, Arduino and out through the serial port?
This is the shield I am using - http://www.amazon.co.uk/gp/product/B004V13O16/ref=oh_details_o03_s00_i01

Hope that's not to simple a question - as I am still reading
Cheers

Jack Christensen

#1
Oct 16, 2012, 03:50 pm Last Edit: Oct 16, 2012, 03:52 pm by Jack Christensen Reason: 1
I see two issues with the receiver code. First, it will attempt to read data when none is present. Second, it will potentially miss data while it delays for 15 seconds.

The receiver code should not have delay() in it, and should test for the presence of an incoming byte before reading/printing it. See Serial.available(). Note that it is not reasonable to expect that the two Arduinos stay in sync by virtue of the delays being the same.
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

rev_ollie

Thanks Jack

I have made the changes advised:
Code: [Select]
int incomingByte = 0; // for incoming serial data

void setup()
{
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop()
{
  if (Serial.available() > 0) {
    Serial.write(Serial.read());
  }
}


When setting the Serial.available I presume there is no general preference between having it on an if or while?

After making the changes the sender is still sending hello (listed on COM7 putty session) but there is now no activity on the Coordinator COM8 session...

If that is the case and a statement has been added to only print when it's receiving something through Serial.read - am I correct in thinking I have either done something wrong or there is nothing coming through the serial to read and write?
 

Jack Christensen

I think the code looks fine now. IF or WHILE does not matter.

I'm not terribly familiar with those XBee shields, I just use adapter boards. I know there are jumpers that need to be set up correctly, they will need to be different for programming the XBees vs. operating. In addition to the associate LED, is there another one, possibly labeled RSS or similar? This would illuminate when data is transmitted.

I'm assuming the XBee "AT" firmware is loaded, as opposed to the "API" firmware.
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

rev_ollie

#4
Oct 16, 2012, 05:06 pm Last Edit: Oct 16, 2012, 05:11 pm by rev_ollie Reason: 1
Hi Jack,

Yes the Coordinator has Zigbee Coordinator AT installed (XB24-ZB Version 20A7).
The router has Zigbee Router AT installed (XB24-ZB version 22A7)

On the shield itself there is only the associate LED which is flashing on both devices. The Arduino board has the TX and RX lights - TX flashes once on the sender within the delay interval. Also a single light marked L on the Arduino - which is on on both boards. 

Also the shield has 2 jumpers labelled XBee/USB - both are currently set to USB...I would wonder if that needs changing on the Coordinator...but the other device seems to be working ok sending it to the putty session
Both have a PAN ID of 2001 - with the router set to verify the channel when joining so I can't see anything hugely obvious

PaulS

How are SH, SL, DH, and DL set on each one? You have to tell each XBee who it and who to talk to.

rev_ollie

Phew...ok

I had another look through X-CTU and it all looked ok - so I ran ATRE and put the commands in again on both devices and they seem to be working now - there must have been something wrong in one of the addresses I wasn't picking up on - (I'm not going to admit I put the Coordinators own address as the DL - and it didn't look that way but anything is possible!)

So yes both are now saying hello and I'm happy its going over the xbee and not through serial...now to play some more

Cheers chaps!

Jack Christensen

If the router is sending and the coordinator is receiving, which is what I understood earlier, then DH and DL can remain at their default values of zero, this causes the traffic to go to the coordinator.

But glad you got it working.
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Go Up