NRF24L01 transceiver not receiving correct data

Hi, I am making a RC car using the nRF24l01 transceiver and the RF24 library. This is my code:

Controller:

//RADIO CODE FROM THE EXAMPLE IN RF24 LIBRARY: https://nrf24.github.io/RF24/examples_2GettingStarted_2GettingStarted_8ino-example.html

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

#define CE_PIN 7
#define CSN_PIN 8

RF24 radio(CE_PIN, CSN_PIN);

const uint8_t pipeOut  = 0xE8E8F0F0E1LL;

bool radioNumber = 1;

bool role = true;

int payload = 0;

//CONTROLS

int SandDPot = A0; //Stop or Go, Forwards or Backwards, and Speed
int turnPot = A1; //Turn degrees

int order = 0; /* 0 = send stop,go,forwards&backwards
                  1 = send speed
                  2 = send turn degrees*/
int SandD; //see line 23
bool gORs; //go or stop
bool fORb; //forwards or backwards
int speed;
int turn;



void setup() {
  
  //RADIO
  if (!radio.begin()){
    while (1) {}
  }

  radio.setPALevel(RF24_PA_LOW);

  radio.setPayloadSize(sizeof(payload));

  radio.openWritingPipe(pipeOut);

  radio.stopListening();

  //CONTROLS 

  pinMode(SandDPot, INPUT);
  pinMode(turnPot, INPUT);

  gORs = false; //stopped
  fORb = true; //if on go, go forward
}

void loop() {

  if (order != 2){ //not sending turn
    SandD = analogRead(SandDPot) - 511.5; //get input make into range of 511 to -511
    if (order == 0){ //sending stop,go,forwards&backwards
      if (SandD != 0){ //0 = stopped
        gORs = true; //moving
        if (SandD > 0){ //if > 0 moving forward
          fORb = true;
          payload = 1;
        } else {
          fORb = false; //going backwards
          payload = 2;
        }
        order++; //check speed
      } else {
        gORs = false; //stopped
        payload = 0;
        order = 0; //check if moving again
      }
      radio.write(&payload, sizeof(int));
    } else { // sending speed
      if (fORb == true){ //going forwards
        speed = map(SandD, 0, 511, 0, 255); //convert to pwm
      } else { //going backwards
        speed = map(SandD, 0, -511, 0, 128); //half as fast
      }
      payload = speed + 3; //when recieving, if > 3 and =< 258, recieving speed
      radio.write(&payload, sizeof(int));
      order++; //check turn 
    }
  } else { //order == 3, checking turn
    turn = analogRead(turnPot); //get input from potentiometer
    turn = map(turn, 0, 1023, 0, 180); //convert to 180 degrees for servo
    payload = turn + 258; //when recieving if > 258, recieving turn
    radio.write(&payload, sizeof(int));
  }
}

Car: (I am using the serial monitor to test the receiving)

//RADIO CODE BASED ON THIS EXAMPLE IN LIBRARY: https://nrf24.github.io/RF24/examples_2GettingStarted_2GettingStarted_8ino-example.html

//RADIO

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

#define CE_PIN 7
#define CSN_PIN 8

RF24 radio(CE_PIN, CSN_PIN);

const uint8_t pipeIn = 0xE8E8F0F0E1LL;

bool radioNumber = 1;

bool role = false;

int commands; //commands go to here

//CAR

int turnDeg;
int speed;

void setup() {

  //RADIO

  if (!radio.begin()){
    while (1) {}
  }

  radio.setPALevel(RF24_PA_LOW);

  radio.openReadingPipe(1, pipeIn);

  radio.startListening();

  Serial.begin(9600);
}

void loop() {

  uint8_t pipe;
  uint8_t bytes;
  
  //Get command
  if (radio.available(&pipe)){
    bytes = radio.getPayloadSize();
    radio.read(&commands, bytes);
  }

  if (commands <= 3){ //if recieving go,stop,forwards,&backwards
    if (commands == 0) { //stopping
      Serial.println("stopped");
    } else if (commands == 1) { //forwards
      Serial.println("forward");
    } else { //backwards
      Serial.println("backwards");
    }
  } else if (commands > 3 && commands <= 258){ //if recieving speed
    speed = commands - 3;
    Serial.println("Speed: " + speed);
  } else { // recieving turn
    turnDeg = commands - 258;
    Serial.println("Turn: " + turnDeg);
  }
}

The problem is that when I run the code I get this in the serial monitor:

Thanks!

what are they doing? did they contain #include "SPI.h" ?

//RF24 LIBRARY: https://nrf24.github.io/RF24/

//RADIO transmitter
#include <SPI.h>
#include <RF24.h>
#include <printf.h>

#define CE_PIN 7
#define CSN_PIN 8

RF24 radio(CE_PIN, CSN_PIN);

const uint8_t pipeOut  = 0xE8E8F0F0E1LL;
byte payload[2] = {0};

//CONTROLS
const int SandDPot = A0; //Stop or Go, Forwards or Backwards, and Speed
const int turnPot = A1; //Turn degrees

void setup() {
  while (!radio.begin()) {}
  radio.setPALevel(RF24_PA_LOW);
  radio.setPayloadSize(2);
  radio.openWritingPipe(pipeOut);
  radio.stopListening();
  pinMode(SandDPot, INPUT);
  pinMode(turnPot, INPUT);
}

void loop() {
  payload[0] = analogRead(SandDPot) / 4; 
  payload[1] = analogRead(turnPot) / 5.68333333;
  radio.write(&payload, 2);
  delay(20);
}
//RADIO receiver

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

