NRF24l01 joystick remote not transmitting to receiver

I'm trying to make a remote control robot controlled by a joystick, with the transmitting Uno and receiving Mega board linked by by NRF24L01 modules. I've attached my wiring diagrams and the code for my transmitter and receiver, respectively, down below. The problem is that the RX light on the receiving Mega board is not lit, and the motors attached to the motor driver don't move. Nothing appears on the receiving serial monitor. The TX light on the transmitting Uno is lit, and the X and Y values of the joystick appear in the monitor.

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

RF24 myRadio (7, 8);
byte addresses[][6] = {"0"};

struct package
{
  int X=1;
  int Y=1;
};


typedef struct package Package;
Package data;


void setup()
{
  Serial.begin(115200);
  delay(100);
  myRadio.begin();  
  myRadio.setChannel(115); 
  myRadio.setPALevel(RF24_PA_MIN);
  myRadio.setDataRate( RF24_250KBPS ) ; 
  myRadio.openWritingPipe( addresses[0]);
  delay(100);
}

void loop()
{
 
  myRadio.write(&data, sizeof(data)); 

  Serial.print("X:");
  Serial.print(data.X);
  Serial.print("    Y");
  Serial.println(data.Y);
  data.X = analogRead(A0);
  data.Y = analogRead(A1);
  delay(100);
}
#include <SPI.h>  
#include "RF24.h" 

RF24 myRadio (7, 8); 
struct package
{
  int X=512;
  int Y=512;
};

byte addresses[][6] = {"0"}; 
int OUT1 = 5;
int OUT2 = 6;
int OUT3 = 9;
int OUT4 = 10;


typedef struct package Package;
Package data;

void setup() 
{
  Serial.begin(115200);
  delay(1000);

  myRadio.begin(); 
  myRadio.setChannel(115); 
  myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS ) ; 
  myRadio.openReadingPipe(1, addresses[0]);
  myRadio.startListening();
  pinMode(OUT1, OUTPUT);
  pinMode(OUT2, OUTPUT);
  pinMode(OUT3, OUTPUT);
  pinMode(OUT4, OUTPUT);
  analogWrite(OUT1, 0);
  analogWrite(OUT2, 0);
  analogWrite(OUT3, 0);
  analogWrite(OUT4, 0);
}


void loop()  
{
  if ( myRadio.available()) 
  {
    while (myRadio.available())
    {
      myRadio.read( &data, sizeof(data) );
    }
    Serial.print("X:");
    Serial.print(data.X);
    Serial.print("      Y");
    Serial.println(data.Y);
    int X = data.X;
    int Y = data.Y;
    int foward = map(X,524,1024,0,255);
    int backward = map(X,500,0,0,255);
    int right = map(Y,524,1024,0,255);
    int left = map(Y,500,0,0,255);
    if(X > 524 && Y < 524 && Y > 500){
      analogWrite(OUT3, foward);
      analogWrite(OUT4, 0);
      analogWrite(OUT1, foward);
      analogWrite(OUT2, 0);
    }else if(X < 500 && Y < 524 && Y > 500){
      analogWrite(OUT4, backward);
      analogWrite(OUT3, 0);
      analogWrite(OUT2, backward);
      analogWrite(OUT1, 0);
    }else if(X < 524 && X > 500 && Y < 524 && Y > 500){
      analogWrite(OUT4, 0);
      analogWrite(OUT3, 0);
      analogWrite(OUT2, 0);
      analogWrite(OUT1, 0);
    }else if(X < 524 && X > 500 && Y > 524){
      analogWrite(OUT4, 0);
      analogWrite(OUT3, left);
      analogWrite(OUT2, left);
      analogWrite(OUT1, 0);
    }else if(X < 524 && X > 500 && Y < 500){
      analogWrite(OUT4, right);
      analogWrite(OUT3, 0);
      analogWrite(OUT2, 0);
      analogWrite(OUT1, right);
    }else if(X > 524 && Y > 524){
      analogWrite(OUT3, foward);
      analogWrite(OUT4, 0);
      analogWrite(OUT1, foward-right);
      analogWrite(OUT2, 0);
    }else if(X > 524 && Y < 500){
      analogWrite(OUT3, foward-left);
      analogWrite(OUT4, 0);
      analogWrite(OUT1, foward);
      analogWrite(OUT2, 0);
    }else if(X < 500 && Y > 524){
      analogWrite(OUT4, backward);
      analogWrite(OUT3, 0);
      analogWrite(OUT2, backward-right);
      analogWrite(OUT1, 0);
    }else if(X < 500 && Y < 500){
      analogWrite(OUT4, backward-left);
      analogWrite(OUT3, 0);
      analogWrite(OUT2, backward);
      analogWrite(OUT1, 0);
    }
    
  }

}

Hi,
The TX and Rx lights are on the pin0 and pin1 serial ports.
As you are using 7 and 8 they are not involved.

Have you tried some simple nRF code to establish your connection, before adding the control code?

Have you looked at this site and tried the code there?

https://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

Tom... :slight_smile:

Tom,

Thanks so much for the link, it was really helpful. Good news is, I'm fairly certain that the module attached to the Uno is sending, as I've tested it with the Getting Started sketch from the library. Bad news is, I don't think the Mega is receiving. The serial monitor for the Uno shows it's trying to transmit, but it keeps printing out that it failed. I changed the Mega to the transmitter and the Uno to the receiver, but still no luck, the serial monitor for the transmitting Mega doesn't display anything even with I type in the 'T' to tell it to transmit.
I've ordered base modules for the NRF24l01s to go into in case the issue has to do with powering them, maybe that'll solve my problem.

Swapped the Mega for another Uno I had lying around, seems to work now. Still ordering the base modules just in case. Now that I've made sure the modules can in fact send and receive, any tips on how to integrate the joystick control into the code?

Nevermind, added in a line that told the controller to stop listening, and it worked perfectly. Thanks for your help.

FishDentist:
Nevermind, added in a line that told the controller to stop listening, and it worked perfectly. Thanks for your help.

Good stuff mate, glad you got it sorted on your own, you don't forget things when you learn that way.
Tom... :slight_smile: