NRF24L01 Issues I cannot resolve by myself.

Hi we have 2x NRF24L01 on Uno boards. One is acting as a transmitter, and the other solely as a a receiver. The project is, the transmitter powers on when a forklift is powered up. The receiver stays on permanently and when receiving data, the output pin becomes high (when the forklift is on it powers a beacon lamp).

The issue is, when you turn the forklift on (power the transmitter) it works 3 out of 4 times perfectly. The other time it begins receiving in the first loop then stops. The same issue occurs if you go out of range and then come back into range. I’m not sure what the problem is. I have a 10uF cap on the NRF24L01 supply pins. Please let me know if you have any questions or if there are things I can troubleshoot?

Cheers

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

RF24 radio(7, 8); // CE, CSN

const byte address[6] = "00001";
int inPin = 3;                    // Forklift running input pin
int forkliftVal = 1;              // 0 = Forklift not running, 1 = Forklift running

void setup() {
  
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(2);            // Baudrate, lower the value, higher the distance (0 2Mbps,1 1 Mbps,,2 250Kbps)
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_LOW);  // Set PA level (min,low,high,max)
  radio.stopListening();
;
  delay(500);  
  }

void loop() { 
  radio.write(&forkliftVal, sizeof(forkliftVal)); // Write the value of 0 or 1 over wireless

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

RF24 radio(7, 8); // CE, CSN

const byte address[6] = "00001";
boolean forkliftVal = 0;
int n = 0;


void setup() {
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(2);
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_LOW);
  radio.startListening();
  pinMode(6, OUTPUT);    // sets the digital pin 2 as output
}
void loop() {
       char text[32] = "";
    radio.read(&forkliftVal, sizeof(forkliftVal));
    if (forkliftVal > 0){
      digitalWrite(6, HIGH);
      n=0;
      }   
    else 
    n++;
 
    if (n==4){digitalWrite(6, LOW);}
     delay(500);
    
}

You should moderate the sending frequency, it is way to high.

You should use

if (radio.available()) {

}

and no delay in the receiver.

radio.setDataRate(2);

Use the predefined constant for that value.

The delay in setup of the transmitter is strange.

This Simple nRF24L01+ Tutorial may be of interest.

...R

Hi Guys

Thanks for your response. I modified the code from Robin2 to suit my output. I still have the issue where occasionally on power up it stops receiving, I think. ill add more detail when m back in the office but if anyone can think of anything regarding this code then that would be great.

Cheers

 // SimpleTx - the master or the transmitter

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


#define CE_PIN   7
#define CSN_PIN 8

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


RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

char dataToSend[10] = "Message 0";
char txNum = '0';


unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second


void setup() {

    Serial.begin(9600);

    Serial.println("SimpleTx Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(slaveAddress);
}

//====================

void loop() {
    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {
        send();
        prevMillis = millis();
    }
}

//====================

void send() {

    bool rslt;
    rslt = radio.write( &dataToSend, sizeof(dataToSend) );
        // Always use sizeof() as it gives the size as the number of bytes.
        // For example if dataToSend was an int sizeof() would correctly return 2

    Serial.print("Data Sent ");
    Serial.print(dataToSend);
    if (rslt) {
        Serial.println("  Acknowledge received");
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }
}

//================

void updateMessage() {
        // so you can see that new data is being sent
    txNum += 1;
    if (txNum > '9') {
        txNum = '0';
    }
    dataToSend[8] = txNum;
}
// SimpleRx - the slave or the receiver

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

#define CE_PIN   7
#define CSN_PIN 8

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("SimpleRx Starting");
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.startListening();
    pinMode(6, OUTPUT);    // sets the digital pin 6 as output
}

//=============

void loop() {
    getData();
    showData();
}

//==============

void getData() {
    if ( radio.available() ) {
        radio.read( &dataReceived, sizeof(dataReceived) );
        newData = true;   
    }
    else {
      delay(1000);
      digitalWrite(6, LOW);
    }
    
}

void showData() {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(dataReceived);
        digitalWrite(6, HIGH);              
       newData = false;
    }
       
}

reejef:
I still have the issue where occasionally on power up it stops receiving, I think.

Do you mean when the receiver is powered up or when the transmitter is powered up?

In my own tests with my Tutorial programs communication obviously stops if either board is de-powered but it starts again when the board is re-powered.

...R

Hi Robin2

When the transmitter is powered up, its powered on when the forklift starts, otherwise it may drain the battery. The receiver stays on permanently.

Do you think it may be a power issue? Through all the testing and plugging and unplugging of laptops, I "think" while having the receiver plugged into a laptop and the serial monitor running, it worked perfectly. Unplugging the laptop and using the power adapter, it seemed to stop/ the output pin didn't turn on after 3 power ups of the transmitter. really strange. What would you guys do next if it was you?

Cheers

reejef:
What would you guys do next if it was you?

If you have another Arduino and nRF24 that you can temporarily substitute for the one on the forklift (i.e. without disturbing the one on the forklift) that could be used to verify that {A} the receiver works and {B} that the problem is related to the forklift (or not).

It would also be a good idea to check whether it is the Arduino or the nRF24 on the forklift that is causing the problem. I would be suspicious that the forklift power supply might have glitches that cause the Arduino to crash.

By the way, is this a full-size forklift or a model?

...R

I don't have substitute parts handy unfortunately. It is a full size 48V forklift. I'm using a little 48V to 5V step down transformer to power the board, maybe this is causing issues on startup?

reejef:
I'm using a little 48V to 5V step down transformer to power the board, maybe this is causing issues on startup?

It would be very easy to check that by temporarily powering the Arduino from a pack of 3 x AA alkaline cells (4.5v).

Exactly what sort of step-down device are you using? 48v to 5v is a big jump and may limit the available output current to a very low level

Another thought is to try a large (1000 micro farad ?) capacitor across the 5v power supply.

...R