Getting a NRF24L01 to write and read an array?

Hi, I recently got my arduinos working with a very simple rf sender and transmitter, but decided to upgrade to a pair of NRF24L01's, and the programming seems simple enough, but am I missing something?

I have set my transmitter up like this:

int inputs[4];
RF24 radio(7, 8);
const byte address[6] = "00001";

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

}

void loop() {

/*various stuff for getting inputs*/

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

 for (byte i = 0; i < 4; i++) 
 {
      Serial.println(inputs[i]);
      
 }
 Serial.println("----");
 delay(2000);


}

The serial monitor displays it's getting and storing my inputs the way I expect, but have I sent the data the correct way?

This is my receiver:

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

int inputs[4];

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

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

void loop()
{
    radio.read(&inputs, sizeof(inputs));
    if (radio.available()) 
    {
      for (byte i = 0; i < 4; i++)
      {
        Serial.println(inputs[i]);
      }
      Serial.println("----");
    }  
}

It finds the radio signal, but all the values in the array stay at 0 instead of mirroring the output of the transmitter, any ideas? It's definitely picking up the signal of the transmitter, but I seem to have made a mistake in actually transferring the data.

Try using the code in @Robin2's Tutorial.

Yes, they are to an extent.

The primary difference between the 2 is that the version without + has only1Mbps and 2Mbps on-air data-rate, while the + version can also do 250Kbps.

void loop()
{
    radio.read(&inputs, sizeof(inputs));
    if (radio.available())

Why are you reading data before testing whether any is available ?

Romonaga:
Yes, they are to an extent.

Sorry, didn't mean to make you reply to nothing, thanks for the info! For my purposes they are interchangeable then.

UKHeliBob:

void loop()

{
    radio.read(&inputs, sizeof(inputs));
    if (radio.available())



Why are you reading data before testing whether any is available ?

Oh wow, I didn't realize that would make a difference!

I was just thinking I'd read any data available, then see what it came up with, and just avoid displaying anything if it didn't find anything. But now that I put it the other way around, it's working. I guess the timing was just off, so that there wasn't any info available, but then the condition triggers and displays the empty variables, just afterwards.

It's working now, just after switching it around. Thanks!

Graylord:
Oh wow, I didn't realize that would make a difference!

? ? ?

That would be like reading a letter before you checked if the postman had called :slight_smile:

...R

I was thinking it would be more like continuously checking the mailbox, whether or not the mail had arrived, but that it should display something once it does.