0

im trying to build an rc plane using arduino nano and nrf24l01 as receiver but im having some issues in the code

it has error on the line done = radio.read(joystick,sizeof(joystick)); which says that void value not ignored as it ought to be

the whole code is below

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#include<Servo.h>

Servo Throttle,Rudder,Elevator,LeftAileron,RightAileron ;

const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(9,10);
int joystick[5];

void setup()
{
  /*Serial.begin(9600);
  delay(1000);
  Serial.println("Starting Rx");*/ //Enable serial for debugging

  attachMotors();

  calibrateMotors();

  radio.begin();

  detachMotors();

  radio.setPALevel(RF24_PA_MAX);
  radio.setPayloadSize(10);
  radio.setDataRate(RF24_250KBPS);
  radio.setRetries(15,15);

  radio.openReadingPipe(1,pipe);
  radio.startListening();;
}

void loop()
{
  detachMotors();

  if(radio.available())
  {
    bool done=false;
    while(!done)
    {
      done=radio.read(joystick,sizeof(joystick));
    }

  attachMotors();

  int a=joystick[0];
  int b= joystick[1]; //stores values from tx
  int c=joystick[2];
  int d=joystick[3];
  int e=joystick[4];

  //Serial.println(a);
  //Serial.println(b);
  //Serial.println(c);
  //Serial.println(d);
  //Serial.println(e);
 // Serial.println(f);

  delay(20);
  Throttle.writeMicroseconds(a);   //write values to motor
  Rudder.write(b);
  Elevator.write(180-c);

  if(d== LOW)
  {
  LeftAileron.write(180); ////to activate right aileron
  RightAileron.write(180);
  delay(15);
  }

  else if(e == LOW)
  { 
    LeftAileron.write(0);  //to activate left aileron
    RightAileron.write(0);
    delay(15);
  }
  else
  {
    LeftAileron.write(100);
    RightAileron.write(110); //Ailerons at neutral pos
    delay(15);
  }
    }
  else
  {
    calibrateMotors();
    delay(15);

  }
  }

void attachMotors()
{
  Throttle.attach(3);
  Rudder.attach(4);
  Elevator.attach(5);
  LeftAileron.attach(6);
  RightAileron.attach(7); 
}

void calibrateMotors()
{
  Rudder.write(90);
  Elevator.write(90);
  LeftAileron.write(100);
  RightAileron.write(110); //centering servo shafts
}

void detachMotors()
{
  Throttle.detach();
  Rudder.detach();
  Elevator.detach();
  LeftAileron.detach();
  RightAileron.detach();
}
  • "Void value" basically means "nothing", that the function doesn't return anything you can to store. If you want to check if packets are available use the .available() and read() if you want to store that data somewhere (after you've made sure there is something in the buffer). – Avamander Jul 19 '17 at 10:56
  • I think this examples could help you but this isn't the same library you seem to be using: github.com/nRF24/RF24/blob/master/examples/GettingStarted/… . (Disclaimer: I am one of the maintainers of the library linked here) – Avamander Jul 19 '17 at 11:01
1

Something changed while you were looking away. This is the updated description of read(). As you can see, it not longer returns a bool. Use available to determine if packets are available:

/**
   * Read the available payload
   *
   * The size of data read is the fixed payload size, see getPayloadSize()
   *
   * @note I specifically chose 'void*' as a data type to make it easier
   * for beginners to use.  No casting needed.
   *
   * @note No longer boolean. Use available to determine if packets are
   * available. Interrupt flags are now cleared during reads instead of
   * when calling available().
   *
   * @param buf Pointer to a buffer where the data should be written
   * @param len Maximum number of bytes to read into the buffer
   *
   * @code
   * if(radio.available()){
   *   radio.read(&data,sizeof(data));
   * }  
void read( void* buf, uint8_t len );
| improve this answer | |
  • Can you please fix the code for me because i recently started on the arduino platform and dont know much. I copy pasted this code from somewhere else :( – Osmond Yang Jul 19 '17 at 11:16
  • Best way to learn is to do it yourself, this answer also has a small code snippet that shows how to read data from the nRF24L01(+), have you tried it? The examples in the examples folder also show you how to use the library if you still can't figure it out. – Avamander Jul 19 '17 at 11:18
  • 1
    Give a man a fish ... – user31481 Jul 19 '17 at 11:19
  • ok ill try to understand the examples – Osmond Yang Jul 19 '17 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.