Converting NRF24 code to XBEE

I have a question. I was building a RC transmitter/Reciever using a NRF24 module and it worked but I want to use XBEE instead. The issue I have is trying to get the Serial Data Packets from one Arduino to another. It is easy to get one Byte across but I want a Packet of 10 different Bytes to be sent and parsed into 10 different variables. I would really like to try and keep the Struct "Data_Package" the same as the NRF24 code but not sure if this is possible.

This is the original NRF24 code looks like this:

// Max size of this struct is 32 bytes - NRF24L01 buffer limit
struct Data_Package {
  byte j1PotX;
  byte j1PotY;
  byte j1Button;
  byte j2PotX;
  byte j2PotY;
  byte j2Button;
  byte pot1;
  byte pot2;
  byte tSwitch1;
  byte tSwitch2;
  byte button1;
  byte button2;
  byte button3;
  byte button4;
Data_Package data; //Create a variable with the above structure

Then the Serial TX/RX look like this:

// TX Send the whole data from the structure to the receiver
  radio.write(&data, sizeof(Data_Package));
// RX Read the whole data and store it into the 'data' structure, sizeof(Data_Package));

I have tried various versions of Serial.Write and Serial.Read followed by (&data, sizeof(Data_Package)); but can not get it to compile. I get error "no matching function for call to 'HardwareSerial::read(Data_Package*, unsigned int)'" Not sure whats going on here.

Basically I was building the below project with Xbee instead of NRF24.

You will have to cast to byte.

  // send
  Serial.write((byte*)&data, sizeof(data));

  // receive
  byte *rcvData = (byte*)&data;
  rcvData[0] =;
  rcvData[1] =;

Thanks, I'll try that.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.