nrf communication problem

hi friends. at first sorry my bad english. for my wireless car project, i use nrf24l01 and gyro sensor(adxl345). i want to control car with glove. on transmitter arduino i use adxl345 and arduino nano. it creates x,y,z axis succesfully. but when i want to send this values to the reciever , i have problem. if i write “radio.write(data, sizeof(data));” it doesnt work but if i write " radio.write(data, 1); radio.write(data, 2); radio.write(data, 3);" it works but has some problems. x axis value is true, y axis value is true one times but one times its value shows zero. and z axis value is always zero.
i use arduino nano both sides, and all nrf has adapter. can someone help me

--------------Transmitter Code----------

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>

#define ACC (0xA7>>1) //ADXL345 ACC address
#define A_TO_READ (6) //num of bytes we are going to read each time (two bytes for each axis)

#define CE_PIN   9
#define CSN_PIN 10

int data[3];

const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
void setup()
{
 Serial.begin(9600);
 radio.begin();
 radio.openWritingPipe(pipe);
 Wire.begin();
 initAcc();
}

void loop()
{
 int hx, hy, hz;
 int acc[3];
 getAccelerometerData(acc);
 hx = acc[0];
 hy = acc[1];
 hz = acc[2];
 
   Serial.print(" X=");
   Serial.print(hx);
   Serial.print(" Y=");
   Serial.print(hy);
   Serial.print(" Z=");
   Serial.println(hz);
   delay(50);
 
 data[0] = hx;
 data[1] = hy;
 data[2] = hz;
 radio.write(data, sizeof(data));
}
.
.
.
(other functions for adxl345)

----------Reciever Code------------

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN   9
#define CSN_PIN 10
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
int data[3];

void setup()
{
  Serial.begin(9600);
 radio.begin();
 radio.openReadingPipe(1, pipe);
 radio.startListening();
}


void loop() {
 if ( radio.available() ) 
  
     radio.read( data, sizeof(data) );
     Serial.print("x :");
     Serial.println(data[0]);
     Serial.print("y :");
     Serial.println(data[1]);
     Serial.print("z :");
     Serial.println(data[2]);
   
 }
 else
 {
   Serial.println("No Signal");
 }
 
}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

can anybody help me?

Have a look at this Simple nRF24L01+ Tutorial.

You should send all the data elements in a single message. If they are all of the same type put them in an array and send the array. That is illustrated in my tutorial.

...R

Why do you use such convoluted code?

void loop()
{
 int hx, hy, hz;
 int acc[3];
 getAccelerometerData(acc);
 hx = acc[0];
 hy = acc[1];
 hz = acc[2];
 
   Serial.print(" X=");
   Serial.print(hx);
   Serial.print(" Y=");
   Serial.print(hy);
   Serial.print(" Z=");
   Serial.println(hz);
   delay(50);
 
 data[0] = hx;
 data[1] = hy;
 data[2] = hz;
 radio.write(data, sizeof(data));
}

You can print and send the data directly from the results array.
Why do you want to print the data before sending it, adding latency?
BTW: Why do you want your string constants to eat RAM?

void loop() {
  int acc[3];
  getAccelerometerData(acc);
  radio.write(acc, sizeof(acc));
 
  Serial.print(F(" X="));
  Serial.print(acc[0];
  Serial.print(F(" Y="));
  Serial.print(acc[1]);
  Serial.print(F(" Z="));
  Serial.println(acc[2]);
  delay(50);
}

Drop that crappy

 else
 {
   Serial.println("No Signal");
 }

If available() returns false, there is just no packet waiting, which is a rather normal state.
By flooding the 9600 Serial you will block and receiving the expected twenty packets a second
will be much harder.

Even the generated output in case of an reception ("x :1023y :1023z :1023" + CR + LF) takes nearly half
of the time you have allotted for a single packet.