NRF24 not working

I simply try to send a sensor info from an Arduino Nano to another one, both with NRF24’s. They used to work but when i updated the maniacbug’s RF24 library version from 1.0.1 to 1.1.3, it is now not working, even i try with the old library version.
I stripped the problem to the GettingStarted.cpp example packed in the library. Still doesn’t work! I tried it with different Arduino Nanos, different NRF24’s even with different cables. :slight_smile:

Arduino IDE version is 1.6.7
Here is the code:
The only difference between sender and receiver is: radioNumber is either 0 or 1.

/*

  • Getting Started example sketch for nRF24L01+ radios
  • This is a very basic example of how to send data from one node to another
  • Updated: Dec 2014 by TMRh20
    */

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

/****************** User Config ************************/
/
Set this radio as radio number 0 or 1 ***/
bool radioNumber = 1;

/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 /
RF24 radio(7,8);
/
*********************************************************/

byte addresses[6] = {“1Node”,“2Node”};

// Used to control whether this node is sending or receiving
bool role = 0;

void setup() {
Serial.begin(115200);
Serial.println(F(“RF24/examples/GettingStarted”));
Serial.println(F("*** PRESS ‘T’ to begin transmitting to the other node"));

radio.begin();

// Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
radio.setPALevel(RF24_PA_LOW);

// Open a writing and reading pipe on each radio, with opposite addresses
if(radioNumber){
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1,addresses[0]);
}else{
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
}

// Start the radio listening for data
radio.startListening();
}

void loop() {

/****************** Ping Out Role ***************************/
if (role == 1) {

radio.stopListening(); // First, stop listening so we can talk.

Serial.println(F(“Now sending”));

unsigned long time = micros(); // Take the time, and send it. This will block until complete
if (!radio.write( &time, sizeof(unsigned long) )){
Serial.println(F(“failed”));
}

radio.startListening(); // Now, continue listening

unsigned long started_waiting_at = micros(); // Set up a timeout period, get the current microseconds
boolean timeout = false; // Set up a variable to indicate if a response was received or not

while ( ! radio.available() ){ // While nothing is received
if (micros() - started_waiting_at > 200000 ){ // If waited longer than 200ms, indicate timeout and exit while loop
timeout = true;
break;
}
}

if ( timeout ){ // Describe the results
Serial.println(F(“Failed, response timed out.”));
}else{
unsigned long got_time; // Grab the response, compare, and send to debugging spew
radio.read( &got_time, sizeof(unsigned long) );
unsigned long time = micros();

// Spew it
Serial.print(F(“Sent “));
Serial.print(time);
Serial.print(F(”, Got response “));
Serial.print(got_time);
Serial.print(F(”, Round-trip delay “));
Serial.print(time-got_time);
Serial.println(F(” microseconds”));
}

// Try again 1s later
delay(1000);
}

/****************** Pong Back Role ***************************/

if ( role == 0 )
{
unsigned long got_time;

if( radio.available()){
// Variable for the received timestamp
while (radio.available()) { // While there is data ready
radio.read( &got_time, sizeof(unsigned long) ); // Get the payload
}

radio.stopListening(); // First, stop listening so we can talk
radio.write( &got_time, sizeof(unsigned long) ); // Send the final one back.
radio.startListening(); // Now, resume listening so we catch the next packets.
Serial.print(F("Sent response "));
Serial.println(got_time);
}
}

/****************** Change Roles via Serial Commands ***************************/

if ( Serial.available() )
{
char c = toupper(Serial.read());
if ( c == ‘T’ && role == 0 ){
Serial.println(F("*** CHANGING TO TRANSMIT ROLE – PRESS ‘R’ TO SWITCH BACK"));
role = 1; // Become the primary transmitter (ping out)

}else
if ( c == ‘R’ && role == 1 ){
Serial.println(F("*** CHANGING TO RECEIVE ROLE – PRESS ‘T’ TO SWITCH BACK"));
role = 0; // Become the primary receiver (pong back)
radio.startListening();

}
}

} // Loop

