Trying to parse more than 3 variables using NRF2401 isn't working for me

Trying to parse more than 3 variables using NRF2401 isn’t working for me. I’ve tried everything I know
of (which isn’t that much as I’m still noob)

Wiring setup as below (two nanos)

Works with 3 variables (after a short delay)

Output when trying to use 4 variables

As you can see the variables get switched around and sometimes just don’t work.

For testing purposes I commented out the 3rd variable being sent and could see the 4th variable successfully. Ie feels like I can send a max of 3 variables at once. I need to send about 7 in total.

This is barebones as I can go code wise so I am trying to figure out where the issue lies.

Any help is greatly appreciated :slight_smile:

Transmitter code

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

RF24 radio(7, 8); // CE, CSN        
 
const byte address[6] = "00001";     //Byte of array representing the address. This is the address where we will send the data. This should be same on the receiving side.

void setup() 
{
      Serial.begin(9600);
      radio.begin();                  //Starting the Wireless communication
      radio.openWritingPipe(address); //Setting the address where we will send the data
      radio.setPALevel(RF24_PA_MIN);  //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
      radio.stopListening();          //This sets the module as transmitter
}

void loop()
{


// Variables
const char line1[32] = "Smile";
const char line2[32] = "if you";
const char line3[32] = "like";
const char line4[32] = "Candy!!!";



radio.write(&line1, sizeof(line1));                  //Sending the message to receiver
radio.write(&line2, sizeof(line2));
radio.write(&line3, sizeof(line3));
radio.write(&line4, sizeof(line4));

        Serial.print("1 = ");
        Serial.println(line1);
        Serial.print("2 = ");
        Serial.println(line2);
        Serial.print("3 = ");
        Serial.println(line3);
        Serial.print("4 = ");
        Serial.println(line4);

delay(1000);



}

Receiver code

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

RF24 radio(7, 8); // CE, CSN

const byte address[6] = "00001";


void setup() 
{

Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);   //Setting the address at which we will receive the data
radio.setPALevel(RF24_PA_MIN);       //You can set this as minimum or maximum depending on the distance between the transmitter and receiver.
radio.startListening();              //This sets the module as receiver
}

void loop()
{
  delay(20);
  if (radio.available())              //Looking for the data.

      {

      // Variable placeholders
        char line1[32] = "";                 //Saving the incoming data
        char line2[32] = "";
        char line3[32] = "";
        char line4[32] = "";
        
        // read variables from sender
        radio.read(&line1, sizeof(line1));              
        radio.read(&line2, sizeof(line2));
        radio.read(&line3, sizeof(line3));
        radio.read(&line4, sizeof(line4));

        
        // print to monitor
        Serial.print("1 = ");
        Serial.println(line1);
        Serial.print("2 = ");
        Serial.println(line2);
        Serial.print("3 = ");
        Serial.println(line3);
        Serial.print("4 = ");
        Serial.println(line4);
        
        
        delay(1000);
 
      }

}

You have not break between each of those variables. (linefeed, colon, etc.) so you are receiving them at different times. Serial communication is waaaaaaaaay slower than your MCU.

Thank you. Still newb. Would you mind showing me an example line to get variables all at the same time?

Look at the Serial Input Basics tutorial by Robin2. It is an excellent guide for good, reliable serial communication

blh64: Look at the Serial Input Basics tutorial by Robin2. It is an excellent guide for good, reliable serial communication

I think you did not notice that the problem is communication with NRF24L01+s, not serial.

OP:

Using 32 byte long data could be done by transmitting the packets on four different pipes, otherwise you have no means to map received packets to target variables.

I would use 30 byte data fields, one byte running counter, one byte target designator. That scheme would work on one pipe.

BTW checking for the existance of one packet does not guarantee four. Even if you wait you can get at most three, as that is the buffer size (fifo depth) for packets.

Thank you :)

Sadly I didn't understand anyt of that. The good news however is I got it to work using sprintf.

Appreciate the help.