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 ![]()
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);
}
}