#define CE_PIN 7
#define CSN_PIN 8

RF24 radio(CE_PIN, CSN_PIN);
const uint8_t pipeIn = 0xE8E8F0F0E1LL;

void setup() {
  //RADIO
  while (!radio.begin()) {}
  radio.setPALevel(RF24_PA_LOW);
  radio.openReadingPipe(1, pipeIn);
  radio.startListening();
  Serial.begin(115200);
}

void loop() {
  static byte payload[2] = {0};

  if (radio.available()) {
    radio.read(&payload, 2);
    int speed =payload[0]-128;
    if (abs(speed) < 5)Serial.println("stopped");
    else {
      if (speed > 0) Serial.println("forward");
      else Serial.println("backwards");
    }

    Serial.print("Speed: ");
    Serial.print(speed);
    Serial.print("\tTurn Deg: ");
    Serial.println(payload[1]);
  }
}

I tried using this code, but I didn't see anything in the serial monitor.

I tried using your code @kolaha, but I didn't see anything in the serial monitor.

I think the problem is with the math in the the Loop function, but I am not sure. If anyone can help me figure that out, thanks!

show how you connect modules


I did not use the IRQ.

nRF24L01+ is 3.3V chip, isn't it?

I am using the YourDuino RoboRED board which has a switch that can change it from operating at 5v to 3.3v.

that switch change supply voltage for Atmega328p only or for entire board? how powerful is 3.3V regulator?

or better answer one another question:
Did you successfully run the test sketch and see the nRF module working?

The rx light on the receiving board is on (it is blinking), but the tx light on the sending board is not.
However, a light on the nrf does go on

Using the example code, the nrf did receive the message, but using your code, it did not.

I don't know exactly what was wrong with my code, but I just edited the example code and it worked.

Controller:

#include <SPI.h>
#include "printf.h"
#include "RF24.h"
 
#define CE_PIN 7
#define CSN_PIN 8

RF24 radio(CE_PIN, CSN_PIN);
 
uint8_t address = 0xE8E8F0F0E1LL;

int payload = 0;

int speedPot = A0; //Speed
int turnPot = A1; //Turn degrees

int speed;
int turn;

void setup() {
 
  Serial.begin(115200);
  while (!Serial) {
    // some boards need to wait to ensure access to serial over USB
  }
 
  // initialize the transceiver on the SPI bus
  if (!radio.begin()) {
    Serial.println(F("radio hardware is not responding!!"));
    while (1) {}  // hold in infinite loop
  }
 
  // print example's introductory prompt
  Serial.println(F("RF24/examples/GettingStarted"));
  
  // Set the PA Level low to try preventing power supply related problems
  // because these examples are likely run with nodes in close proximity to
  // each other.
  radio.setPALevel(RF24_PA_LOW);  // RF24_PA_MAX is default.
 
  // save on transmission time by setting the radio to only transmit the
  // number of bytes we need to transmit a int
  radio.setPayloadSize(sizeof(payload));  // int datatype occupies 2 bytes
 
  radio.openWritingPipe(address);
 
  radio.stopListening();  // put radio in TX mode

  //contols 
  pinMode(speedPot, INPUT);
  pinMode(turnPot, INPUT);
}
 
void loop() {
 
  speed = analogRead(speedPot);
  turn = analogRead(turnPot);

  speed = map(speed, 0, 1023, -256, 256);
  turn = map(turn, 0, 1023, 257, 347);

  payload = speed;
  radio.write(&payload, sizeof(int));
  Serial.println(payload);
  delay(1000);
  payload = turn;
  radio.write(&payload, sizeof(int));
  Serial.println(payload);
  delay(1000);
 
}

Receiver:

#include <SPI.h>
#include "printf.h"
#include "RF24.h"
 
#define CE_PIN 7
#define CSN_PIN 8

RF24 radio(CE_PIN, CSN_PIN);
 
uint8_t address = 0xE8E8F0F0E1LL;

int payload = 0;
 
void setup() {
 
  Serial.begin(115200);
  while (!Serial) {
    // some boards need to wait to ensure access to serial over USB
  }
 
  // initialize the transceiver on the SPI bus
  if (!radio.begin()) {
    Serial.println(F("radio hardware is not responding!!"));
    while (1) {}  // hold in infinite loop
  }

  // Set the PA Level low to try preventing power supply related problems
  // because these examples are likely run with nodes in close proximity to
  // each other.
  radio.setPALevel(RF24_PA_LOW);  // RF24_PA_MAX is default.
 
  // save on transmission time by setting the radio to only transmit the
  // number of bytes we need to transmit a int
  radio.setPayloadSize(sizeof(payload));  // int datatype occupies 2 bytes

  radio.openReadingPipe(1, address);

  radio.startListening();  // put radio in RX mode
}
 
void loop() {

  uint8_t pipe;
  if (radio.available(&pipe)) {              
    uint8_t bytes = radio.getPayloadSize();  // get the size of the payload
    radio.read(&payload, bytes);   

    //get speed, direction & turn
    if (payload == 0) {
      Serial.println("Stopped");
    } else if (payload < 0) {
      Serial.print("Backwards: ");
      Serial.println(payload);
    } else if (payload > 0 && payload < 257) {
      Serial.print("Forwards: ");
      Serial.println(payload);
    } else {
      payload = payload - 302;
      Serial.print("Turn: ");
      Serial.println(payload);
    }
  }
}

Thanks @kolaha for trying to solve the problem!