XBee AT/API Reliability

Hi all, I'm trying to control 4 servos with 4 pot via xbee, setup as follows:

Tx: Arduino connected to 4 pots(pins 0-3) & XBee (Series 2.5)

Rx: Arduino connected to 4 servos (pins 5, 6, 10, 11) & XBee (Series 2.5)

The Tx side will map the pot values (0-180) and send them over to Rx.

 

I've setup the XBees in AT Mode using guibot's tutorial but the order of the 4 values @ the Rx end jumbles up at times.

Thus, I'm trying out the API mode with the Xbee library but with no success.

I've tested the Series2_Tx & Series2_Rx examples in the library but I'm getting 2 flash on the led, which translates to:

// local XBee did not provide a timely TX Status Response -- should not happen

 

Is AT mode sufficient for what I'm attempting? How should I go about with the API mode?

 

Thanx

Are you sending them all in

Are you sending them all in a packet?

I use the “regular” out of the box mode with xBees and they are yet another serial link, always giving me everything in order received. They do buffer and then send, so I think you can overrun the buffer. I would call millis() after every send and save the value in an unsigned long. Then the next time you are about to send, subtract that value from the current millis() value to make sure that data has had time to go out. I would also send a packet with a specific start and end character and an expected number of bytes in between to make sure they are good.

intermittent connection?

how do you config the XBees?

I only set the panID, node ID, & baud rate to 9600 (ZNet 2.5 Coordinator & End Device AT)

I’ve a startByte & endByte as follows:

Serial.print(startByte, BYTE);

Serial.print(val1, BYTE);

Serial.print(val2, BYTE);

Serial.print(val3, BYTE);

Serial.print(val4, BYTE);

Serial.print(endByte, BYTE);

delay(10);

 

The code works find when the XBee is not connected.

The Tx pin on the Arduino flashed at a constant rate.

With the XBee connected, the Tx pin flashed for a while, inconsistent pause, then flash again.

why is this so?

 

 

I don’t configure them at all

I planned to, and for some projects it makes sense, but for my first use there are times when I want one satellite unit to respond to a peer when they are both out of range of the base. So I actually have a from and to address as part of my own custom format. Messages are short and infrequent, so it isn’t a big processing drain for all units to get them and have most decide to ignore them. I got an extra unit that I put on a USB Explorer so I can watch all the traffic.

Anyway, straight out of the box, they should work fine but if there is other traffic on the same frequency you will get it and have to discard it.

Once that works, then I would worry with adding the IDs. Then you will know whether or not the issue is related to ID processing or not. If you can’t get messages with factory configuration then you may be getting interference from some other device.

Config?

Don’t config as in don’t even need to set one as coordinator & one as end device?

Qn regarding the tx led: does the intermittent flash indicates that the prob lies with the tx arduino?

Updates

I’ve restored the XBees to factory setting & same thing;

w/o XBee, Tx led flashed at constant rate

w XBee, Tx led flashed intermittently

Are you doing anything to be

Are you doing anything to be sure you don’t overflow on the Tx end? The baud rate at which you communicate with the xBee module is not the guaranteed baud rate that characters are delivered at. Try starting with overkill, like a delay(50) after you send each character. If that works, reduce the number until it fails again and you can determine the actual aggregate rate you are getting.

And yes, I meant full reset to “party line” mode.

I’ve tried delay(1000) but

I’ve tried delay(1000) but with same result.

 

How do i ensure that the Tx is not overflowing?

A delay of 1000 between each

A delay of 1000 between each character? If you can’t send one character per second at close range using factory defaults then one of your xBee units is bad. You should see a a data rate of over 500 characters per second even at medium range.

But just to make sure - your diagnostic has to be at the send end first and needs to have e a timeout.

You’re right, one or both of

You’re right, one or both of my XBee’s is dead.

 

Borrowed some XBee’s from my friend and it works. Now I’m trying to ‘revive’ my XBees.

 

