nRF24l01 Not receive data

Hello friends,

I have stuck with my code and i need you're lights please, i have been crazy with that code and i don't know where i lost ... :~

I use the bellow code for Transmit

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

unsigned long Power = 0x20DF10EF;
unsigned long ProUP = 0x20DF00FF;

RF24 radio(9, 10);
uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(){
  Serial.begin(9600);
  radio.begin();

  radio.setPALevel(RF24_PA_HIGH);  // Get Max signal 0dbm (-18dbm is min)
  radio.setDataRate(RF24_250KBPS); // Lower baud high dist. only on nRF24l01+

  radio.setChannel(70);     // Set the Channel (between 0 to 127)
  radio.setRetries(15,15);   // Set max retries and delay time on retries 15 max
  radio.enableDynamicPayloads();

  radio.openWritingPipe(pipe);
}
void loop()

{
	bool ok =radio.write(&Power, sizeof(Power));
	Serial.print("Power code transmitter: ");
	Serial.println(Power);
	if (ok) Serial.println("Tx Suxxess.");
	delay(3000);

	radio.write(&ProUP, sizeof(ProUP));
	Serial.print("Prog. Up code transmitter: ");
	Serial.println(ProUP);
	delay(3000);
}

And the bellow code for receive

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

#include <IRremote.h>

IRsend irsend;

unsigned long IR_Send;

RF24 radio(9,10);
uint64_t pipe = 0xE8E8F0F0E1LL;

void setup()
{
  Serial.begin(9600);
  radio.begin();

  radio.setPALevel(RF24_PA_HIGH);  // Get Max signal 0dbm (-18dbm is min)
  radio.setDataRate(RF24_250KBPS); // Lower baud high dist. only on nRF24l01+

  radio.setChannel(70);     // Set the Channel (between 0 to 127)
  radio.setRetries(15,15);   // Set max retries and delay time on retries 15 max
  //radio.setPayloadSize(32);
  radio.enableDynamicPayloads();

  radio.openReadingPipe(1,pipe);
  radio.startListening();
  irsend.sendNEC(0x20DF00FF,32);  // For test only
}
void loop()
{
	IR_Send=0;
	If(radio.available()){
		radio.read(&IR_Send, radio.getDynamicPayloadSize());
		irsend.sendNEC(IR_Send,32);
  	  	Serial.print("I Sent to TV: ");
  	  	Serial.println(IR_Send);
	}
}

The problem is: I don't receive anything at all ( this code

Serial.print("I Sent to TV: ");
  	  	Serial.println(IR_Send);

never show in serial monitor.

PS. I have change other channel number with no success ..

The modules are ok because i use this example here Sending structs with nRF24L01 modules and the RF24 library - Bajdi electronics and this it is working.

Can someone please help me.

Thank you in advance

Best Regards,
Tasos

The code looks ok, but I've almost always had problems with the radio modules when trying to only use 1 pipe/address.

The example uses two as well:

  const uint64_t pipes[2] = {   0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1,pipes[1]);

 OR for the other radio:

   radio.openWritingPipe(pipes[1]);
  radio.openReadingPipe(1,pipes[0]);

That may work better if the modules test ok.

Hello Dear TMRh20,

Thank you very much for the reply ! ! !

You are correct :slight_smile: i change the code with the two pipes on both (tx,rx) and some times works some others not, so i start thing maybe something going wrong with the hardware. I use two arduino pro mini and this boards doesn't have a 3.3v regulator so for to get quickly the 3.3v from 5v i use 3 x 1N4148 to go bellow from 3.6v ( this get with 2 x 1N4148) because i read in datasheet you must use 3.3v if the spi lines are connected to 5v. Now the power to the boards i get it from the usb programmer and it looks like the RX need more power from the power can get it from the usb programmer and i said this because when i use external 5v power supply the boards works perfect. :slight_smile: I share my experience in case some one has the same problem to fix it quickly and not spend time to find what's going on .... At the end i will replace the 1N4148 with the regulator when i will come :wink:

I would like to ask you.

For the TX i use

radio.openWritingPipe(pipes[1]);
	radio.openReadingPipe(1, pipes[0]);

for the RX i use

radio.openWritingPipe(pipes[0]);
	radio.openReadingPipe(1, pipes[1]);

This is the correct way or i can do:

