Whats wrong with this RC code?

Hi.
The sketch compile error need help please.
Thanks
Adam

#include <Servo.h>

#include <SPI.h>

#include "RF24.h"

Servo myservo;

//SCK -> 13//MISO -> 12//MOSI -> 11//CSN -> 7//CE -> 8

RF24 radio(8, 7);

const uint64_t pipe = 0xE8E8F0F0E1LL;

int msg[1];

void setup()

{

  myservo.attach(9);

  radio.begin();

  radio.openReadingPipe(1, pipe);

  radio.startListening();

}

void loop()

{

  if (radio.available())

  {

    bool done = false;

    while (!done)

    {

      done = radio.read(msg, 1);

      myservo.write (msg[0]);

    }

  } Servo.h >
}

ERROR:

Arduino: 1.8.16 (Windows 7), Board: "Arduino Uno"

C:\Users\HUA.DELLV-PC\Documents\Arduino\NRF24L01_R_1\NRF24L01_R_1.ino: In function 'void loop()':

NRF24L01_R_1:45:31: error: void value not ignored as it ought to be

       done = radio.read(msg, 1);

                               ^

NRF24L01_R_1:51:10: error: expected unqualified-id before '.' token

   } Servo.h >

          ^

exit status 1

void value not ignored as it ought to be



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

 } Servo.h >

What is that line doing there ? (or anywhere)

1 Like

Looks like the complier has pointed to the line with the error.

1 Like

sorry typo.

Thanks.

Does your sketch compile with the typo corrected ?

1 Like

no, but error code same before and after.

Please post your sketch as it is now, putting it in a new post

1 Like

Thanks.
Everything exactly same except the penultimate line:

} /// Servo.h >

Oops.

radio.read does not return a value, see the RF24 examples on how to use it.

1 Like

Thank you.
I used the examples of:
RF24Network/examples/helloworld_tx/
and
RF24Network/examples/helloworld_rx/
just can't make any communication, what can be wrong?

tx:

/**
 * Copyright (C) 2012 James Coliz, Jr. <maniacbug@ymail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * Update 2014 - TMRh20
 */

/**
 * Simplest possible example of using RF24Network
 *
 * TRANSMITTER NODE
 * Every 2 seconds, send a payload to the receiver node.
 */

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

RF24 radio(10, 9);   // WAS: 7,8                  // nRF24L01(+) radio attached using Getting Started board

RF24Network network(radio);          // Network uses that radio

const uint16_t this_node = 01;       // Address of our node in Octal format
const uint16_t other_node = 00;      // Address of the other node in Octal format

const unsigned long interval = 2000; // How often (in ms) to send 'hello world' to the other unit

unsigned long last_sent;             // When did we last send?
unsigned long packets_sent;          // How many have we sent already


struct payload_t {                   // Structure of our payload
  unsigned long ms;
  unsigned long counter;
};

void setup(void) {
  Serial.begin(115200);
  while (!Serial) {
    // some boards need this because of native USB capability
  }
  Serial.println(F("RF24Network/examples/helloworld_tx/"));

  if (!radio.begin()) {
    Serial.println(F("Radio hardware not responding!"));
    while (1) {
      // hold in infinite loop
    }
  }
  radio.setChannel(90);
  network.begin(/*node address*/ this_node);
}

void loop() {

  network.update(); // Check the network regularly

  unsigned long now = millis();

  // If it's time to send a message, send it!
  if (now - last_sent >= interval) {
    last_sent = now;

    Serial.print(F("Sending... "));
    payload_t payload = { millis(), packets_sent++ };
    RF24NetworkHeader header(/*to node*/ other_node);
    bool ok = network.write(header, &payload, sizeof(payload));
    Serial.println(ok ? F("ok.") : F("failed."));
  }
}

rx:

/**
 * Copyright (C) 2012 James Coliz, Jr. <maniacbug@ymail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * Update 2014 - TMRh20
 */

/**
 * Simplest possible example of using RF24Network,
 *
 * RECEIVER NODE
 * Listens for messages from the transmitter and prints them out.
 */

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


RF24 radio(10, 9);               // nRF24L01(+) radio attached using Getting Started board

RF24Network network(radio);     // Network uses that radio
const uint16_t this_node = 00;  // Address of our node in Octal format (04, 031, etc)
const uint16_t other_node = 01; // Address of the other node in Octal format

struct payload_t {              // Structure of our payload
  unsigned long ms;
  unsigned long counter;
};


void setup(void) {
  Serial.begin(115200);
  while (!Serial) {
    // some boards need this because of native USB capability
  }
  Serial.println(F("RF24Network/examples/helloworld_rx/"));

  if (!radio.begin()) {
    Serial.println(F("Radio hardware not responding!"));
    while (1) {
      // hold in infinite loop
    }
  }
  radio.setChannel(90);
  network.begin(/*node address*/ this_node);
}