One more problem though, I’ve to put the Coordinator on the Rx & the End Device on the Tx for it to work.

Switching them does not work.

I can’t help you with the

I can’t help you with the Coordinator and End Device issues. I wanted a more equal peer relationship, so I implemented my own protocol. An observation I can make is that your test indicates that the End Device has the correct address for the Coordinator. Other assumptions are still assumptions…

Meery Xmas! Managed to

Meery Xmas!

 

Managed to revived one of the XBees, still working on the second one. Any help with de-bricking will be appreciated.

 

I thot the one of the Xbee must be set to the coordinator; the other an end device?

what kind of protocol are you using?

 

HBPL

 

Home Brewed Party Line - I made that up. I have not used the configuration utility on mine. I have the 900 Pros. Out of the box, I turned a couple on and found I could send back and forth as if there were a wire, but it is inherently half duplex. I turned on a third and found it was receiving all transmissions from the other two. In the overall system I am working on, there is a base unit but several scenarios where it is out of range or not functioning. I can’t reveal details, but it is very important that individual elements of the system should continue to work together if at all possible.

Anyway, I send short infrequent packets with collision avoidance and detection. That is a fancy way of saying I make sure there is no data coming in right now before I send and none coming in right after I send. A few specific packets require acknowledgement and will be resent on an interval until acknowledged. The unit’s address (my conceptual address) is used to compute resend intervals so that colliding units will not stay in synch.

My packets are ASCII so I can read them, separated by CRLF. I always start with a particular letter, followed by 4 hex numerals, 2 for from address and 2 for to address, a 3 character command and however many parameters I need after that each preceded with a comma. Easy to read, import and manipulate. Most packets are under 20 characters and all are under 60. It is rare to have more than one unit transmitting more frequently than every few minutes and when more than one are frequently transmitting, it is usually query/response. 

hey, do you have the code

hey, 

do you have the code for what you are doing?

I know this is the forum for discussing your problem with the xbee’s but i would be very interested in seeing your code

Thanx for the detailed

Thanx for the detailed explanation and all the help. Really appreciate it.

Here you go: Tx:const int

Here you go:

 

Tx:

const int startByte = 199;
const int endByte = 250;

int data1, data2, data3, data4;

void setup(){
  Serial.begin(9600);
}

void loop(){
  data1 = analogRead(0);
  data2 = analogRead(1);
  data3 = analogRead(2);
  data4 = analogRead(3);
 
  data1 = map(data1, 0, 1023, 0, 180);
  data2 = map(data2, 0, 1023, 0, 180);
  data3 = map(data3, 0, 1023, 0, 180);
  data4 = map(data4, 0, 1023, 0, 180);

  Serial.print(startByte, BYTE);            //Initiate
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
  Serial.print(data3, BYTE);
  Serial.print(data4, BYTE);
  Serial.print(endByte, BYTE);              //End
 
  delay(10);
}

 

Rx:

#include <Servo.h>

Servo servo1, servo2, servo3, servo4;

byte rx, data1, data2, data3, data4;

const int startByte = 199;
const int endByte = 250;
const int error = 255;

void setup(){
  Serial.begin(9600);

  servo1.attach(5);
  servo2.attach(6);
  servo3.attach(10);
  servo4.attach(11);
}

void loop(){
  if (Serial.available()){
    rx = Serial.read();
    delay(6);                  //needed for code to work
   
    if (int(rx) == startByte){
      data1 = Serial.read();
      data2 = Serial.read();
      data3 = Serial.read();
      data4 = Serial.read();
      rx = Serial.read();
     
      if(int(rx) == endByte && (int(data1) != error ||
                                  int(data2) != error ||
                                  int(data3) != error ||
                                  int(data4) != error)){
        servo1.write(int(data1));
        servo2.write(int(data2));
        servo3.write(int(data3));
        servo4.write(int(data4));
      }
    }
  } 
}