nRF24L01

so this is my first time on arduino forums and i just wrote some code for my transmitter which is sending the values of two potentiometers to another arduino with a L98NA and it is supposed to take the values in and call a function movement(); based off those values however im having trouble with the RF and i cant seem to figure out where it went wrong

rx.ino (3.11 KB)

transmitter.v1.ino (839 Bytes)

There are some people with good nRF24L01 knowledge in the forum, please help them to help you. Read the "How to post" (it is at the beginning of each sub forum).

Post your code (use code tags), describe what works, what you tested, what are the results, what do you expect should happen vs what happened ... Good posts usually get fast and good answers. If you use any non Arduino modules and parts provide links to datasheets and libraries you used.

Welcome to the Arduino forum.

ive written code for my TX which should send an array using the potentiometer values from A0 and A1 i have a simple serial.println() to make sure its reading them properly
TX code:

#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
RF24 radio(8,9);
const byte address[6] = "12345"; // setting up pipe address 

int values[2]; 



void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setChannel(100); 
  radio.setDataRate( RF24_250KBPS );
  radio.openWritingPipe(address);       // setting up address for writing the values and sending them 
  radio.setPALevel(RF24_PA_MIN);  // Arduinos are relatively close so im using MIN
  radio.stopListening();
  pinMode(A0, INPUT); 
  pinMode(A1, INPUT);

}

void loop() {
  radio.stopListening();
  values[0] = analogRead(A0); // assigning the values in the array the values of the potentiometer 
  values[1] = analogRead(A1);
  Serial.print("x = ");
  Serial.println(values[0]);     // printing the xvalues in the serial monitor
  Serial.println("----------------------");
  delay(100);
  Serial.print("y = ");
  Serial.println(values[1]);               printing the yvalues in the serial monitor
  Serial.println("----------------------"); 
  delay(100);
  radio.write(&values, sizeof(values)); // sending the values to RX
  
  
}

And then my RX which has a L98NA it should receive the data sent by the TX and call a function movement() based off the values being received
RX:

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

int motorin1 = 2;  // setting up the motor inputs 
int motorin2 = 3;
int motor2in1 = 4;
int motor2in2 = 5;
int motor1ENA = 6;  // setting up the enable pins for speed control
int motor2ENA = 9;
float turnspeed;
RF24 radio(8,7);       // ce , csn
const byte address[6] = "12345";
    float fwdspeed;  // speed variables that ive assigned below 
    float bwdspeed;
    float rightspd;
    float lftspd;
 int values[2];  // setting up an array for the data being received 






void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1,address);
  radio.setPALevel(RF24_PA_MIN);
  radio.setChannel(100); 
  radio.setDataRate( RF24_250KBPS );
  radio.startListening();
  pinMode(motorin1, OUTPUT);  // setting up motors as outputs 
  pinMode(motorin2, OUTPUT);
  pinMode(motor2in1, OUTPUT);
  pinMode(motor2in2, OUTPUT);
  pinMode(motor2ENA, OUTPUT);
  pinMode(motor1ENA, OUTPUT);
  
}

int movement(String dir, float speedd) {  // function fro moving the motors based off a string and a speed 
 
  
  if(dir == "forward"){
    digitalWrite(motorin1, HIGH);
    digitalWrite(motorin2, LOW);
    digitalWrite(motor2in1, HIGH);
    digitalWrite(motor2in2, LOW);
    Serial.println("Motor is turning forwards");
        analogWrite(motor2ENA, speedd);
    analogWrite(motor1ENA, speedd);
  }
  if (dir == "backwards"){
    digitalWrite(motorin1, LOW);
    digitalWrite(motorin2, HIGH);
    digitalWrite(motor2in1, LOW);
    digitalWrite(motor2in2, HIGH);
    Serial.println("Motor is turning backwards");
        analogWrite(motor2ENA, speedd);
    analogWrite(motor1ENA, speedd);
  }
 if (dir == "right"){
  digitalWrite(motorin1, LOW);
  digitalWrite(motorin2, HIGH);
  digitalWrite(motor2in1, HIGH);
  digitalWrite(motor2in2, LOW);

  
 }
  if( dir == "left"){
  digitalWrite(motorin1, HIGH);
  digitalWrite(motorin2, LOW);
  digitalWrite(motor2in1, LOW);
  digitalWrite(motor2in2, HIGH);

  }


}



void loop() {
  radio.startListening();
  
  if(radio.available()){
    while(radio.available());{
    radio.read(&values, sizeof(values));
    }
     fwdspeed = (float)values[0] * 2.191;  // setting up speed translation because incoming values are from 540 to 1023 and i want them in the range 0 to 225 
     bwdspeed = (float)values[0] * 2.55; // 530 to 0 incoming 
     rightspd = (float)values[1] * 2.28;  // 514 to 0 incoming 
     lftspd   = (float)values[1] * 2.257;  // 515 to 1023 incoming 
     int yval = values[0];
     int xval = values[1];
      if(yval > 540 && xval < 525 && xval > 515){ // ive each if statement a range because the two pots are on a joystick so i wanted to account for side to side movement when you push the joystick forward 
        movement("forward", fwdspeed);
        delay(100);
      }
      if(yval < 525 && xval < 525 && xval > 515){
        movement("backwards", bwdspeed);
        delay(100);
      }
      if(xval > 525 && yval < 540 && yval > 525){
        movement("left", lftspd);
        delay(100);
      }
      if(xval < 515 && yval , 540 && yval > 525){
        movement("right", rightspd);
        delay(100);
      }
      Serial.println(xval);
      Serial.println(yval); // not sure if the block of if statements would work i havent been able to test it 
      delay(100);
     
  }
  if(!radio.available()){
    Serial.println("not available");                          // this is all that's printing in the monitor                                                                                                            
  }
    
    
  
      
   
}

im not sure if i was thorough enough in explaining my code but i mainly want to know why radio.available is false im not sure what i did wrong

just realized i forgot to add the SPI library in my Rx just did and tested the code it still did nothing

Have you seen Robin2's simple rf24 tutorial. That tutorial helped me to get my radios to work. One of the biggest factors in getting them to work is proper power to the radios. Robin2's tutorial has suggestions that may help.

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

There is also a connection test program to check that the Arduino can talk to the nRF24 it is connected to.

A common problem with nRF24 modules is insufficient 3.3v current from the Arduino 3.3v pin. This seems to be a particular problem with the nano. The high-power nRF24s (with the external antenna) will definitely need an external power supply. At least for testing try powering the nRF24 with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.

...R

Two topics merged

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a timeout from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky “How to use this forum - please read.” post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

You don’t say how the values you print out on the TX side compare to the values you print out on the Rx side.

Looking at your Rx code, I’m not sure that you meant to write this:

if(xval < 515 && yval , 540 && yval > 525){

If your keyboard layout is the same as mine, then I guess you meant to type ‘<’.

It also helps us if you format your code using Tools->Auto Format, or CTRL+T.

Did you ever get this sorted out?

Having issues myself..

Ran @Robin2 's TEST sketch as well (but not clear as to what I'm looking at as far as results?)