Xbee S2C & Arduino uno

Hi guys,

I am having problems with my Xbees , i am working on a sensor network project and i got these Xbee S2C instead of the normal xbees series 2 , and no code on the internet is working for me to send and receive data from one to another using 2 arduino uno for each xbee one arduino.

i have programmed them on the XCTU software one router and one coordinator , when they are in transparent mode i can get them to communicate and even when they are in API mode . but when i connect them to my arduino uno here is the problem, there is no code that i can either write or just copy past from all over the internet that would send data from one xbee to another , cause i think if i am able to receive data , any data if just one letter or anything ,then code for the sensors that i am going to connect later on is not going to be an issue. So please if anyone has any idea how to fix this i would very much appreciate it .

XBee S2C Zigbees can be interfaced with an Arduino similarly to any other XBee, just feed it the UART serial data you want transmitted. Same for receiving - it's the same process as any other XBee.

i have tried so many codes , and even tried including xbee.h and making a code using it but i don't receive anything on the coordinator , can you give a sample code for transmitter and receiver that should work on Xbee S2 C .
and btw the part number of the xb is (XB24CZ7WIT-004) if it helps

Pgchaer:
i have tried so many codes , and even tried including xbee.h and making a code using it but i don't receive anything on the coordinator , can you give a sample code for transmitter and receiver that should work on Xbee S2 C .
and btw the part number of the xb is (XB24CZ7WIT-004) if it helps

Wait, are you doing all of this testing in API, transparent, or some other mode? Pick a sketch, use API mode (unless your project requires a different mode), and then reply with your code (in tags) with any specific problems you are facing.

Also, can you please give a DETAILED project description?

1 Like

Check this out: link

i am using my xbees in api mode, the project is a sensor network which consists 2 nodes and a base station .
but it is irrelevant now since i just want to establish a connection between the 2 xbees through the arduinos and send and receive data.
regarding the code i have tried countless and i am not receiving any data in any of them when with the same code other people online seem to be getting results, ill post the 2 most recent tested codes :

Code 1 Router :

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); 
}

Code 1 Coordinator:

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();

       }
}

Code 2 Router :

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

XBee xbee = XBee();

SoftwareSerial XBee(2,3); // RX, TX

ZBRxResponse ZBRx16 = ZBRxResponse();


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

void loop() 
{
 // Create an array for holding the data you want to send.
 uint8_t payload[] = { 255, 128 };
 
 // Specify the address of the remote XBee (this is the SH + SL)
 XBeeAddress64 addr64 = XBeeAddress64(0x00000000, 0x0000FFFF); 
 
 // Create a TX Request
 ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
 
 // Send your request
 xbee.send(zbTx);
 delay(100);
}

Code 2 Coordinator:

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

XBee xbee = XBee();

SoftwareSerial XBee(2,3); // RX, TX

ZBRxResponse ZBRx16 = ZBRxResponse();
#define MAX_FRAME_DATA_SIZE 110

void setup() 
{
 pinMode(13, OUTPUT);
 Serial.begin(9600);
 Serial.flush();
 XBee.begin(9600);
 
}

void loop() 
{
 xbee.readPacket();
 
 if (xbee.getResponse().isAvailable()) {
     // got something
 
       xbee.getResponse().getZBRxResponse(ZBRx16);
       if (ZBRx16.getData(0)==255)
         digitalWrite(13, HIGH);
     }
}

Although i don't really know what the second code should show exactly but the coordinator should have received something, PS: i am a beginner in arduino code that's why im having a really hard time.

and about the link i already checked it and this guy has youtube videos which i have watched called xbee tutorials 1-5 , he was the reason i worked with xbees but his code doesn't work with my xbees other than the XCTU setups for his xbees are different than the XB24C (mine) and that he always uses just 1 arduino with the other xbee linked directly to the computer.

Do not cross post. I remember your earlier thread where I told you that you shouldn't use the hardware serial port for the XBee comms. You need to use a library such as softwareserial.h

Make that change, test it, and if it still doesn't work, post the NEW code and any details as to how it isn't working.

it wasn't me who opened that thread i just tried to make use of his code and it didn't work on my project i even tried what he did to remove the rx or tx ( i didn't understand what he did i just tested random stuff) you can check his thread to make sure .

about your suggestion what do you mean by using softwareserial.h ?what would the changes be in the code , cause i tried a couple of codes that used this library and still didn't get any output. if you can post an example that could work that would be great.

And i am not sure if this is what you meant but i tried to check youtube and use softwareserial.h and this is what i got but i didn't know how to adjust the Router just the coordinator

Coordinator Code:

#include <SoftwareSerial.h>
int incoming=0;
SoftwareSerial mySerial {2,3};  //RX,TX
void setup() {
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  if (mySerial.available()) {
    Serial.write(mySerial.read());
    if (Serial.available())
    mySerial.write(Serial.read());

    Serial.println(" hello world");
                

       }
}

i just added those 2 lines on the Router code from the previous reply:

#include <SoftwareSerial.h>
SoftwareSerial mySerial {2,3}; //RX,TX

Sorry for the late reply and mixing you up with the OP of another post.

As for your problem, I'm not too sure what's going wrong. Can you list the exact configuration details of each XBee (found via XCTU)?

Also, do you by any chance have two explorer dongles?

Here is the reference guide that explains what sofwareserial.h is, why it is useful to you, and how to use it.

yes i have 2 explorer dongles and i can test the connectivity on xctu and i can send and receive data there but when i plug it into the arduino nothing comes up .
as for the settings there are as follows (im only going to list what i have changed)
coordinator:
id pan : 1234
jv : disabled
CE: enabled
DH:0
DL:FFFF
AP: API enabled 1

Router:
id pan : 1234
jv: enabled
CE: disabled
DH:0
DL:FFFF
AP:API enabled 1 ( and i tried transparent)

when i tried transparent when i send data i receive on the coordinator and all is good but just when there is no arduino , when i try a code to send anything nothing shows up on the coordinator even tho they would be connected to each other , but in the end i need the router in api mode since i wana use more than just 1 with 4 sensors each .
and thank you for your reply its very much appreciated .

Ok, cool.

First, I would check how the XBees are being powered. I once had a very similar problem with my XBees where they could communicate via XCTU, but not Arduino. Turns out powering the XBee off the Arduino was a bad idea.

You'll need to power the XBees off their own power supplies if you haven't done so already. What are you doing to power the modules?

Lastly, can you send a picture of your physical setup with clear labels for each wire?

yes i am powering the xbees from the arduino but the lights of the adapter are lighting normally and nothing is strange although i will try what you just suggested . but i think my main problem lies with the code , if you can provide a really simple code that is supposed to work and send data and receive it i will test and know for sure its not from the code .

my setup is simple same connections on the routed and coordinator.

i have an adapter with 5 pins coming out of it :
1- 5v
2-ground
3-TX
4-RX
5-Reset

i connect the first 2 pins to the pins on the arduino that says 5v and ground
and i connect the tx of the xbee to the rx of the arduino and the rx of the xbee to the tx of the arduino.

and that's basically it i didnt even connect the sensors , i think all that would be easy if i just can send and receive data from router to coordinator.

Pgchaer:
my setup is simple same connections on the routed and coordinator.

i have an adapter with 5 pins coming out of it :
1- 5v
2-ground
3-TX
4-RX
5-Reset

i connect the first 2 pins to the pins on the arduino that says 5v and ground
and i connect the tx of the xbee to the rx of the arduino and the rx of the xbee to the tx of the arduino.

Yes, but I'd rather see a pic of the actual setup as concrete proof. There is a slight chance you missed a connection and didn't notice - I've done it myself - so have many others. Plus, I don't understand your pinout description. (i.e. what does 1, 2, 3 (etc.) mean?).

Quick Q: You crossed TX and RX lines, right? As in: TX from Arduino goes to RX (aka Din) of XBee and vice versa.

Yes i have crossed the TX and RX . and the numbers above refer to the pins on the adapter i have attached a picture of the adapter as well as the setup .
and again the numbers in the picture are as follows:

1- 5v
2-ground
3-TX
4-RX
5-Reset

adapter:

Setup:

i've tried to attach the pictures and many other ways it didn't show , so i uploaded them to a site and linked the url instead.

Ah ha!

A picture is worth a thousand words, and your pics just told me your wiring is wrong. Here's why: When using XBees (or any other UART comms device for that matter), you need to use the softwareserial TX and RX pins instead of pins 0 and 1 (like you're doing right now).

Therefore, you need to take out the wire in pin 0 and put it in pin 2, take the wire out of pin 1 and put it in pin 3.

Try this and it just might work with the following code (Link):

Arduino code:

Hardware Hookup:
  The XBee Shield makes all of the connections you'll need
  between Arduino and XBee. If you have the shield make
  sure the SWITCH IS IN THE "DLINE" POSITION. That will connect
  the XBee's DOUT and DIN pins to Arduino pins 2 and 3.

*****************************************************************/
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(2, 3); // RX, TX

void setup()
{
  // Set up both ports at 9600 baud. This value is most important
  // for the XBee. Make sure the baud rate matches the config
  // setting of your XBee.
  XBee.begin(9600);
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available())
  { // If data comes in from serial monitor, send it out to XBee
    XBee.write(Serial.read());
  }
  if (XBee.available())
  { // If data comes in from XBee, send it out to serial monitor
    Serial.write(XBee.read());
  }
}

IMPORTANT: connect the other XBee into your PC, and set up a comms link in XCTU between the PC XBee and Arduino XBee. Next, use the serial monitor to send a character or two to the Arduino and see if you can see it pop up in the XCTU.

Do you understand?

okay so i understood what you suggested , and i tested the code and changed the connections although in all the tutorials i saw they were connecting to the 0 and 1 of the arduino that's why i was doing so , i tried both api and transparent mode and still nothing i even tried to change the code since it was not working as the exercise intended and fixed it and still i got nothing on the coordinator side.

i have found this thread that has a similar problem but he seemed to solve it but didn't post exactly how so if anyone can understand better what he did and know how to solve it please let me know.
here is the link to his thread :

https://forum.arduino.cc/index.php?topic=473785.0

you need to connect the 3.3 volt to Xbees ND NOT 5 volt..

Also, softwareserial are the libraries used for other pins of arduino which are not for serial communication but do so by software!!