Go Down

Topic: Serial Communication between XBee using Arduino (Read 2976 times) previous topic - next topic

Priyanshu27

#30
Aug 23, 2018, 06:32 pm Last Edit: Aug 23, 2018, 07:09 pm by Priyanshu27
If you see the code in Reply #28, in the loop there are two functions called, one for the transmitXBee and other is for receiveXBee. I'm using only and only this code for exchanging messages as the Arduino UNO has to be mounted on the top of the LEGO Robot and I've to merge my code for taking values from the sensor as well as have to transmit and receive the data to other XBee.

However, as asked by you to make two programs till the time it is sure if both the codes are working fine and merge them after that. I'm attaching my transmitter and receiver code separately.

Transmitter Code:

Code: [Select]

#include <XBee.h>
#include <time.h>
#include <stdlib.h>
XBee xbee = XBee();
XBeeAddress64 ROUTER1 = XBeeAddress64(0x0013A200,0x4147FE2A);
XBeeAddress64 ROUTER2 = XBeeAddress64(0x0013A200,0x4147FE2B);
XBeeAddress64 ROUTER3 = XBeeAddress64(0x0013A200,0x4147FE2E);
XBeeAddress64 ROUTER4 = XBeeAddress64(0x0013A200,0x414E65AA);
XBeeAddress64 ROUTER5 = XBeeAddress64(0x0013A200,0x414E65AE);
XBeeAddress64 ROUTER6 = XBeeAddress64(0x0013A200,0x414E65B1);
uint8_t input = 0;
void setup()
{
  Serial.begin(9600);
  xbee.setSerial(Serial);
  Serial.println("Stating Up!");
  srand((unsigned)time(NULL));
}

void loop()
{
  uint8_t data[3];
  uint8_t receivedChar = '0';
  boolean newData = false;
  data[0] = '6';
  data[1] = rand()%256;
  data[2] = ',';
  data[3] = rand()%256;
  ZBTxRequest zbTx1 = ZBTxRequest(ROUTER1, data, sizeof(data));
  ZBTxRequest zbTx2 = ZBTxRequest(ROUTER2, data, sizeof(data));
  ZBTxRequest zbTx3 = ZBTxRequest(ROUTER3, data, sizeof(data));
  ZBTxRequest zbTx4 = ZBTxRequest(ROUTER4, data, sizeof(data));
  ZBTxRequest zbTx5 = ZBTxRequest(ROUTER5, data, sizeof(data));
  ZBTxRequest zbTx6 = ZBTxRequest(ROUTER6, data, sizeof(data));
 
  delay(500);
  Serial.println("Start Transmitting");
  Serial.print("Data Sent:\t");
  Serial.print(data[0]);
  Serial.print(data[1]);
  Serial.print(data[2]);
  Serial.println(data[3]);
  delay(500);
  if (Serial.available() > 0)
  {
    receivedChar = Serial.read();
    newData = true;
  }
  if (newData == true)
  {
    Serial.print("Input: ");
    Serial.println(receivedChar);
    newData = false;
    switch(receivedChar)
    {
      case '1':
        Serial.println("To Router 1");
        xbee.send(zbTx1);
        Serial.println();
        delay(500);
        break;
      case '2':
        Serial.println("To Router 2");
        xbee.send(zbTx2);
        Serial.println();
        delay(500);
        break;
      case '3':
        Serial.println("To Router 3");
        xbee.send(zbTx3);
        Serial.println();
        delay(500);
        break;
      case '4':
        Serial.println("To Router 4");
        xbee.send(zbTx4);
        Serial.println();
        delay(500);
        break;
      case '5':
        Serial.println("To Router 5");
        xbee.send(zbTx5);
        Serial.println();
        delay(500);
        break;
      default:
        Serial.println("Wrong input entered");
        break;
    }
  }
}


Receiver Code:

Code: [Select]

#include <XBee.h>
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();
uint8_t count = 0;
String sample = "";
void setup()
{
  Serial.begin(9600);
  xbee.begin(Serial);
}
void loop()
{
  xbee.readPacket(500);
  Serial.println("Reading for Packet");
  if(xbee.getResponse().isAvailable())
  {
    Serial.print("Packet Available: ");
    Serial.println(count);
    delay(500);
    if(xbee.getResponse().getApiId() == ZB_RX_RESPONSE)
    {
      xbee.getResponse().getZBRxResponse(rx);
      delay(300);
     
      for(int i=0; i<rx.getDataLength(); i++)
      {
        sample += (char)rx.getData(i);
        //Serial.print(rx.getData(i),DEC);
      }
      Serial.print("count: ");
      count++;
      Serial.println(count);
      Serial.print("Packet Received: ");
      Serial.println(sample);
      delay(1500);
    }
  }
  else if(xbee.getResponse().isError())
  {
    Serial.print("Error Reading Packet. Error Code: ");
    Serial.println(xbee.getResponse().getErrorCode());
    delay(500);
  }
}


