Read data on XBee

Hi!

I've :
-Arduino Uno
-wireless proto shield
-XBee pro 868MHz S5 802.15.4
-RS485/XBee adapter.

When I press the "Ident" button of the adapter, I receive strange characters (Û, ÿ ...) in my serial monitor.

But the adapter's manual indicate : All API devices that receive this transmission will
send a Node Identification frame out their UART (API ID 0x95). This data is it readable on the serial monitor ? And after that, is it possible to read the text data received by the XBee?

Here is my sketch

#include <SoftwareSerial.h>
#include <XBee.h>

SoftwareSerial XBee(2, 3); //2-RX, 3-TX
int brocheRX = 2 ;
String APID (brocheRX) ;

void setup() {

Serial.begin(9600) ;
delay(50) ;
XBee.begin (9600) ;
pinMode (2, OUTPUT) ;
pinMode (3 , INPUT) ;
}

void loop() {

if (Serial.available() ) {
APID = Serial.readString() ;
Serial.println(APID) ;

}// end if
}//end loop

Thank you in advance for your answer.

When I press the "Ident" button of the adapter, I receive strange characters (Û, ÿ ...) in my serial monitor.

All we have is a vague description of the hardware - no links, no schematics, nothing really.

String APID (brocheRX)  ;

This is equivalent to:

String APID = "2";

How is THAT a useful initial value?

But the adapter's manual indicate : All API devices that receive this transmission will
send a Node Identification frame out their UART (API ID 0x95). This data is it readable on the serial monitor ?

So, the XBees are expected to be in API mode, but you are reading them as though they are in AT mode. Wrong!

I send pictures and notice of the XBee/RS485. Digi Python Wiki Archive.

int brocheRX= 2 it is to affect the receive data to the pin2 (RX) no?

Ok then the problem is that XBee must be set in AT mode? With Arduino or with X-CTU? Because when I test the range with X-CTU the data wich I received are bad too.

And when I replace the API by the AT mode, the sketch which I have written is good or not?

Adapter.PNG

Adapter 2.PNG

Adaptateurs DIN.pdf (912 KB)

Oops I didn't realize. I must read the data by packet like this sketch (XBee S2 RX) :

#include <XBee.h>

/*
This example is for Series 2 XBee
Receives a ZB RX packet and sets a PWM value based on packet data.
Error led is flashed if an unexpected packet is received
*/

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();

int statusLed = 13;
int errorLed = 13;
int dataLed = 13;

void flashLed(int pin, int times, int wait) {

for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(wait);
digitalWrite(pin, LOW);

if (i + 1 < times) {
delay(wait);
}
}
}

void setup() {
pinMode(statusLed, OUTPUT);
pinMode(errorLed, OUTPUT);
pinMode(dataLed, OUTPUT);

// start serial
Serial.begin(9600);
xbee.begin(Serial);

flashLed(statusLed, 3, 50);
}

// continuously reads packets, looking for ZB Receive or Modem Status
void loop() {

xbee.readPacket();

if (xbee.getResponse().isAvailable()) {
// got something

if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
// got a zb rx packet

// now fill our zb rx class
xbee.getResponse().getZBRxResponse(rx);

if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
// the sender got an ACK
flashLed(statusLed, 10, 10);
} else {
// we got it (obviously) but sender didn't get an ACK
flashLed(errorLed, 2, 20);
}
// set dataLed PWM to value of the first byte in the data
analogWrite(dataLed, rx.getData(0));
} else if (xbee.getResponse().getApiId() == MODEM_STATUS_RESPONSE) {
xbee.getResponse().getModemStatusResponse(msr);
// the local XBee sends this response on certain events, like association/dissociation

if (msr.getStatus() == ASSOCIATED) {
// yay this is great. flash led
flashLed(statusLed, 10, 10);
} else if (msr.getStatus() == DISASSOCIATED) {
// this is awful.. flash led to show our discontent
flashLed(errorLed, 10, 10);
} else {
// another status
flashLed(statusLed, 5, 10);
}
} else {
// not something we were expecting
flashLed(errorLed, 1, 25);
}
} else if (xbee.getResponse().isError()) {
//nss.print("Error reading packet. Error code: ");
//nss.println(xbee.getResponse().getErrorCode());
}
}

And I want to read this String data which I receive. it is possible ?

And I want to read this String data which I receive. it is possible ?

You don't receive String data. You receive a packet that might contain some characters. You can use them as is. You can copy them to a string (a NULL terminated array of chars) or you can copy them to a String.

If you use a String, you are on your own.

int brocheRX= 2 it is to affect the receive data to the pin2 (RX) no?

No. That variable is never used, except to uselessly assign an initial value to the String instance.

You told the SoftwareSerial class that pins 2 and 3 were its to use. Diddling with them in setup() is a bad idea.

Ok but do I need the "Series1_Rx" or "Serie2_Rx" sketch for my XBee pro 868MHz serie 5 ?

I tested this sketch :

#include <SoftwareSerial.h>
#include <XBee.h>

XBee xbee = XBee();

SoftwareSerial XBee( 2, 3 ); //2-RX, 3-TX
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();

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

void loop() {
xbee.readPacket() ;
if ( xbee.getResponse().isAvailable() ) {
if (Serial.available() ) ;
if ( xbee.getResponse().getApiId() == ZB_RX_RESPONSE ) ;
xbee.getResponse().getZBRxResponse( rx );
String RxByUNO = Serial.readString() ;
Serial.println( RxByUNO ) ;

}// end if
}//end loop

But I don't know how to copy packet to a String ?

            if (Serial.available() ) ;

WTF?

But I don't know how to copy packet to a String ?

And, I have no intention of telling you. Copying to a string, on the other hand is simple.