void loop(void) {

  network.update();                  // Check the network regularly

  while (network.available()) {      // Is there anything ready for us?

    RF24NetworkHeader header;        // If so, grab it and print it out
    payload_t payload;
    network.read(header, &payload, sizeof(payload));
    Serial.print(F("Received packet: counter="));
    Serial.print(payload.counter);
    Serial.print(F(", origin timestamp="));
    Serial.println(payload.ms);
  }
}

Faulty modules.
Faulty wiring.
Faulty Arduino.

Follow this tutorial;

Perhaps run the connection test first, this will tell you if the modules are connected correctly.

1 Like

Thanks.
I did test without the GND connected for both T/R and got:
Seems got communicated, but the receiver side didn't print out the received data, why?
Both T/R powered by a PC and by Arduino UNO.
I just wonder if the NRF24L01 is such unstable, how it be used? any better board ref. please.

SimpleTx.ino Serial Monitor :
SM_SimpleTx_WITHOUT GND

SimpleRx.ino Serial Monitor :

If I used CheckConnection tested and got serial monitor as below, can I consider at least the hardware and wiring is OK?

/* https://forum.arduino.cc/t/simple-nrf24l01-2-4ghz-transceiver-demo/405123/2

*/

// 18 Mar 2018 - simple program to verify connection between Arduino
//      and nRF24L01+
//  This program does NOT attempt any communication with another nRF24

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

#include <printf.h>

#define CE_PIN   9
#define CSN_PIN 10

const byte thisSlaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};

RF24 radio(CE_PIN, CSN_PIN);

char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;


void setup() {

  Serial.begin(9600);
  Serial.println("xxx_setup!");

  Serial.print("File   : "), Serial.println(__FILE__);
  const char compile_date[] = __DATE__ " " __TIME__;
  Serial.print("Compile timestamp: ");
  Serial.println(compile_date);

  printf_begin();

  Serial.println("CheckConnection Starting");
  Serial.println();
  Serial.println("FIRST WITH THE DEFAULT ADDRESSES after power on");
  Serial.println("  Note that RF24 does NOT reset when Arduino resets - only when power is removed");
  Serial.println("  If the numbers are mostly 0x00 or 0xff it means that the Arduino is not");
  Serial.println("     communicating with the nRF24");
  Serial.println();
  radio.begin();
  radio.printDetails();
  Serial.println();
  Serial.println();
  Serial.println("AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1");
  Serial.println(" and 250KBPS data rate");
  Serial.println();
  radio.openReadingPipe(1, thisSlaveAddress);
  radio.setDataRate( RF24_250KBPS );
  radio.printDetails();
  Serial.println();
  Serial.println();
}


void loop() {

}

serial monitor:

FIRST WITH THE DEFAULT ADDRESSES after power on
  Note that RF24 does NOT reset when Arduino resets - only when power is removed
  If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
     communicating with the nRF24

STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1	 = 0x000000000e 0x0000000038
RX_ADDR_P2-5	 = 0x0e 0x1c 0x0e 0xe0
TX_ADDR		 = 0x000000000e
RX_PW_P0-6	 = 0x1c 0x0e 0x38 0x0e 0x1c 0x0e
EN_AA		 = 0x1c
EN_RXADDR	 = 0x0e
RF_CH		 = 0x1c
RF_SETUP	 = 0x0e
CONFIG		 = 0x0e
DYNPD/FEATURE	 = 0x0e 0x1c
Data Rate	 = 2MBPS
Model		 = nRF24L01
CRC Length	 = 16 bits
PA Power	 = PA_MAX


AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
 and 250KBPS data rate

STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1	 = 0x000000000e 0x0000000038
RX_ADDR_P2-5	 = 0x0e 0x1c 0x0e 0xe0
TX_ADDR		 = 0x000000000e
RX_PW_P0-6	 = 0x1c 0x0e 0x38 0x0e 0x1c 0x0e
EN_AA		 = 0x1c
EN_RXADDR	 = 0x0e
RF_CH		 = 0x1c
RF_SETUP	 = 0x0e
CONFIG		 = 0x0e
DYNPD/FEATURE	 = 0x0e 0x1c
Data Rate	 = 2MBPS
Model		 = nRF24L01
CRC Length	 = 16 bits
PA Power	 = PA_MAX

Exactly the opposite, that is a clear connection fail.

1 Like

Thanks.
Would you please explain more?

Either;

You dont have the modules connected correctly.
The modules are faulty.
The Arduino is faulty.

1 Like

Thank you srnet.
It works now!
Its so unstable that just work a while, and gone again, why?


Data Sent Message 5  Tx failed
Data Sent Message 5  Tx failed
Data Sent Message 5  Tx failed
Data Sent Message 5  Tx failed
..........................

What did you do to fix it ?

1 Like

Thanks.
not much.
I used 2 AA batteries no improve and 10uf. the NRF24L01 was measured ~3.3V even powered by USB.