Starting two nRF24L01+ at the same time = no connection?

Hello everyone,

In my project I am using two nRF24L01+ to send and receive the status of a pin and light up a led in accordance to the message it received from the other RF module.

My problem is, whenever I start both the Arduinos at the same time, there is no connection between them but if I reset one or open the serial port on one Arduino they connect.

I'm wondering what could be causing this and how to fix this. Any ideas? Thanks!

Setup Code:

void setup(void){
  Serial.begin(9600);
  radio.begin(); 
  radio.setDataRate(RF24_250KBPS);
}

Post the entire code of both arduinos.

Alright, I attached the code that runs on both Arduinos.
I apologize in advanced if its messy and hard to read, I am new to Arduino :stuck_out_tongue:

 /*   - Pin 9 - CE
     - Pin 10 - CS(N)
     - Pin 11 - MOSI
     - Pin 12 - MISO
     - Pin 13 - SCK
     On the Receiver:
     - Pin 3 - LED
     On the Transmitter:
     - Pin 7 - Button */

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

RF24 radio(9,10);

const uint64_t pipe = 0xE8E8F0F0E1LL;
int rxData[1]; // stores the data in 
int dataPin = 7;
int modePin = 6;
int ledPin = 3;
 
int lastStatus = -1;

void setup(void){
  Serial.begin(9600);
  radio.begin(); 
  radio.setDataRate(RF24_250KBPS);
  // optionally, increase the delay between retries & # of retries
  //radio.setRetries(15,15);
  // optionally, reduce the payload size.  seems to
  // improve reliability
  //radio.setPayloadSize(8);
  pinMode(dataPin, INPUT_PULLUP);
  pinMode(modePin, INPUT_PULLUP);
  
}
 
void loop(void){
  boolean pinStatus = digitalRead(dataPin);
  
  if(pinStatus == HIGH){ // if pin 7 is HIGH (not plugged into anything) , led should light up. Vice versa if the pin is LOW
    master(111); 
    //Serial.print("led should light up");
  } // set it so the default is off
  if(pinStatus == LOW){
    master(0);}  
}

void master(int data_to_send){  
 if(lastStatus == -1 || lastStatus == 1){
    delay(100);
    radio.openReadingPipe(1,pipe);
    delay(100);
    radio.startListening();
    delay(100);
    lastStatus = 0;   
  }
 
 unsigned long started_waiting_at = millis();
 boolean timeout = false;
 
 unsigned long transmit_timer;
 boolean transmitter_timeout = false;
 
 boolean readStat;
 
 while(timeout == false){
   while(! radio.available() && !timeout){
     if(millis() - started_waiting_at > 800){
       timeout = true;    
     }
     if(!timeout){
       delay(150);
       readStat = radio.read(rxData, 1);
       delay(150);
       if(readStat == true){ // could not receive data
         writeLED(-1); // sends -1 when radio connection did not work
       }   
       if(readStat == false){ // only sends data if it is confirmed from receiver
         writeLED(rxData[0]);
         lastStatus = 0; // just finished with transmitter mode    
         timeout = true;    
       }
       //Serial.print("first attempt recived Data. Data in: ");Serial.println(rxData[0]); // rx data here is old
     }

   }
   if(readStat == false){
     lastStatus = 0; // just finished with transmitter mode    
     timeout = true;
     break;
   }  
 if(millis() - started_waiting_at > 400){
    timeout = true;
    lastStatus = 0; // just finished with transmitter mode    
     }
 }
   
 if(lastStatus == -1 || lastStatus == 0){
   delay(100);
   radio.stopListening();
   delay(100);
   radio.openWritingPipe(pipe);
   delay(100); 
   lastStatus = 1; // Mode is set to transmitt 
  }
  
 
  transmit_timer = millis(); 
  do{
     transmit(data_to_send); 
     if(millis() - transmit_timer > 500){
       transmitter_timeout = true;
       }
     //Serial.print("Sending data for .5 second now. Data sending = ");Serial.println(data_to_send);
   }while(!transmitter_timeout);
}


void writeLED(int dataIn){ // if data in = 111 then set pin high, else set it low
    if (dataIn == 111){delay(10);digitalWrite(ledPin, HIGH);}
      else {digitalWrite(ledPin, LOW);}
      delay(20);
}

Maybe I could just make an arduino reboot itself periodically. Does anybody know if its possible to do a software reset?

If one unit is sending status data and the other receiving it how can you run the same code on both units? When both units start at the same time what is to stop them both being the sending unit? If you just want one way communication create a sending sketch and a different receiving sketch. If you want two way communication you will need to have two addresses, one for each unit.