Check my code for NRF24l01

Im still a newbie to coding arduinos. I am doing a project and need someone to check my code. I am using a thumb joystick to control 2 servos through arduino minis and nrf24l01. Also to control a button. Im sure i have some mistakes could anyone help?

TRANSMITTER

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h" 
#define button 8 
RF24 radio(9,10); /* CE= pin 9  and CSN = pin 10 */
const uint64_t pipe = 0xE8E8F0F0E1LL;
boolean buttonState = 0; 

void setup(void)
{
  pinMode(button, INPUT); /* SETS PIN 8 AS AN INPUT FOR BUTTON SIGNAL*/
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe); 
}

void loop() 
{
  int potValue1 = analogRead(A0);                     /* THUMB Y */
  int angleValue1 = map(potValue1,0,1023,0,180);       /* THUMB Y */
  int potValue2 = analogRead(A1);                     /* THUMB X */
  int angleValue2 = map(potValue2,0,1023,0,180);       /* THUMB X */
  buttonState = digitalRead(button);                  /* BUTTON PUSHED?*/
  radio.write(&angleValue1, sizeof(angleValue1));
  radio.write(&angleValue2, sizeof(angleValue2));         
  radio.write(&buttonState, sizeof(buttonState));
}

RECEIVER

#include <Servo.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#define shooter 2 
Servo servo1;
Servo servo2;
RF24 radio(9,10); /* CE= pin 9  and CSN = pin 10 */
const uint64_t pipe = 0xE8E8F0F0E1LL;
boolean buttonState = 0; 

void setup()
{
  pinMode(shooter,OUTPUT);  /* SETS PIN 2 AS AN OUTPUT FOR SHOOTER VOLTAGE*/
  servo1.attach(7); /* SERVO YELLOW SIGNAL WIRE ATTACHED TO PIN 7*/
  servo2.attach(3); /* SERVO YELLOW SIGNAL WIRE ATTACHED TO PIN3*/
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
}
void loop()
{
  if (radio.available())
{
  while (radio.available())           /* READING THUMB JOYSTICK AND SENDING TO SERVOS*/
  {
    int angleV1=0;
    int angleV2=0;
    radio.read(&angleV1, sizeof(angleV1));
    servo1.write(angleV1);
    radio.read(&angleV2, sizeof(angleV2));
    servo2.write(angleV2);
  }
  while (!radio.available());                     /*WAITING FOR BUTTON TO BE PUSHED FOR SHOOTER*/
  radio.read(&buttonState,sizeof(buttonState));
  if (buttonState == HIGH)
      { digitalWrite(shooter, HIGH);}
  else 
    {digitalWrite(shooter,LOW);}
}
}

Does it work ? If not then what does it do ?

Im sure i have some mistakes

Why do you think that? The code does something, but you didn't tell us what it does, or how that differs from what you want.

It does nothing. the servos will recenter on power but moving the thumbstick does nothing.

You send three independent messages. You need three independent reads, of those messages. When you read the nth message, you need to know how to use that value. Is it an x value, a y value, or a button state?

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

You should NOT be sending three numbers in three separate messages. Send them in a single message then there can be no doubt about which number is for which purpose. Put the three numbers into an array and send the array.

...R

PaulS: Why do you think that? The code does something, but you didn't tell us what it does, or how that differs from what you want.

because it doesnt work lol, the code looks good but im not sure if im sending the info between the RF modules correctly

I updated Reply #5 while you were writing Reply #6

...R

Have you tried printing what you receive ?

Robin2: Have a look at this Simple nRF24L01+ Tutorial.

You should NOT be sending three numbers in three separate messages. Send them in a single message then there can be no doubt about which number is for which purpose. Put the three numbers into an array and send the array.

...R

I have read your tutorial and it did help alot.

How would i make an array for the values to send? I guess my question is how would i read the analog input in and map it in an array?

UKHeliBob: Have you tried printing what you receive ?

I have not. Im no professional when it comes to coding, and this is my 1st time using arduinos. How would i do that?

You should not be using an nRF24L01 the first time that you use an Arduino. Maybe not even the fifth time.

"It doesn't work" is not helpful. What it is intended to do, what it does, and how they differ is better.

Im no professional when it comes to coding, and this is my 1st time using arduinos. How would i do that?

In the receiver put

Serial.begin(9600);

in setup()

Then in loop() put

radio.read(&buttonState,sizeof(buttonState));
Serial.print("buttonState : ");
Serial.println(buttonState);

and so on and open the Serial monitor when the program is running

This allows you to see the values being received, if any

UKHeliBob: In the receiver put

Serial.begin(9600);

in setup()

Then in loop() put

radio.read(&buttonState,sizeof(buttonState));
Serial.print("buttonState : ");
Serial.println(buttonState);

and so on and open the Serial monitor when the program is running

This allows you to see the values being received, if any

how do i wire my pro mini receiver to the serial monitor?

Alphaburner: How would i make an array for the values to send? I guess my question is how would i read the analog input in and map it in an array?

Let's just take things step by step. To put the values in an array first you need an array with 3 elements

int myDataArray[3]

and to put your readings into the array

myDataArray[0] = angleValue1;
myDataArray[1] = angleValue2;
myDataArray[2] = buttonState;

and send the array

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

On the receiving side have an identical array

...R

PS ... I just noticed that your Tx is trying to send messages as fast as loop() repeats. That won't help - the nRF24 probably can't keep up and the Rx certainly won't be able to. Only send the data a few times per second - perhaps 5 times.

how do i wire my pro mini receiver to the serial monitor?

The Seroa; monitor is part of the IDE

In the IDE menu Tools/Serial Monitor or Ctr+Shift+M on the keyboard or the Serial Monitor icon in the IDE itself