Hope this will help your query which I might missed.

Robin2

Thanks, that's a big help. However you have not told us exactly what happens when you try that pair of programs.

Also, if this was my problem I would take everything out of the Tx program except the minimum needed to send a message to a single Rx. Simplify, Simplify, Simplify.

And you seem to be sending the contents of the array data[] but I don't see any corresponding array in the Rx program.

I have been having another look at the XBee library documentation and examples. IMHO it is all a bit of dog's breakfast.

It looks like you can send an array[] easily but there is no easy way to receive it - so I can't even be sure that it will be sent :)

Assuming your array data[]is sent correctly then what is received in the payload are the bytes that make up the array. This is a wild guess, but it may work.

... I'll need a little time to figure this out - will reply again asap

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Priyanshu27

Quote
However you have not told us exactly what happens when you try that pair of programs
I mentioned my question in Reply #28 but, I'll state again for your easiness. I'm using a Sainsmart XBee-Arduino Shield which is used to make communication between XBee and Arduino. So there are two jumpers on that shield stating USB/XBEE. So when you have to upload an Arduino Code place the jumpers in USB Mode and when you want to make communication wirelessly, switch them to XBEE Mode.

So, when the jumpers are in USB Mode, the transmitted code is working fine and I'm able to take input from the user. But, when I'm switching the jumpers to XBEE Mode, neither it accepting any serial input nor it is displaying anything at the receiver end (which I understand since it didn't take any input at transmitter end so how it will show anything at the receiver end). So, do I have to apply some similar code I applied at the transmitter end on the receiver side as well or I'm missing any function or library because of which communication will be possible (I have no idea if I would be missing as I'm having zero experience with XBee)?

Quote
Assuming your array data[]is sent correctly then what is received in the payload are the bytes that make up the array. This is a wild guess, but it may work.
Yeah, kind of you are correct. As on the transmitter end if I'm sending from the router (say) 6, and the coordinates are (123,230). So the data which is sent is visible as 5412344230, which means, 54 is the ASCII value of symbol '6', 123 and 230 are the coordinates of the random location and 44 is the ASCII value of ','. So we can understand the coordinates with the help of seeing the ASCII value as 44. So we are sending a data array but at the receiver, we are taking it bitwise and because of lack of knowledge, I'm not able to figure out how to receive the data as sent.

Quote
... I'll need a little time to figure this out - will reply again asap
Sure, you can have your time and meanwhile, I also search for some option by searching through some pages and groups available online. I'll update immediately if I get anything.

Robin2

The following contains a simple technique that I have used previously but had forgotten the details. And I have been meaning for some time to refresh my knowldege.

At the top of your RX program add these two definitions
Code: [Select]
int receivedData[3];
byte* dataPointer;


and then replace this piece of code
Code: [Select]
      for(int i=0; i<rx.getDataLength(); i++)
      {
        sample += (char)rx.getData(i);
        //Serial.print(rx.getData(i),DEC);
      }
      Serial.print("count: ");
      count++;
      Serial.println(count);
      Serial.print("Packet Received: ");
      Serial.println(sample);


with the following
Code: [Select]
    dataPointer = reinterpret_cast<byte *>(receivedData);
    for(int n =0; n < rx.getDataLength(); n++)
    {
        *dataPointer = rx.getData(n);
        dataPointer += 1;
    }
    for (byte n = 0; n < 3; n++) {
        Serial.println(receivedData[n]);
    }


This may look complicated (thanks to C++'s cryptic language) but what it does is actually very simple. It figures out the memory address of the start of the array (in the variable dataPointer) and then writes each successive received byte into the memory addresses of the array. Hopefully that will replicate exactly the array that was sent.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Priyanshu27

Hi Robin, I appreciate you gave me a solution for the receiver mode to store the data transmitted in an array. But for checking that there was some problem at the transmitting end as well which I'm not able to figure out.

Quote
'm using a Sainsmart XBee-Arduino Shield which is used to make communication between XBee and Arduino. So there are two jumpers on that shield stating USB/XBEE. So when you have to upload an Arduino Code place the jumpers in USB Mode and when you want to make communication wirelessly, switch them to XBEE Mode.

So, when the jumpers are in USB Mode, the transmitted code is working fine and I'm able to take input from the user. But, when I'm switching the jumpers to XBEE Mode, neither it accepting any serial input nor it is displaying anything at the receiver end (which I understand since it didn't take any input at transmitter end so how it will show anything at the receiver end)
I explained the whole procedure of how to send a message wirelessly through an XBee it in my previous Reply #32. So, when I type anything in USB Mode it is taking the input entered by me, however, when I type in XBee Mode when the XBee has to transmit wirelessly it is not taking any input.

I tried searching in the documentation of the XBee provided by DIGI "Datasheet for XBee 900HP DigiMesh Kit" and few other places on the internet like StackExchange, and the Arduino Forum itself, but couldn't find any relevant information on that. There may be a possibility that I have missed something while searching, however, almost every place it states that I need to configure my XBee through XCTU to make communication possible which I already did.

Can you look something for me, it will be a great help. So far, you helped me a lot because of which I can see some progress in my project.

Robin2

Hi Robin, I appreciate you gave me a solution for the receiver mode to store the data transmitted in an array. But for checking that there was some problem at the transmitting end as well which I'm not able to figure out.
I am not an XBee expert but I will try to help. Please post the latest version of your Tx and Rx programs that take account of my earlier advice. And tell us in detail what happens when you run them (or post error messages if they won't compile).

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Priyanshu27

Quote
Please post the latest version of your Tx and Rx programs that take account of my earlier advice
Transmitter Code:
Code: [Select]

#include <XBee.h>
#include <time.h>
#include <stdlib.h>
XBee xbee = XBee();
XBeeAddress64 ROUTER1 = XBeeAddress64(0x0013A200,0x4147FE2A);
XBeeAddress64 ROUTER2 = XBeeAddress64(0x0013A200,0x4147FE2B);
XBeeAddress64 ROUTER3 = XBeeAddress64(0x0013A200,0x4147FE2E);
XBeeAddress64 ROUTER4 = XBeeAddress64(0x0013A200,0x414E65AA);
XBeeAddress64 ROUTER5 = XBeeAddress64(0x0013A200,0x414E65AE);
XBeeAddress64 ROUTER6 = XBeeAddress64(0x0013A200,0x414E65B1);
uint8_t input = 0;
void setup()
{
  Serial.begin(9600);
  xbee.setSerial(Serial);
  Serial.println("Stating Up!");
  srand((unsigned)time(NULL));
}

void loop()
{
  uint8_t data[3];
  uint8_t receivedChar = '0';
  boolean newData = false;
  data[0] = '6';
  data[1] = rand()%256;
  data[2] = ',';
  data[3] = rand()%256;
  ZBTxRequest zbTx1 = ZBTxRequest(ROUTER1, data, sizeof(data));
  ZBTxRequest zbTx2 = ZBTxRequest(ROUTER2, data, sizeof(data));
  ZBTxRequest zbTx3 = ZBTxRequest(ROUTER3, data, sizeof(data));
  ZBTxRequest zbTx4 = ZBTxRequest(ROUTER4, data, sizeof(data));
  ZBTxRequest zbTx5 = ZBTxRequest(ROUTER5, data, sizeof(data));
  ZBTxRequest zbTx6 = ZBTxRequest(ROUTER6, data, sizeof(data));
 
  delay(500);
  Serial.println("Start Transmitting");
  Serial.print("Data Sent:\t");
  Serial.print(data[0]);
  Serial.print(data[1]);
  Serial.print(data[2]);
  Serial.println(data[3]);
  delay(500);
  if (Serial.available() > 0)
  {
    receivedChar = Serial.read();
    newData = true;
  }
  if (newData == true)
  {
    Serial.print("Input: ");
    Serial.println(receivedChar);
    newData = false;
    switch(receivedChar)
    {
      case '1':
        Serial.println("To Router 1");
        xbee.send(zbTx1);
        Serial.println();
        delay(500);
        break;
      case '2':
        Serial.println("To Router 2");
        xbee.send(zbTx2);
        Serial.println();
        delay(500);
        break;
      case '3':
        Serial.println("To Router 3");
        xbee.send(zbTx3);
        Serial.println();
        delay(500);
        break;
      case '4':
        Serial.println("To Router 4");
        xbee.send(zbTx4);
        Serial.println();
        delay(500);
        break;
      case '5':
        Serial.println("To Router 5");
        xbee.send(zbTx5);
        Serial.println();
        delay(500);
        break;
      default:
        Serial.println("Wrong input entered");
        break;
    }
  }
}


Receiver Code:
Code: [Select]

#include <XBee.h>
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();
uint8_t count = 0;
String sample = "";
void setup()
{
  Serial.begin(9600);
  xbee.begin(Serial);
}
void loop()
{
  int receivedData[3];
  byte* dataPointer;
  xbee.readPacket(500);
  Serial.println("Reading for Packet");
  if(xbee.getResponse().isAvailable())
  {
    Serial.print("Packet Available: ");
    Serial.println(count);
    delay(500);
    if(xbee.getResponse().getApiId() == ZB_RX_RESPONSE)
    {
      xbee.getResponse().getZBRxResponse(rx);
      delay(300);
      dataPointer = reinterpret_cast<byte *>(receivedData);
      for(int n =0; n < rx.getDataLength(); n++)
      {
        *dataPointer = rx.getData(n);
        dataPointer += 1;
      }
      Serial.print("Packet Received: ");
      for (byte n = 0; n < 3; n++)
      {
        Serial.println(receivedData[n]);
      }
      Serial.print("count: ");
      count++;
      Serial.println(count);
      delay(1500);
    }
  }
  else if(xbee.getResponse().isError())
  {
    Serial.print("Error Reading Packet. Error Code: ");
    Serial.println(xbee.getResponse().getErrorCode());
    delay(500);
  }
}


I'm attaching my output on the serial monitor. You can find them in the attachments.

Also, the code was working there was no compiling error.

Quote
And tell us in detail what happens when you run them
In the attachment, when we transmit a message in USB Mode (@Figure: Transmitter_USB), the input can be seen on the Monitor. However, when we switch it to the XBEE Mode (@Figure: Transmitter_XBEE),  on the Monitor, no input is accepted by the Arduino. On the receiver side, the output remains constant in both the USB and the XBEE modes.

Robin2

#37
Aug 24, 2018, 09:25 pm Last Edit: Aug 24, 2018, 09:28 pm by Robin2
I'm attaching my output on the serial monitor. You can find them in the attachments.

Please don't post pictures of text - just copy and paste your text.

And if posting images (for other reasons) please display them in your post so we can see them without downloading them. See this  Simple Image Guide


I looked at your programs, but I need to see the output.

I think I asked before and you did not say why there are all these lines
Code: [Select]
XBeeAddress64 ROUTER1 = XBeeAddress64(0x0013A200,0x4147FE2A);
XBeeAddress64 ROUTER2 = XBeeAddress64(0x0013A200,0x4147FE2B);
XBeeAddress64 ROUTER3 = XBeeAddress64(0x0013A200,0x4147FE2E);
XBeeAddress64 ROUTER4 = XBeeAddress64(0x0013A200,0x414E65AA);
XBeeAddress64 ROUTER5 = XBeeAddress64(0x0013A200,0x414E65AE);
XBeeAddress64 ROUTER6 = XBeeAddress64(0x0013A200,0x414E65B1);



...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Priyanshu27

Quote
And if posting images (for other reasons) please display them in your post so we can see them without downloading them. See this  Simple Image Guide
The outputs I've attached in Reply #36, I'm attaching them again as directed in the link you provided.

Quote
I looked at your programs, but I need to see the output.
Transmitter_USB: When the jumpers of the shield are in USB Mode.




Transmitter_XBEE: When the jumpers are switched in XBee Mode.




Receiver: The output on the receiving side.



Quote
I think I asked before and you did not say why there are all these lines
I'm afraid you didn't ask that, but, I'll tell you what it tells.

These lines are defining the respective Router's 64-bit MAC Address. Now, when you want to transmit a message from Router 6 to Router 5 (say), you can see zbTx5 in the Transmitter Code. This zbTx5 contains the MAC Address of Router 5, the data we are transmitting and the size of the data which is predefined variables in ZBTxRequest() function of the XBee library.

I hope I answered your queries, but I think that you shall be asking me for the data I'm sending to explain.
So as you can see in the Transmitter_USB image data is 5410244161 when sent to Router 5, it means, 54 is representing '6' which the Router from which message is transmitted, 102 is the x-coordinate, 44 is the ASCII value of "," (comma) and 161 is the y-coordinate. So when we receive it at the receiver end after storing in an array which you suggested, we can separate the coordinates by seeing 54 and 44 position in the data.

Robin2

I'm afraid you didn't ask that, but, I'll tell you what it tells
Until you get something working remove ALL but one of them of the destinations. Make the program as simple as it can possibly be.

The output from your RX program "Reading for Packet" (which I can't copy and past from your picture) suggests that it never receives anything.

Perhaps you have the wrong MAC address? - hence the need to simplify.

I have no idea what the jumpers mean (I prefer a cardigan myself).

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Priyanshu27

Quote
Until you get something working remove ALL but one of them of the destinations. Make the program as simple as it can possibly be
I tried that as well but still, it was not working. What I figured out from my code is that till the time I was sending to the Routers directly without having an input from the Serial Monitor, the code was working fine and I was able to receive it as well.

But, after I added the switch-case statements for performing unicasting operations the code is not working. If you see in the Reply #36, the code I used for transmitting, the code is working till the point we are printing the data we are sending. After that, I've applied an if-statement: if (Serial.available()>0), from that point onwards, the code is not working.

Quote
The output from your RX program "Reading for Packet" (which I can't copy and past from your picture) suggests that it never receives anything.
Yeah in the receiver code, it is just reading the first line stating "Reading for Packet".

Quote
Perhaps you have the wrong MAC address?
No, MAC address is correct. If MAC Address would have been wrong then it won't be able to broadcast any message so far. The problem of transmission begun after I tried unicasting messages by taking input from the user.

Quote
I have no idea what the jumpers mean
LOL!!! I'm attaching a link of Documentation for XBee Shield, it might help you understanding the jumpers (Btw jumpers are the Blue colored blocks in the image shown in the documentation).

Robin2

#41
Aug 25, 2018, 10:00 am Last Edit: Aug 25, 2018, 10:01 am by Robin2
I tried that as well but still, it was not working. What I figured out from my code is that till the time I was sending to the Routers directly without having an input from the Serial Monitor, the code was working fine and I was able to receive it as well.
Post the Tx and the Rx programs that work.

When you run into problems it is often a good idea to go back to a working version and start over.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Priyanshu27

#42
Aug 25, 2018, 09:08 pm Last Edit: Aug 25, 2018, 09:10 pm by Priyanshu27
Quote
Post the Tx and the Rx programs that work.
Transmitter Code (Simplified):

Code: [Select]

#include <XBee.h>
#include <time.h>
#include <stdlib.h>
XBee xbee = XBee();
XBeeAddress64 ROUTER1 = XBeeAddress64(0x0013A200,0x4147FE2A);
XBeeAddress64 ROUTER2 = XBeeAddress64(0x0013A200,0x4147FE2B);
XBeeAddress64 ROUTER3 = XBeeAddress64(0x0013A200,0x4147FE2E);
XBeeAddress64 ROUTER4 = XBeeAddress64(0x0013A200,0x414E65AA);
XBeeAddress64 ROUTER5 = XBeeAddress64(0x0013A200,0x414E65AE);
XBeeAddress64 ROUTER6 = XBeeAddress64(0x0013A200,0x414E65B1);
uint8_t input = 0;
void setup()
{
  Serial.begin(9600);
  xbee.setSerial(Serial);
  Serial.println("Stating Up!");
  srand((unsigned)time(NULL));
}

void loop()
{
  uint8_t i = 0;
  uint8_t data[3];
  uint8_t receivedChar = '0';
  boolean newData = false;
  data[0] = '6';
  data[1] = rand()%256;
  data[2] = ',';
  data[3] = rand()%256;
  //ZBTxRequest zbTx1 = ZBTxRequest(ROUTER1, data, sizeof(data));
  //ZBTxRequest zbTx2 = ZBTxRequest(ROUTER2, data, sizeof(data));
  //ZBTxRequest zbTx3 = ZBTxRequest(ROUTER3, data, sizeof(data));
  //ZBTxRequest zbTx4 = ZBTxRequest(ROUTER4, data, sizeof(data));
  ZBTxRequest zbTx5 = ZBTxRequest(ROUTER5, data, sizeof(data));
  ZBTxRequest zbTx6 = ZBTxRequest(ROUTER6, data, sizeof(data));
  
  delay(500);
  Serial.println("Start Transmitting");
  Serial.print("Data Sent:\t");
  Serial.print(data[0]);
  Serial.print(data[1]);
  Serial.print(data[2]);
  Serial.println(data[3]);
  delay(500);
  while(i<1)
  {
    /*
    delay(500);
    xbee.send(zbTx1);
    Serial.println("To Router 1");
    delay(500);
    xbee.send(zbTx2);
    Serial.println("To Router 2");
    delay(500);
    xbee.send(zbTx3);
    Serial.println("To Router 3");
    delay(500);
    xbee.send(zbTx4);
    Serial.println("To Router 4");
    delay(500);*/
    xbee.send(zbTx5);
    Serial.println("To Router 5");
    delay(500);
    i++;
  }
}


Receiver Code (Suggested by you):

Code: [Select]

#include <XBee.h>
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();
uint8_t count = 0;
String sample = "";
void setup()
{
  Serial.begin(9600);
  xbee.begin(Serial);
}
void loop()
{
  int receivedData[3];
  byte* dataPointer;
  xbee.readPacket(500);
  Serial.println("Reading for Packet");
  delay(500);
  if(xbee.getResponse().isAvailable())
  {
    Serial.print("Packet Available: ");
    Serial.println(count);
    delay(500);
    if(xbee.getResponse().getApiId() == ZB_RX_RESPONSE)
    {
      xbee.getResponse().getZBRxResponse(rx);
      delay(300);
      dataPointer = reinterpret_cast<byte *>(receivedData);
      for(int n =0; n < rx.getDataLength(); n++)
      {
        *dataPointer = rx.getData(n);
        dataPointer += 1;
      }
      Serial.print("Packet Received: ");
      for (byte n = 0; n < 3; n++)
      {
        Serial.println(receivedData[n]);
      }
      Serial.print("count: ");
      count++;
      Serial.println(count);
      delay(1500);
    }
  }
  else if(xbee.getResponse().isError())
  {
    Serial.print("Error Reading Packet. Error Code: ");
    Serial.println(xbee.getResponse().getErrorCode());
    delay(500);
  }
  else
  {
    Serial.println("Packet Not Found");
    delay(500);
  }
}


Quote
When you run into problems it is often a good idea to go back to a working version and start over.
I tried running the above programs and attaching my output for both transmitter and receiver.

Output Transmitter:



Output Receiver:



The question I wanted to ask after running the programs is regarding the suggestion you gave by creating a pointer, we are storing values in an array. So after we typecasted the output I'm able to get in return is like this:

Packet Received: -26058
-25300
-25597

Here, "-26058" value is changing in every iteration, but "-25300" and "-25597" is repeating in every iteration as soon as any packet is received. So, firstly, what are these values, i.e., what it is symbolizing. And, secondly, why are they repeating in every iteration which you clearly saw in the attached image.

Robin2

#43
Aug 25, 2018, 10:11 pm Last Edit: Aug 25, 2018, 10:16 pm by Robin2
Let's slow down a bit and get back to basics.

In Reply #40 you said
Quote
till the time I was sending to the Routers directly without having an input from the Serial Monitor, the code was working fine and I was able to receive it as well.
and in Reply #41 I asked you to post those working programs.

Instead you have posted some other programs, you have posted pictures of the output even though I asked you not to, and you have not said whether the programs you did post are working properly.

How can you claim the transmitter code is simplified when it still has addresses for 6 XBees?

Generating random numbers when you are trying to debug a problem is just madness.

When you create an array with 3 elements you CAN NOT write to the 4th element.

In the circumstances it is very very hard to help.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Priyanshu27

#44
Aug 26, 2018, 12:11 am Last Edit: Aug 26, 2018, 12:13 am by Priyanshu27
Quote
Instead you have posted some other programs, you have posted pictures of the output even though I asked you not to, and you have not said whether the programs you did post are working properly.
I've posted the programs which are not taking any input from the user, the one you asked me to. Also, I run them just to show that it is working without taking input from the user. If you see in the code I sent, I've not mentioned any Serial.read() function to take input from the user.

Quote
How can you claim the transmitter code is simplified when it still has addresses for 6 XBees?
If you want I can remove them, as they are just mentioned them but not actually sending them. If you look in the while loop, I've commented all the other transmissions and have considered only sending data to Router 5 (zbTx5)

Quote
When you create an array with 3 elements you CAN NOT write to the 4th element.
I just noticed this thing and got the point you are referring to. I changed it to 4 both on the transmitter as well as on the receiver side and surprisingly for me, it was working. I'm attaching my output so that you can see what output I'm getting.

The outputs I'm getting after correcting the array size as you instructed are:

Transmitter:



Receiver:



Also, after switching from broadcasting to taking input from the user, it is not accepting input from the Serial Monitor of Arduino. And that is the main thing which I want to do for my project. If you want I can attach the code and output of that too.

Go Up