Home/Support/Support Forum/Two way XBee communication with ARDUINO

Two way XBee communication with ARDUINO

0 votes
Hi. I have only 2 XBee`s in my network, 1 Cordinator API and 1 end device AT. My cordinator is hook up to a ARDUINO UNO, my end device is driven by batteries.

My end device is reading a analog temperature signal and my cordinator is reciving this and I can read the value with serial monitor.

My poroblem is this: I want to read the analog signal with my ARDUINO program, check if this signal is greater then 28 C, if the temperatur is greater then 28 I want to set a digital output high on the end device.

I have some experience with the AT command request I have tried to solve my problem with the code

"If (temp > 28)
send a command request with serial.write"

The XBee is able to send the command request, but after this the end device stop reading the analog signal.

Any suggestions to have I should solve this? Any help would be appreciated.

With kind regard

Espen
asked Oct 12, 2015 in XBee Programmable Development by espeno New to the Community (0 points)

Please log in or register to answer this question.

1 Answer

0 votes
What is the line that is Enabled and what is the API frame you are sending to change the state of the remote DIO line?
answered Oct 12, 2015 by mvut Veteran of the Digi Community (11,300 points)
I have tried several for both the Digital and Analog signal. Right now they are AI = AD2, DO = AD3. The API frame I am sending is 0x17 Remote command request.
Espen
What are the Actual API frames you are sending?
I don`t understand your question....  Im sending a API frame from arduino that has frame type 0x17. This frame works as long as I dont have analog input enabled on the end device. But when a analog input channel is enabled the end device is sending a 0x92 frame that I am reading the analog sample from. I compare the analog signal in arduino program, when the analog signal reach threshold arduino program sends a 0x17 frame (I can see this in the serial monitor). After the end device recive the frame it stops reading the analog signal.
Another words if I wanted to test this, What is the FULL API frame that is being sent to the transmitting XBee  and what lines, settings or AT Commands that are NOT at their default values on the remote side?
Ok, here is my code for reading signal and sending frame:
float temp;
float analogValue;
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available() >= 21)
    {
    if (Serial.read() == 0x7E) {
      for(int i=0; i<18; i++) {
      byte discard = Serial.read();
      }
      int analogHigh = Serial.read();
      int analogLow = Serial.read();
      analogValue = analogLow + (analogHigh*256);
      temp = (((analogValue/1023)*1200)-500)/10;
      Serial.print(temp);
      }
      Serial.println();
    }

  if (temp >= 30)
  {
    func(0x5);
  }
  else
  {
    func(0x4);
  }
}

  void func(char value)
  {
  Serial.write(0x7E);
  Serial.write((byte)0x0);
  Serial.write(0x10);
  Serial.write(0x17);
  Serial.write((byte)0x0);
  Serial.write((byte)0x0);
  Serial.write((byte)0x0);
  Serial.write((byte)0x0);
  Serial.write((byte)0x0);
  Serial.write((byte)0x0);
  Serial.write((byte)0x0);
  Serial.write(0xFF);
  Serial.write(0xFF);
  Serial.write(0xFF);
  Serial.write(0xFE);
  Serial.write(0x02);
  Serial.write('D');
  Serial.write('1');
  Serial.write(value);
  long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '1' + value;
  Serial.write( 0xFF - (sum & 0xFF));
  }
That does not tell us what your API frame is that you are sending out the UART.  

The API frame would be something like:
7E 00 10 17 00 00 00 00 00 00 00 FF FF FF FE 02 44 31 03 73

Notice that the frame is entirely in Hex and includes the value and the checksum.  Now I am not sure you can issue a Remote AT command to ALL nodes like this but you should try and do this as a Unicast packet instead.
Not sure why I have to send a Unicast packet, the program below have no problem setting the AD3 as an digital output and toggle between HIGH and LOW.  

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

void loop()
{
  setRemoteState(0x5);
  delay(3000);
  setRemoteState(0x4);
  delay(3000);
}

void setRemoteState(char value) { // Lagrer verdien vi √łnsker og sende til ruter
  
  Serial.write(0x7E);
  Serial.write((byte)0x0);
  Serial.write(0x10);
  Serial.write(0x17);
  Serial.write((byte)0x0);
  Serial.write((byte)0x0);
  Serial.write((byte)0x0);
  Serial.write((byte)0x0);
  Serial.write((byte)0x0);
  Serial.write((byte)0x0);
  Serial.write((byte)0x0);
  Serial.write(0xFF);
  Serial.write(0xFF);
  Serial.write(0xFF);
  Serial.write(0xFE);
  Serial.write(0x02);
  Serial.write('D');
  Serial.write('3');
  Serial.write(value);
  long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '3' + value;
  Serial.write( 0xFF - (sum & 0xFF));
}
So what line is enabled as an analog input?  Could it be that your Code does not know how to Parse out the data between the two types?
AD2. The 0x92 frame changes as soon as im trying to send the 0x17 frame. Im not even sure if it`s possible to do this with XBee. Continuously sending one frame and receiving another. The documentation around this is very pore.
Sounds like you are sampling ADC and not aware that it will also sample DIO lines in the same packet.   That is to say, before you Enable the DIO line, your receive frame only shows that you have an Analog Sample and the values is this...  But as soon as you Enable the DIO, that sample packet changes to include all Enabled ADC and DIO lines as well.   So your application need to be able to read the 0x92 frame regardless of what is in that packet.
Thanks! that gave me a few ideas. But will the sample 0x92 also include DO signals? I thought is was not a sample as it`s an output.
By the way, do you know if the receiver will always send at Command Response to the AT command? Or is this only with AT command IS?
I think there is something wrong with my arduino program.
It will not sample an output line but it will sample any enabled inputs.

All AT commands will issue some sort of response when issued.
...