NRF24L01 Module Issues

Hey all,
I am trying to use two NRF24L01 to communicate: one sends data from the A0 and A1 pins and the receiver transmits that to the serial monitor. They seem to be connecting fine, but when I use the serial monitor I just get lots of zeros even when I move the joysticks;
00
00
00
00
00
etc.

receiver code;

#include <SPI.h>

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}
void loop() {
  if (radio.available()) {
   int dataPackage[2];
    radio.read(&dataPackage, sizeof(dataPackage));
Serial.print(dataPackage[0]); Serial.print(" "); Serial.println(dataPackage[1]);
  }
}

transmitter code;

#include <SPI.h>

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}
void loop() {
  int dataPackage[] = {analogRead(A0), analogRead(A1)};
  radio.write(&dataPackage, sizeof(dataPackage));
 delay(5);
}

I have 10 uF electrolytic capacitors on both modules, and I have already done an independent test of the joysticks, in other words, everything hardware is A-ok.

Thanks,

  • D

test if this code works - only then you know of your setup is "OK"

(and then look at the example code)

Try a longer delay() between transmissions. Start with 1000 millisecs,

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

...R

You could try this, It complies ok and should work, I don't have my hardware to hand to test and I know the code should work.

You need to make sure that your CE and CSN pins are set up correct first. If you do not receive any data coming in from the TX unit the Rx flashes LED 13 and displays it on the Seral monitor.

Try it let us know how you get on.

Like Robin2 say's have a good read through the tutorial and try the samples, I did and have learnt a hell of a lot and this is how I got my modules working.

TX code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN   7
#define CSN_PIN 8
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

const uint64_t pipeOut = 0xB3B4B5B6A3LL;//0xE8E8F0F0E1LL; //IMPORTANT: The same as in the receiver

struct MyData {
  int   Channel1;
  int   Channel2;

};

MyData data;

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipeOut);

}

void loop() {

  data.Channel1 = analogRead(A0) ;
  data.Channel2 = analogRead(A1);
  radio.write(&data, sizeof(MyData));


}

RX code:

//####################################################
//# Include all the libraries                        #
//####################################################
#include  <Wire.h> //Wire libary 
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const uint64_t pipeIn =  0xB3B4B5B6A3LL;//0xE8E8F0F0E1LL64 bit encrypicted code
#define CE_PIN   7
#define CSN_PIN 8
const long TX_interval = 500;  //Error flag timer for not recieving from the tx
unsigned long lastRecvTime = 0; // escape from recieve data
unsigned long TX_previousMillis = 0; // stores the last mills
RF24 radio(CE_PIN, CSN_PIN);
bool newData = false;
bool lostData = false;
#define Error_led 13
struct MyData {
  int Channwl1_IN;
  int Channel2_IN;


};
MyData data;
void resetData()
{
  unsigned long TX_Error = millis();
  newData = false;
  if (TX_Error - TX_previousMillis >= TX_interval) {
    // save the last time you blinked the LED
    TX_previousMillis = TX_Error;
    digitalWrite(Error_led, !digitalRead(Error_led));
  }
  if (newData == false) { //new data received from eLevel
    //newData = false;
    Serial.println("TX SIGNAL LOST/NO SIGNAL");
  }
}
void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  radio.begin();
  radio.setDataRate(RF24_250KBPS); // Both endpoints must have this set the same
  radio.setAutoAck(false);
  radio.openReadingPipe(1, pipeIn);
  radio.startListening();
  resetData();
}//--(end setup )---


void recvData()
{
  while ( radio.available() ) {
    radio.read(&data, sizeof(MyData));
    lastRecvTime = millis();
    newData = true;
  }
}

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  recvData();
  showData();
  unsigned long now = millis();
  if ( now - lastRecvTime > 1000 ) { //if data stops coming IN within 1 second, lets us know
    // signal lost?
    resetData();
  }
}




void showData() {
  Serial.print("Channwl 1:" );
  Serial.print(data.Channwl1_IN);
  Serial.print(", ");
  Serial.print("Channwl 2:" );
  Serial.print(data.Channel2_IN);
  Serial.println("  ");


}

Steve

Steveiboy:
You could try this, It complies ok and should work, I don't have my hardware to hand to test

That's a very brave assertion where wireless is involved :slight_smile:

...R

It should work as it’s part of some code that I already use and the last time I shared that code on here in another topic it worked.

Means it was late last night I did I not have my hardware to hand to test it which I have set up in my workshop.

Steveiboy:
It should work as it’s part of some code that I already use and the last time I shared that code on here in another topic it worked.

Fair enough.

Your Reply #3 did not give the impression that you had successfully tested the same code with hardware on another occasion.

...R