Remote control car radio receiving issues

I have been working on a remote control car for a few months now and i have had a few errors along the way but that is all fixed and i finally got the code to upload... and it dosen't work.

Here is the controller code:

// RF24 - Version: Latest 
#include "RF24.h"
#include <SPI.h>

// Hardware configuration: Set up nRF24L01 radio on SPI bus (pins 10, 11, 12, 13) plus pins 7 & 8
RF24 radio(7, 8);

byte addresses[][6] = {"1Node","2Node"};

// Define the Joystick Connections
int joyY = 0;
int joyX = 1;

int joyposY = 512; 
int joyposX = 512;

int valX;
int valY;

void setup() {
  
  radio.begin();                    //start radio communication

  radio.setPALevel(RF24_PA_LOW);    //power level

  radio.setDataRate(RF24_2MBPS);   //make it quick

  radio.setChannel(124);             // Use a channel unlikely to be used by Wifi

  radio.openWritingPipe(addresses[1]);       //send
  radio.openReadingPipe(1, addresses[0]);    //recieve
  
  radio.startListening();          //start listening for radio
  
}

void loop() {
  
  valX = analogRead(joyX);
  valY = analogRead(joyY);
  
  uint8_t data[2]; // defines size of array
  data[0] = valX;  // puts the value from the variable valX into the first element 
                   // note elements numbered from 0
                   // also assumes that valX is defined as uint8_t or byte
  data[1] = valY;

  radio.stopListening(); 

   if (!radio.write( &data, sizeof(unsigned char) )) {
    Serial.println("No acknowledgement of transmission - receiving radio device connected?");
   }
   
    radio.startListening();
  
  // But it won't listen for long, 200 milliseconds is enough
  unsigned long started_waiting_at = millis();
  
  // Loop here until we get indication that some data is ready for us to read (or we time out)
  while ( ! radio.available() ) {

    //No response received within our timescale
     
    if (millis() - started_waiting_at > 200 ) {
      Serial.println("No response received - timeout");
      return;
    }
    
  // Now read the data that is waiting for us in the nRF24L01's buffer
  
  unsigned char dataRx;
  radio.read( &dataRx, sizeof(unsigned char) );

  // Show user what we sent and what we got back
  
  Serial.print("Sent ");
  Serial.print(", received: ");
  Serial.println(dataRx);

}

}

and this is the car code:


// RF24 - Version: Latest 
#include "RF24.h"
               
#include <SPI.h>
                
// Servo - Version: Latest 
#include <Servo.h>
               
                
// This is just the way the RF24 library works:
// Hardware configuration: Set up nRF24L01 radio on SPI bus (pins 10, 11, 12, 13) plus pins 7 & 8
RF24 radio(7, 8);

byte addresses[][6] = {"1Node","2Node"};

int valX;
int valY;

Servo myservo1;
int myservo1Pin = 4;

Servo myservo2;
int myservo2Pin = 5;

void setup() {
  
  myservo1.attach(myservo1Pin);
  myservo2.attach(myservo2Pin);
  
  radio.begin();                    //start radio communication

  radio.setPALevel(RF24_PA_LOW);    //power level

  radio.setDataRate(RF24_2MBPS);   //make it quick

  radio.setChannel(124);             // Use a channel unlikely to be used by Wifi

  radio.openWritingPipe(addresses[0]);       //send
  radio.openReadingPipe(1, addresses[1]);    //recieve
  
  radio.startListening();          //start listening for radio

}

void loop() {
  
  Serial.begin(9600);
  Serial.println("THIS IS THE RECEIVER CODE - YOU NEED THE OTHER ARDUINO TO TRANSMIT");
  
  radio.begin();
  
  // This is what we receive from the other device (the transmitter)
  unsigned char data;

  // Is there any data for us to get?
  if ( radio.available()) {

  // Go and read the data and put it into that variable
  while (radio.available()) {
  radio.read( &data, sizeof(char));
  }
  
  radio.stopListening();
  
  Serial.print("recieved");
  
  }
  
  {

  if (valX < 460) // turn left
  {
  valY = map(valY, 0, 1023, 0, 180);
  valX = map(valX, 0, 1023, 0, 90);
  myservo1.write(valY-valX/2);                    // servo 1 slows
  myservo2.write(180-valY);
  delay(15);
  }
  else if (valX > 564) // turn right
  {
  valY = map(valY, 0, 1023, 0, 180);
  valX = map(valX, 0, 1023, 0, 90);
  myservo1.write(valY);
  myservo2.write((180-valY)-valX/2);              // servo 2 slows
  delay(15);
  }
  
  }

}

the rx LED ( which indicates if you are receiving data) on the car is not lighting up. I think that may be the main issue but i have no clue how to fix it.

thank you very much for your help.

jethro crooke

What doesn't work? What is it supposed to do? How do you know it doesn't work? What testing and debugging have you done?
Paul

How are the radios on the transmitter and receiver powered? The number one problem with the RF24 radios is lack of current capability of the radio power supplies.

Please post schematics of the complete transmitting Arduino circuit and the complete receiving Arduino circuit.

The car is meant to move with a joystick that is on the controller, the car is not receiving any data (i found that out from the rx LED on the car,) and the car doesn’t move with the joystick. It just stays still.

The nrf24L01 has the extension board an is taking a 5 volt input.

CE = D7
CSN = D8
SCK = D13
MO = D11
M1 = D12

The receiving side and transmitting side are the same

I assume that at some point over the last few months you had this working whilst you were testing it. Have a look over your code from the last known working version to determine what has changed to make it not work in its current form.

it never worked but i can see that i had made it sound like that.

Drop that line from the receiver, it is just crazy.

You receive a single byte and then compare it against values that are bigger than a byte,
again, quite strange.

This should be

if (!radio.write( &data, sizeof(data) )) {

Reading from the chip while nothing is available is quite strange also.

The receiver will never reply, so what are you waiting for?

I think you should rethink your whole strategy.

In which case I would suggest going back to basics and starting with the excellent tutorials written by @Robin2. Once you believe you have it wired up correctly, run the connection test sketch at post #30 to check things out before trying to communcate between your modules.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.