TX

radio.openWritingPipe(pipes[0]);
	radio.openReadingPipe(1, pipes[1]);

and Rx

radio.openWritingPipe(pipes[1]);
	radio.openReadingPipe(1, pipes[0]);

I discover that you have make a very nice and power library for Audio with this modules ! ! ! Well Done ! ! !

I want to get some time to play :wink:

And i thing you have make you're own rf24 library ... write ? i will do a better read :slight_smile:

and a last question please, it is possible to use irremote library at the rx to get raw command for use this as an example irsend.sendRaw(raw,68,38);
I am asking this because the max payload size it is 32 and in the above example the raw size it is 68, i think i can use the command in Tx like

memcpy(output,&raw[0],32);
radio.write(&output, sizeof(output));
// Delay ?
memcpy(output,&raw[32],64);
radio.write(&output, sizeof(output));
// Delay ?
memcpy(output,&raw[64],4);
radio.write(&output, 4);

if the above it is correct how can i collect the data in Rx side ?

if (radio.available()){
		bool done = false;
		while (!done){ 
			done = radio.read(&raw,sizeof(raw)); // this will get all in once ? How can i synchronize ?
			
		}
	}

Thank you in advance.

Well the pipes vs addressing thing is a bit confusing, so I like to look at it like this:

  const uint64_t addresses[2] = {   0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
  radio.openWritingPipe(addresses[0]);
  radio.openReadingPipe(1,addresses[1]);

Then, to answer your question, yes. As long as the transmitter and receiver are using opposite addresses, it should work fine. The pipe numbers aren't always that important, mainly the addresses.

And i thing you have make you're own rf24 library ... write ? i will do a better read smiley

Yup, I've created a faster/more efficient fork of the RF24/RF24Network libs that support a wider range of hardware and functionality, mainly to improve my audio library and its capabilities.

if the above it is correct how can i collect the data in Rx side ?

The memcpy looks ok, except the second one should use length 32 instead of 64. In this case you will probably want to use some sort of simple protocol to manage the payloads and re-assembly.

For example, the transmitter could number the payloads by modifying the first or last byte of the payload, so the receiver knows if it has received all of the payloads in the correct sequence. Or you could send a 'start payload' telling the receiver to expect three payloads within a certain timeframe, and indicate that they will need to be re-assembled. I've included an example of the latter method in my library fork: http://tmrh20.github.io/RF24/TransferTimeouts_8ino-example.html , but the write method needs to be changed to work with any of the other libs. *Edit to add: It might be easiest to also spread out the data being sent so all the payloads are the same size. Otherwise that needs to be accounted for on the receiving end.

Then on the receiving end, its just a matter of confirming successful transfer, then reversing the operation, and writing the payload data into a 68 byte array, which you could do by reversing your memcpy code, or with a for loop.

Hello Dear TMRh20,

Thank you very much for you're help and you're time ! ! !

The pipes has confusing me too but from the time it is working for now it is ok i will try later when i get more free time to read and play until understand well.

I see you' re library and yes you are a Genius ! ! ! You make it much better ! ! ! Well Done ! ! ! I have install it and this i will use it :slight_smile:

Because the array it will not fixed i should be make it to calculate automatically, so i try to make a code only for this for to test and be sure this piece of code working well before i try to add and the command for the nRF24L01 library.

So far after few hour's i do the follow:

unsigned int Raw[] = {4600,4450,650,1600,650,1600,650,1600,650,500,600,500,650,500,650,500,600,500,650,1600,650,1600,650,1600,650,500,650,450,650,500,650,500,600,500,650,500,600,1650,600,500,650,500,600,500,650,500,600,500,650,500,650,1600,650,500,600,1650,600,1650,600,1650,650,1600,650,1600,650,1600,650};
unsigned int output[31]; // For the payload of nRF24L01 array 30 + 1 for null termination
int Rawsize = sizeof(Raw)/sizeof(unsigned int); // Get the raw size of the array

void setup()
{
	Serial.begin(57600);
	Serial.println("Starting");
	Serial.print("Size of array: ");
	Serial.println(Rawsize);     // Show me the size of the array
	Serial.println(Rawsize/30);  // Show me how many times i will do the loop
	Serial.println();

}

void loop()
{
	byte q = 0; // Counter for print the Raw code to compare the output
	for (byte i = 0; i <= Rawsize/30; i++){  // Do a loop for send 30 byte until complete the full array
		Serial.print("Count i = ");
		Serial.println(i);

		if (i == Rawsize/30){  // is the last number ? check if it is full
			byte RemainSize = Rawsize - (Rawsize/30) * 30; // calculate the remaing array ...
			memcpy(output,&Raw[i*30],RemainSize * 2); //62 fill 0 to 30 ? and 30 fill 0 to 15 ?

			// debug only for check in serial monitor if i get the correct data
			for (byte x = 0;x < RemainSize; x++){
				Serial.print("Count x: ");
				Serial.print(x);
				Serial.print(" Data: ");
				Serial.print(output[x]);
				Serial.print(" Raw data: ");
				Serial.println(Raw[q]);
				q++;
			}

		}else{
			memcpy(output,&Raw[i*30],62); //62 fill 0 to 30 ? and 30 fill 0 to 15 ?

			// debug only for check in serial monitor if i get the correct data
			for (byte x = 0;x < 30; x++){
				Serial.print("Count x: ");
				Serial.print(x);
				Serial.print(" Data: ");
				Serial.print(output[x]);
				Serial.print(" Raw data: ");
				Serial.println(Raw[q]);
				q++;
			}

		}
		// radio.write(&output,sizeof(output)); // It send 30 bytes array each time
		delay(100); // it is ok this delay ? or i can make it less ?
	}
}

and the result from the serial monitor i got it is :

Starting
Size of array: 67
2

Count i = 0
Count x: 0 Data: 4600 Raw data: 4600
Count x: 1 Data: 4450 Raw data: 4450
Count x: 2 Data: 650 Raw data: 650
Count x: 3 Data: 1600 Raw data: 1600
Count x: 4 Data: 650 Raw data: 650
Count x: 5 Data: 1600 Raw data: 1600
Count x: 6 Data: 650 Raw data: 650
Count x: 7 Data: 1600 Raw data: 1600
Count x: 8 Data: 650 Raw data: 650
Count x: 9 Data: 500 Raw data: 500
Count x: 10 Data: 600 Raw data: 600
Count x: 11 Data: 500 Raw data: 500
Count x: 12 Data: 650 Raw data: 650
Count x: 13 Data: 500 Raw data: 500
Count x: 14 Data: 650 Raw data: 650
Count x: 15 Data: 500 Raw data: 500
Count x: 16 Data: 600 Raw data: 600
Count x: 17 Data: 500 Raw data: 500
Count x: 18 Data: 650 Raw data: 650
Count x: 19 Data: 1600 Raw data: 1600
Count x: 20 Data: 650 Raw data: 650
Count x: 21 Data: 1600 Raw data: 1600
Count x: 22 Data: 650 Raw data: 650
Count x: 23 Data: 1600 Raw data: 1600
Count x: 24 Data: 650 Raw data: 650
Count x: 25 Data: 500 Raw data: 500
Count x: 26 Data: 650 Raw data: 650
Count x: 27 Data: 450 Raw data: 450
Count x: 28 Data: 650 Raw data: 650
Count x: 29 Data: 500 Raw data: 500
Count i = 1
Count x: 0 Data: 650 Raw data: 650
Count x: 1 Data: 500 Raw data: 500
Count x: 2 Data: 600 Raw data: 600
Count x: 3 Data: 500 Raw data: 500
Count x: 4 Data: 650 Raw data: 650
Count x: 5 Data: 500 Raw data: 500
Count x: 6 Data: 600 Raw data: 600
Count x: 7 Data: 1650 Raw data: 1650
Count x: 8 Data: 600 Raw data: 600
Count x: 9 Data: 500 Raw data: 500
Count x: 10 Data: 650 Raw data: 650
Count x: 11 Data: 500 Raw data: 500
Count x: 12 Data: 600 Raw data: 600
Count x: 13 Data: 500 Raw data: 500
Count x: 14 Data: 650 Raw data: 650
Count x: 15 Data: 500 Raw data: 500
Count x: 16 Data: 600 Raw data: 600
Count x: 17 Data: 500 Raw data: 500
Count x: 18 Data: 650 Raw data: 650
Count x: 19 Data: 500 Raw data: 500
Count x: 20 Data: 650 Raw data: 650
Count x: 21 Data: 1600 Raw data: 1600
Count x: 22 Data: 650 Raw data: 650
Count x: 23 Data: 500 Raw data: 500
Count x: 24 Data: 600 Raw data: 600
Count x: 25 Data: 1650 Raw data: 1650
Count x: 26 Data: 600 Raw data: 600
Count x: 27 Data: 1650 Raw data: 1650
Count x: 28 Data: 600 Raw data: 600
Count x: 29 Data: 1650 Raw data: 1650
Count i = 2
Count x: 0 Data: 650 Raw data: 650
Count x: 1 Data: 1600 Raw data: 1600
Count x: 2 Data: 650 Raw data: 650
Count x: 3 Data: 1600 Raw data: 1600
Count x: 4 Data: 650 Raw data: 650
Count x: 5 Data: 1600 Raw data: 1600
Count x: 6 Data: 650 Raw data: 650

It looks done what i need to do.

Really confusing me this piece of code memcpy(output,&Raw[i*30],62);

62 means, copy 62 bytes (if exist all) from the raw to output ? at the begin i use 30 but it was copy only the first 15 with the real code the other was filling with 0 when i do it 62 then i got the 30 bytes in output with correct data.

I left 2 bytes, the first one i was thinking to use as a start byte and the other as and byte, but i was thinking something like
S1 for first 32 bytes and E1 for the end of the 32 bytes
S2 for second 32 bytes and E2 for the end of 32 bytes

or for example i must send two inform from S2 and then check the sequence from E1 , E2
S2 for first 32 bytes and E1 for the end of the 32 bytes
S2 for second 32 bytes and E2 for the end of 32 bytes

If this it is fine how i can make output[0] = S2 ? Can i ?

Thank you in Advance.

Best Regards,
Tasos

Ok, a couple of confusing things here. First, I didn't realize it was an array of integers, so that changes everything.

There are 2 bytes in every integer, so your array would actually be 68*2 bytes ( 136 bytes long), which will require 5 payloads just for the data in one array.

unsigned int Raw[] = {4600,4450,650,1600,650,1600,650,1600,650,500,600,500,650,500,650,500,600,500,650,1600,650,1600,650,1600,650,500,650,450,650,500,650,500,600,500,650,500,600,1650,600,500,650,500,600,500,650,500,600,500,650,500,650,1600,650,500,600,1650,600,1650,600,1650,650,1600,650,1600,650,1600,650};
unsigned int output[16]; // For the payload of nRF24L01 array 30 + 1 for null termination

void setup() {
  Serial.begin(115200);
  //for(int i=0; i< 68; i++){
  //  Raw[i] = i; 
  //}
 
}

void loop() {
  
  memcpy(&output[1],&Raw,30);      // Copies 30 bytes or 15 integers
  output[0] = 1;                                         // Sets the first integer (2 bytes) to equal 1
  for(int i=0; i<16; i++){
    Serial.println(output[i]); // Print out the 15 integers + 1 start integer
  }
  memcpy(&output[1],&Raw[15],30);
  output[0] = 2;
  for(int i=0; i<16; i++){
    Serial.println(output[i]);
  }
  memcpy(&output[1],&Raw[30],30);
  output[0] = 3;
  for(int i=0; i<16; i++){
    Serial.println(output[i]);
  }
  memcpy(&output[1],&Raw[45],30);
  output[0] = 4;
  for(int i=0; i<16; i++){
    Serial.println(output[i]);
  }
  memcpy(&output[1],&Raw[60],14);   *Edit: Should be 14 not 16
  output[0] = 5;
  for(int i=0; i<8; i++){
    Serial.println(output[i]);
  }

  Serial.println("********");
  delay(2000);
  
}

The code I posted above shows how to insert the start integer, and ensure that every byte is accounted for. It will actually take 5 transmissions to send all of the data.

When sending, you would still do radio.write(&output,sizeof(output));

Also, your array is 67 integers or 134 bytes long.

Hello Dear TMRh20,

You are a star ! ! !

Thank you very much for you're time and help and you're explain of the code ! ! !

Now it is clear to me :slight_smile:

Thank you very very much ! ! ! :slight_smile:

Have a nice time and good programming my friend ! ! ! :slight_smile:

Best Regards,
Tasos