Below is the outputs:

Sender----

RF24/examples/GettingStarted
*** PRESS ‘T’ to begin transmitting to the other node
*** CHANGING TO TRANSMIT ROLE – PRESS ‘R’ TO SWITCH BACK
Now sending
Failed, response timed out.
Now sending

Receiver----

RF24/examples/GettingStarted
*** PRESS ‘T’ to begin transmitting to the other node
*** CHANGING TO TRANSMIT ROLE – PRESS ‘R’ TO SWITCH BACK
Now sending
failed
Failed, response timed out.
*** CHANGING TO RECEIVE ROLE – PRESS ‘T’ TO SWITCH BACK

THANK YOU!! :slight_smile:

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

I got my nRF24s working with this Tutorial

If you use the writeAckPayload() function you can get data as part of the acknowledgement without needing to change between listening and talking.

…R

The tmrh20 library is current.

https://github.com/TMRh20/RF24

I have used it recently.

I got two Arduino UNOs and two NRF24L01s, and used following codes for transmit and receive…It worked like a charm.

Now when I open the file again, the “transmit file” is still working, but I got error message on “receiving” side
does anyone know why and how to fix it?

Transmit code:

#include <SPI.h>
  
#include <nRF24L01.h>
   
#include <RF24.h>
 
   
RF24 radio (7, 8);
   


const byte rxAddr [6] = "00001";

//create the object radio(nRF24L01)


float data [0];

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

 radio.setRetries(15, 15);
 radio.openWritingPipe(rxAddr[1]);
 radio.stopListening();
 }

void loop() 
 {
  
  data[0]=analogRead(A0)*(5.0/1023.0);;
  
  bool ok=radio.write(data, sizeof(data));;

 if(ok)
   {
     Serial.println ("Data sent:");
     Serial.println (data [0]);
     
   }
 else 
   {
   Serial.println ("It failed to send");
   }
   delay (1000);
 }

Receving code:

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

   
RF24 radio (7, 8);
   

const byte rxAddr [6] = "00001";

//create the object radio(nRF24L01)


float data [3];

void setup() 
 {
   while (!Serial);

 Serial.begin(9600);
 radio.begin();

 radio.openReadingPipe(1, rxAddr);
 radio.startListening();
 }

void loop() 
 {
  
  

 if(radio.available())
   {
     radio.read (&data, sizeof(data));
     Serial.println(data[0]);
     
   }
else
   {
   Serial.println ("Error");
   }
   delay (1000);
 }

You clearly failed to read the earlier posts in this Thread. Please do so.

...R

by the way, I tested the program for “hello world” and it works just fine. The difference between this one and the one I uploaded earlier is text vs. data. So, it means the setup and hardware are working, only error in the source code, I guess?

Please advise

Here is my “Hello World!” code:

Transmit:

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


RF24 radio(7, 8);

const byte rxAddr[6] = "00001";

void setup()
{
 radio.begin();
 radio.setRetries(15, 15);
 radio.openWritingPipe(rxAddr[1]);
 
 radio.stopListening();
}

void loop()
{
 const char text[] = " Hello World!";
 radio.write(&text, sizeof(text));
 
 
 delay(1000);
}

Receiver:

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

RF24 radio(7, 8);

const byte rxAddr[6] = "00001";

void setup()
{
 while (!Serial);
 Serial.begin(9600);
 
 radio.begin();
 radio.openReadingPipe(0, rxAddr);
 
 radio.startListening();
}

void loop()
{
 if (radio.available())
 {
   char text[32] = {0};
   radio.read(&text, sizeof(text));
   
   Serial.println(text);
 }
}

Try changing this

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

to

radio.read (data, sizeof(data));

...R

Hi Robin,

Thank you. But it is still sending "Error" msg. any other suggestions? L

Yes. Start with a copy of the working programs and change as little as possible to get them to send and receive the other data.

...R