a simple example of how to TX and RX char array maniacbug RF24 NRF24L01+ modules

Hi all

I have been battling for weeks now and have been through code examples like crazy as well as different libraries and forks.
I looked here : http://playground.arduino.cc/InterfacingWithHardware/Nrf2401 and the code was easy and simple enough to understand but it is specifically for a sparkfun module :frowning: and also doesn’t compile

There are so many examples and bits of code.
All I would like to do is send a char array (TX) to the other side (RX).

I have had success with the Radiohead libraries but would prefer to use the RF24 maniac bug library.

Could some kind soul please show me a very simple example of how to :
1.send a char array (eg callcode[18]) from one arduino and receive and load it into the same char buffer one the other arduino.
2.possibly have the receiver(RX) reply back that is received the data.

AND/OR possibly explain how to do it.

Thanks a million

Joe

This is about as simple as it gets:

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

// Your chosen radio CE,CS pins
RF24 radio(7,8);

uint64_t addresses[] = {0xABABABABABLL, 0xC3C3C3C3C3LL};

/****** Configure this for sender or receiver *****/
boolean sender = 0; // Change this from 0 to 1 to switch between sending or receiving sketch


void setup() {
  
  Serial.begin(57600);
  radio.begin(); 
  
  if(sender == 0){
    radio.openWritingPipe(addresses[1]);
    radio.openReadingPipe(1,addresses[0]);
    radio.startListening();
  }else{
    radio.openWritingPipe(addresses[0]);    //*Edit to correct address assignments
    radio.openReadingPipe(1,addresses[1]);
    radio.stopListening(); 
  }
  
}

char myArray[] = "This is not a test";

void loop() {
    
  if(sender == 0){
      if(radio.available()){
        char tmpArray[19];                                               // This generally should be the same size as the sending array
        radio.read(&tmpArray,sizeof(tmpArray));  // Reading 19 bytes of payload (18 characters + NULL character)
        Serial.println(tmpArray);                                   // Prints only the received characters because the array is NULL terminated
        
      }
    
  }else{
  
      bool ok = radio.write(&myArray,sizeof(myArray));
  
      if(ok){ Serial.println("Transfer OK");
      }else { Serial.println("Transfer Fail"); 
      }
      delay(1000);
  }

}

There is really no need for the receiver to reply manually, it does automatically, so the transmitter knows if the payload was received. The char array is NULL terminated, so it is easily printed at the receiver without knowing the length.

A more complicated example using dynamic payload sizes is shown at: http://tmrh20.github.io/RF24/pingpair_dyn_8ino-example.html .

Of course, if using the RF24 libs, I would also recommend using one of the current forks at GitHub - stanleyseow/RF24: Arduino and Raspberry Pi driver/libraries for nRF24L01 or https://github.com/tmrh20/RF24

Hey TMRh20

:-) Thank you a million times over :-)

The code example seems to work. And the reason why I say it seems to work is because as you have sent it , it runs a sum total of fine once the receiver which displays the output of "This is not a test". And on the TX is too also shows a "Transmit OK " once. the rest of the time it outputs "Transfer failed". And I think this may have been happening with my attempts too. So I added the following line to the end of the example you sent.

radio.powerDown();

Which seems to solve the issue. I also tried these but found the delays were too long and the TX would show transit fails every couple of lines.

 radio.powerDown();
       delay(100);
       radio.powerUp();

Do you know why your code would only have run once ? Is it because a buffer needs flushing ? And if so would you happen to know which one.

I am now trying to get this working on an ATTINY85 specifically with the RF24 library only Would you happen to have tried this too ? And if so can you offer me some tips or any other resources.

Thanks a million once again.YOU ROCK !

Joe

Hey, thanks! In my initial post, I made a mistake in the code, but basically the addresses should be opposite, so one device transmits to the others reading address and vice versa:

  if(sender == 0){
    radio.openWritingPipe(addresses[1]);
    radio.openReadingPipe(1,addresses[0]);
    radio.startListening();
  }else{
    radio.openWritingPipe(addresses[0]);    //*Edit to correct address assignments
    radio.openReadingPipe(1,addresses[1]);
    radio.stopListening(); 
  }

I think that should solve the issue, sorry about the mistake :~

Hey Tmrh20

Thanks again :-)

But what's the difference in the old and the new ? Am i missing something ?

Joe

The addressing assignments were initially incorrect. Both posts have been updated.

bump for clearness, why is both openWritingpipe and openReadingPipe needed on receiver and sender nodes? is the receiver always broadcasting back (ACK)?

thank you TMrh20 for your clear answer and for maintaining the best RF24 fork. https://github.com/tmrh20/RF24

sorry guys...I don't know how you did manage to make this s... work at all...

I have wasted 4 hours so far with this s... and I can even compile...

I'm getting 9 or 10 errors like:

C:\Users\CIL201~1\AppData\Local\Temp\build31dc99d22094ad0dfaf0d6a470e3f0f1.tmp\sketch\nrf24_rcv.ino.cpp.o: In function `setup':

C:\Program Files\Arduino\examples\12.nrf24_rcv\nrf24_rcv/nrf24_rcv.ino:22: undefined reference to `RF24::begin()'

C:\Program Files\Arduino\examples\12.nrf24_rcv\nrf24_rcv/nrf24_rcv.ino:23: undefined reference to `RF24::openReadingPipe(unsigned char, unsigned long long)'

guess some .cpp files are missing in libraries like rf24config.cpp and rf24.cpp....

I got my nRF24s working with this Tutorial

I suggest you use the TMRh20 version of the RF24 library - it solves some problems from the ManiacBug version

The pair of programs in this link may be useful.

…R