nRF24L01 data transmission problem

hi !

i am trying to send 30 second countdown clock detail between two nRF24L01’s (one is sending other one should capture) i think sending is somehow totally differ from what receives (receives wrong detail)
this is my coding … anybody who can help would be most appreciated

TX code


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

RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
uint8_t count = 30; // 30 seconds to count down to zero

struct package
{
 uint8_t digit1;
 uint8_t digit2;
};

typedef struct package Package;
Package data;

void setup() {
 
 Serial.begin(9600);
 radio.begin();
 radio.openWritingPipe(address);
 radio.setPALevel(RF24_PA_MIN);
 radio.setAutoAck(false);
 radio.stopListening();

}

void loop() {

 uint8_t minutes = count / 60;
 uint8_t secondsTens = (count - minutes * 60) / 10; // Seconds tens place
 uint8_t secondsOnes =
   count - (minutes * 60) - (secondsTens * 10); // Seconds ones place

 data.digit1 = secondsOnes;
 data.digit2 = secondsTens;

 Serial.print(data.digit2);
 Serial.println(data.digit1);

 radio.write(&data, sizeof(data));

 delay(1000);
 count--;
 if (count == 0) {
   count = 30;
 }
}

RX Code


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


RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
uint8_t secondsOnes = 0;
uint8_t secondsTens = 0;



struct package
{
 uint8_t digit1;
 uint8_t digit2;
};


typedef struct package Package;
Package data;


void setup() {
 
 Serial.begin(9600);
 radio.begin();
 radio.openReadingPipe(0, address);
 radio.setPALevel(RF24_PA_MIN);
 radio.setAutoAck(false);
 radio.startListening();

}


void loop() {


 radio.read(&data, sizeof(data));
 secondsTens = data.digit2;
 secondsOnes = data.digit1;
 Serial.print(secondsTens);
 Serial.println(secondsOnes);
 delay(1000);
 
}

well TX serial window gives correct 30 to 0 countdown while RX serial window printing 245245 continuously …pls help

thank you

To make it easy for people to help you please modify your post and use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor. See How to use the Forum

Take the delay() out of the RX code. Just print data when a new value arrives.

Have a look at this Simple nRF24L01+ Tutorial.

...R

thank you i did not know that... and i tried with out delay it shows 245245 as value continuously in rx side serial monitor... i cant understand how that number loops when tx side serial monitor correcly countdown from 30 to 0 ...

uthsuka:
i cant understand how that number loops when tx side serial monitor correcly countdown from 30 to 0 ...

There is a function radio.available() that you should (have) use(d).
If it returns true, there is a packet that can be read.
Just reading a non existant packet returns junk.