Issues in provided code for nRF24L01

Hi,

I've been experimenting with the nRF24L01 transmit/receive modules for Arduino.

This tutorial provides two Arduino projects, one for the transmitter and one for the receiver. It's originally a mail box indicator project where one Arduino sends a bit when the mail box is opened, and the other Arduino receives it and indicate that the mail box is opened.

I'm going to use this as a baseline for my project, which is to indicate that a fridge door has been opened where samples are placed temporarily for pick-up. The laboratory employee will get a notification light, walks down to the fridge, picks up the sample and should then reset the indicator with a button by the fridge.

This is the receiver code in question:

// RECEIVER

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
//#include "printf.h"

#define ledPin 4

// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 

RF24 radio(9,10);


// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 
  0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };


void setup(void)
{
  pinMode(ledPin, OUTPUT); 
  Serial.begin(57600);
 // printf_begin();
 // printf("THIS IS THE RECEIVER");

  radio.begin();

  // optionally, increase the delay between retries & # of retries
  radio.setRetries(15,15);
  // optionally, reduce the payload size.  seems to
  // improve reliability
  //radio.setPayloadSize(8);

  radio.openReadingPipe(1,pipes[0]);
  radio.startListening();


  //radio.printDetails(); uncomment to debug
}

void loop(void)
{
  unsigned long data_in = getData();
  if(data_in == 999){
    Serial.println("THE VALUE IS HIGH!");
    digitalWrite(ledPin,HIGH);
  }
  else if(data_in == 111){
    Serial.println("THE VALUE IS LOW");
    digitalWrite(ledPin, LOW);
  }
  else if(data_in != 111 || data_in != 999)
    Serial.println("UNEXPECTED DATA IN");
}

unsigned long  getData(){
  delay(50);
  unsigned long  got_time;  
  if ( radio.available() )  {
    // Dump the payloads until we've gotten everything
    bool done = false;
    while (!done)
    {
      // Fetch the payload, and see if this was the last one.
      done = radio.read( &got_time, sizeof(unsigned long )); // return true when done
      // Spew it
     // printf("Got payload %lu...",got_time);

    }
  }
  return(got_time);
}

However, the receiver code does not want to compile. It throws an error:

Arduino: 1.8.15 (Windows 10), Board: "Arduino Micro"

C:\Users\XXXXX\OneDrive - XXXXX\Dokumenter XXXXXX - XXXXXXX\Prosjekter\KjĂžleskapssignal lab\Program\RECEIVER\RECEIVER.ino: In function 'long unsigned int getData()':

RECEIVER:66:59: error: void value not ignored as it ought to be

exit status 1

void value not ignored as it ought to be

The transmitter code compiles with no problem:

// TRANSMITTER

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
//#include "printf.h"


#define ledPin 7
#define sensorPin 4

// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 

RF24 radio(9,10);

//
// Topology
//

// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 
  0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

void setup(void)
{
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  pinMode(sensorPin, INPUT_PULLUP);

  Serial.begin(57600);
//  printf_begin();
 // printf("TRANSMITTER\n");

  radio.begin();

  // optionally, increase the delay between retries & # of retries
  radio.setRetries(15,15);

  // optionally, reduce the payload size.  seems to
  // improve reliability
  //radio.setPayloadSize(8);

  //
  // Open pipes to other nodes for communication
  //

  // This simple sketch opens two pipes for these two nodes to communicate
  // back and forth.
  // Open 'our' pipe for writing
  // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)

  //if ( role == role_ping_out )
  {
    radio.openWritingPipe(pipes[0]);
    //radio.openReadingPipe(1,pipes[1]);
  }
  //else
  {
    //radio.openWritingPipe(pipes[1]);
    // radio.openReadingPipe(1,pipes[0]);
  }

  //
  // Start listening
  //

  // radio.startListening();

  //
  // Dump the configuration of the rf unit for debugging
  //

  //radio.printDetails();
}

void loop(void)
{
  boolean recived_data;  
  boolean sensorStat = digitalRead(sensorPin);
  if(sensorStat == LOW){ // connection has been made
    boolean recived_data;  
    do{
      recived_data = sendData(999);
      Serial.println("Data has not been recived");
    }while(recived_data == false);
  //if(sensorStat == HIGH)
//sendData(111);
  }
}
boolean sendData(unsigned long dataToSend){
  // Take the time, and send it.  This will block until complete

 // printf("Now sending %lu...",dataToSend);
  bool ok = radio.write( &dataToSend, sizeof(unsigned long ) );

  if (ok){
   // printf("Message was recived\n"); // confirmed it has been recived
    digitalWrite(ledPin, HIGH);
    return(true);
  }
  else{
  //  printf("failed.\n\r");
    digitalWrite(ledPin,LOW);
    return false;
  }
}

I'm not quite familiar with Arduino programming yet, and my attempts to learn what's wrong have failed. I have been mostly programming industrial PLCs, so this is completely new for me.
It seems like it's trying to get a value out of ( &got_time, sizeof(unsigned long ) but it shouldn't?

The Arduino used is a Micro for both the transmitter and receiver.

Does anyone know what I should do to correct the error? Thanks.

This indicates that the code was written for the predecessor (Maniac Bug) of the current recommended NRF24L01 library (TMRh20).

The read method does not now return a value. Fine a newer tutorial to follow.

Incidentally, that project you are following uses a battery powered Arduino Uno. Expect to have to spend a lot of money buying new batteries.

Maybe Robin's Simple nRF24L01+ 2.4GHz transceiver demo can be of help.

This indicates that the code was written for the predecessor (Maniac Bug) of the current recommended NRF24L01 library (TMRh20).

Figures, I will see if I can find any newer example projects to use.

Incidentally, that project you are following uses a battery powered Arduino Uno. Expect to have to spend a lot of money buying new batteries.

I will be using a 5V power supply on both of these (3,3V from a buck converter for the RF), so I'm only following the tutorial for the code and RF module wiring.

Maybe Robin's Simple nRF24L01+ 2.4GHz transceiver demo can be of help.

Thanks! I will check it out.

Once you have solved the problems of getting a compilable version of the code, then the next problems with these transceiver devices, are usually power related, especially if you are using the higher power versions of the NRF24L01, usually sold as NRF24L01 + LNA + PA.

If you are using a mains power supply (say an smart phone charger) then an adapter like this should solves such problems and you then do not need a buck converter for the 3.3 volts:


e.g.: Socket adapter module board for 8 pin nrf24l01+ wireless transceiver Sale - Banggood.com

If the transmitter part (the one on the fridge door) is to be battery powered, then you have to be more careful about your choice of components for a reasonable battery life.

I'm still struggling with this problem. The issue is that I don't know how to use the existing program with the newer TMRh20 library, and creating a new program from scratch seems to be out of my knowledge.

I'm absolutely terrible at Arduino programming, but I still want to continue this project.

Does anyone have any tips on how I could resolve this error with the existing code and library?

Edit: I tried using the ManiacBug version and the program compiled without issues. Now over to testing and modifying as I'm adding a reset button on the transmitter side. ManiacBug RF24 library