I keep receiving a value of 0 on my NRF24L01 ! help ! [SOLVED]

Hello,
I am trying to send a value of 12 from one arduino to the other using the nRF24L01 long range with the big antenna. So I made my connections and uploaded my sketches. At first i did not receive anything on the receiver side, so I rechecked my connection and here it was a wrong connected pin so I corrected it and I started getting value on my monitor on the receiver side. My problem is that I keep getting 0 and not 12 ! So I need your help please figuring out the problem ?

here is my transmitter sketch:

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

//1st byte is for throttle value from pot

int msgTX[2]; //Message to be transmitted, can contain up to 2 array elements, 2 bytes
int ackMessage[2]; //Acknowledgment message, means the message that will be received from the receiver or the car, 1 element for the moment

//Defining radio object for the RF24 function
RF24 radio(9, 10); // CE, CSN
//const byte address[6] = "00001";

//Defining the radio variables and values
const uint64_t pipe = 0xE8E8F0F0E1LL; //pipe address
const rf24_datarate_e dataRate = RF24_250KBPS; //Data rate defined in the documentations, RF24_250KBPS, RF24_1MBPS or RF24_2MBPS

//Throttle potentiometers
//const byte Throttle = A5;

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setDataRate(dataRate);
  //radio.openWritingPipe(address);
  radio.enableAckPayload(); //enables receiving data from receiver side
  //radio.setPALevel(RF24_PA_MIN); //Power Amplifier (PA) level to one of four levels RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
  //radio.stopListening();
  
}
void loop() {
 
  radio.openWritingPipe(pipe);
  msgTX[0] = 12;
  radio.write(msgTX, sizeof(msgTX)); //Sends the Data
  AcknowledgmentDATA();
  
}

//DATA Receiving from the Receiver part, Acknowledgment Data
void AcknowledgmentDATA(){
    
    while ( radio.isAckPayloadAvailable() ){
        //Serial.println("Ack Available");
        radio.read(ackMessage, sizeof(ackMessage));
        int value = ackMessage[1];

   }
  
}

and here is my receiver sketch:

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

int msgRX[2]; //Message to be transmitted, can contain up to 2 array elements, 2 bytes
int ackMessage[2]; //Acknowledgment message, means the message that will be received from the receiver or the car, 1 element for the moment

RF24 radio(9, 10); // CE, CSN

//const byte address[6] = "00001";

//Defining the radio variables and values
const uint64_t pipe = 0xE8E8F0F0E1LL; //pipe address
const rf24_datarate_e dataRate = RF24_250KBPS; //Data rate defined in the documentations, RF24_250KBPS, RF24_1MBPS or RF24_2MBPS

int Throttle;


void setup() {
  
  Serial.begin(9600);
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  //radio.openReadingPipe(0, address);
  radio.openReadingPipe(1, pipe);
  //radio.setPALevel(RF24_PA_MAX);//Power Amplifier (PA) level to one of four levels RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
  radio.enableAckPayload();
  radio.startListening();
  
}
void loop() {
  //ackMessage[1] = 200;
  //radio.writeAckPayload(1, ackMessage, sizeof(ackMessage));
 
  if (radio.available()) {
    radio.read(msgRX, sizeof(msgRX));
    Throttle = msgRX[0]; //middle throttle value is 121
    Serial.print("Throttle: ");
    Serial.println(Throttle);
  }
}

Are your units sitting on the same desk? The receivers can be overwhelmed by a transmitter that is too close.

aarg:
Are your units sitting on the same desk? The receivers can be overwhelmed by a transmitter that is too close.

yes they are on the same desk because both arduino are connected to my laptop, I never had that problem before even if close but this time I can not seem to figure what might be the problem that I keep receiving 0 on the receiver side

Can you disconnect one or both of the antennas?

aarg:
Can you disconnect one or both of the antennas?

ok done, i disconnected both, I kept getting 0, then i tried keeping one of them but still getting 0. I also tested with my multimeter the voltage of each and both are around 3.V

How do you explain the commented out lines? Don't you actually need this one?

  //radio.openWritingPipe(address);

aarg:
How do you explain the commented out lines? Don't you actually need this one?

  //radio.openWritingPipe(address);

No because pipe is the address that one was from an old sketch but I kept it did not delete anything

firashelou:
No because pipe is the address that one was from an old sketch but I kept it did not delete anything

I'm confused. Are you saying that the sketch you posted is different than the one you are talking about?

aarg:
I'm confused. Are you saying that the sketch you posted is different than the one you are talking about?

it is the same i am using ! except all commented should be ignored
I used this sketch before when I build it a year ago and it worked perfectly at the time but now it is not, so i need help to see if maybe by mistake i deleted something

Sure, so don't you need to open a pipe for the transmit?

aarg:
Sure, so don't you need to open a pipe for the transmit?

for the receiver i did open radio.openReadingPipe(1, pipe);

and for the controller I opened writing pipe with radio.openWritingPipe(pipe);

It seemed that my connections were swiped on the receiver side, but i wasn't seeing it at all :confused:
so I kept reading my notebook about connections and checking again until I found that I have 2 white wires which I wasn't clearly seeing them so I adjusted them and here it goes it works ! So this post will be as a reference for future projects.

Thanks everyone for the help :slight_smile:

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

There is also a connection test program to check that the Arduino can talk to the nRF24 it is connected to. If the first example does not work be sure to try the connection test for both of your Arduinos. Nothing will work if the connection test fails.

A common problem with nRF24 modules is insufficient 3.3v current from the Arduino 3.3v pin. This seems to be a particular problem with the nano. The high-power nRF24s (with the external antenna) will definitely need an external power supply. At least for testing try powering the nRF24 with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.

If you are using the high-power nRF24s (with the external antenna) it may help to have a distance of about 3 metres between the two nRF24s so that the signal does not overwhelm the receiver. However someone on the Forum has had them working without that separation - I don't have any personal experience with them. If you are new to nRF24s it may be better to start with a pair of low power modules with the pcb antenna.

...R

Robin2:
Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

There is also a connection test program to check that the Arduino can talk to the nRF24 it is connected to. If the first example does not work be sure to try the connection test for both of your Arduinos. Nothing will work if the connection test fails.

A common problem with nRF24 modules is insufficient 3.3v current from the Arduino 3.3v pin. This seems to be a particular problem with the nano. The high-power nRF24s (with the external antenna) will definitely need an external power supply. At least for testing try powering the nRF24 with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.

If you are using the high-power nRF24s (with the external antenna) it may help to have a distance of about 3 metres between the two nRF24s so that the signal does not overwhelm the receiver. However someone on the Forum has had them working without that separation - I don't have any personal experience with them. If you are new to nRF24s it may be better to start with a pair of low power modules with the pcb antenna.

...R

thanks Robin, yea that is what i did, i worked with it alone with a potentiometer and then added it to the full circuit

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