Nrf24l01 modules not connecting to each other

Hello :wave: everyone my name is Andre Sanchez Harris and am a newbie to the nrf24l01 modules, i am working on a drone project using nrf modules to communicate with each other, i have written my code for both the receiver and transmitter board using the arduino nano 328p for the receiver board and the arduino uno r3 board for the transmitter board, bought two pairs of nrf modules (nrf24l01+ and the nrf24l01+pa/lna) which i connected the nrf24l01+ module to my nano board connection the SCK pin to D13, MOSI pin to D11, MISO pin to D12, CE pin to D7, CSN pin to D8, VCC pin to 3.3volt pin of the nano and GND to GND repeat the same thing with the nrf24l01+pa/lna on the arduino uno r3 board but with the VCC pin connected to 2 pairs of AA Alkaline batteries and the GND to GND and then applied a capacitor of 100uf to the vcc and gnd of both modules. Then uploaded their respective codes to the arduino boards but after all of this, i couldn't get the modules to communication with each other, so please any help and advice i could get from you guys here will be very helpful and i would much appreciate it, thank u.

Welcome to the forum

Why did you start your topic in one of the Covid-19 Response categories of the forum ?

Your topic has been moved to the Programming Questions category. Please be more careful where you create new topics

I am not clear from your description how things are connected, particularly the power connections

Please post a schematic of your circuits. A 'photo of a hand drawn circuit is good enough

Also post your sketches, using code tags when you do.

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Here is my transmitter code :

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

/Create a unique pipe out. The receiver has to
wear the same unique code
/

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

RF24 radio(7, 8); // select CE and CSN pins

// Define pins
const int ledPin = 9; // This is the led pin number
const int buzzerPin = 3; // This is the buzzer pin number

// The sizeof this struct should not exceed 32 bytes
// This gives us up to 32 8 bits channals
struct MyData {
byte throttle;
byte yaw;
byte pitch;
byte roll;
byte AUX1;
byte AUX2;
};

MyData data;

void resetData() {
//This are the start values of each channal
// Throttle is 0 in order to stop the motors
//127 is the middle value of the 10ADC.
data.throttle = 0;
data.yaw = 127;
data.pitch = 127;
data.roll = 127;
data.AUX1 = 0;
data.AUX2 = 0;
}

void setup() {
//Start everything up
Serial.begin(9600);
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.setChannel(100);
radio.openWritingPipe(pipeOut);
radio.setPALevel(RF24_PA_LOW);
resetData();

radio.stopListening(); //sets the module as transmitter

radio.printDetails();

pinMode(ledPin, OUTPUT); // Set the led pin as output

pinMode(buzzerPin, OUTPUT); // Set the buzzer pin as output
}

/**************************************************/

// Returns a corrected value for a joystick position that takes into account
// the values of the outer extents and the middle of the joystick range.
int mapJoystickValues(int val, int lower, int middle, int upper, bool reverse) {
val = constrain(val, lower, upper);
if ( val < middle )
val = map(val, lower, middle, 0, 128);
else
val = map(val, middle, upper, 128, 255);
return ( reverse ? 255 - val : val );
}

void loop() {

// Function to blink the led if the transmitter is powered on
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);

// The calibration numbers used here should be measured
// for your joysticks and potentiometer till they send the correct values.
data.throttle = mapJoystickValues( analogRead(A1), 13, 524, 1015, true );
data.yaw = mapJoystickValues( analogRead(A2), 1, 505, 1020, true );
data.pitch = mapJoystickValues( analogRead(A0), 12, 544, 1021, true );
data.roll = mapJoystickValues( analogRead(A3), 34, 522, 1020, true );
data.AUX1 = digitalRead(4);
data.AUX2 = digitalRead(2);

// Function to check if the receiver is available
if (radio.available()) {
// Turn on the buzzer and led if connected to the receiver
digitalWrite(buzzerPin, HIGH);
delay(100);
digitalWrite(buzzerPin, LOW);
delay(100);
digitalWrite(buzzerPin, HIGH);
delay(100);
digitalWrite(buzzerPin, LOW);
digitalWrite(ledPin, HIGH);

// Function to transmit the data wirelessly
radio.write(&data, sizeof(MyData));
}
} Use code tags to format code for the forum

strong text
Here is my receiver code :

#include "Arduino.h"
#include "config.h"
#include "def.h"
#include "types.h"
#include "MultiWii.h"
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Tone.h>
#include "NRF24_RX.h"

#if defined(NRF24_RX)

int16_t nrf24_rcData[RC_CHANS];

// Single radio pipe address for the 2 nodes to communicate.
static const uint64_t pipeIn = 0xE8E8F0F0E1LL; //Remember, SAME AS TRANSMITTER CODE

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

// Define pins
const int ledPin = 4;
const int escPin = 10;
const int speakerPin = 2;

RF24Data MyData;
RF24AckPayload nrf24AckPayload;
extern RF24AckPayload nrf24AckPayload;

void resetRF24Data() {
MyData.throttle = 0;
MyData.yaw = 128;
MyData.pitch = 128;
MyData.roll = 128;

//Same as the transmitter code
MyData.AUX1 = 0;
MyData.AUX2 = 0;
MyData.switches = 0;
}

void resetRF24AckPayload() {
nrf24AckPayload.lat = 0;
nrf24AckPayload.lon = 0;
nrf24AckPayload.heading = 0;
nrf24AckPayload.pitch = 0;
nrf24AckPayload.roll = 0;
nrf24AckPayload.alt = 0;
nrf24AckPayload.flags = 0;
}

void NRF24_Init() {

resetRF24Data();
resetRF24AckPayload();
Serial.begin(9600);
tone.begin();
radio.begin(); radio.setDataRate(RF24_250KBPS); radio.setAutoAck(false); // Ensure autoACK is enabled
//radio.enableAckPayload();

radio.setChannel(100);
radio.openReadingPipe(1,pipeIn);

radio.startListening(); // Sets the module as receiver

radio.printDetails();

pinMode(ledPin, OUTPUT); // Set led pin as output

pinMode(escPin, OUTPUT);
pinMode(speakerPin, OUTPUT);

// Play a 440 Hz square wave on the speaker pin
tone(speakerPin, 440);
delay(100);
// Play a 261 Hz square wave on the speaker pin
tone(speakerPin, 261);
delay(100);
noTone(speakerPin);

// Function to move the camera up and down when board is powered on or reset
digitalWrite(escPin, HIGH);
delay(100);
digitalWrite(escPin, LOW);
}

void NRF24_Read_RC() {

// This function blinks the led when the receiver is being powered on
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(2000);

// Function to check if the radio is available
if ( radio.available()) {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
}

static unsigned long lastRecvTime = 0;

nrf24AckPayload.lat = 35.62;
nrf24AckPayload.lon = 139.68;
nrf24AckPayload.heading = att.heading;
nrf24AckPayload.pitch = att.angle[PITCH];
nrf24AckPayload.roll = att.angle[ROLL];
nrf24AckPayload.alt = alt.EstAlt;
memcpy(&nrf24AckPayload.flags, &f, 1); // first byte of status flags

unsigned long now = millis();

while ( radio.available()) {
radio.writeAckPayload(1, &nrf24AckPayload, sizeof(RF24AckPayload));
radio.read(&MyData, sizeof(RF24Data));
lastRecvTime = now;
}
if ( now - lastRecvTime > 10000 ) {
// signal lost?
resetRF24Data();
}

nrf24_rcData[THROTTLE] = map(MyData.throttle, 0, 255, 1000, 2000); //If your channels are inverted, reverse the map value. Example. From 1000 to 2000 ---> 2000 to 1000
nrf24_rcData[ROLL] = map(MyData.roll, 0, 255, 1000, 2000);
nrf24_rcData[PITCH] = map(MyData.pitch, 0, 255, 1000, 2000);
nrf24_rcData[YAW] = map(MyData.yaw, 0, 255, 1000, 2000);
nrf24_rcData[AUX1] = map(MyData.AUX1, 0, 1, 1000, 2000);
nrf24_rcData[AUX2] = map(MyData.AUX2, 0, 1, 1000, 2000);
}

#endifUse code tags to format code for the forum

Did you miss the request to post code using code tags and the description of how to do it easily ?

Yes sir.

Then please edit your post and add the code tags

Please also post the contents of NRF24_RX.h, using code tags when you do


#include "Arduino.h"
#include "config.h"
#include "def.h"
#include "types.h"
#include "MultiWii.h"
#include <SPI.h>
#include <nRF24L01.h>  
#include <RF24.h>
#include <Tone.h>
#include "NRF24_RX.h"

#if defined(NRF24_RX)

int16_t nrf24_rcData[RC_CHANS];

// Single radio pipe address for the 2 nodes to communicate.
static const uint64_t pipeIn = 0xE8E8F0F0E1LL;  //Remember, SAME AS TRANSMITTER CODE

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

 // Define pins
const int ledPin = 4; 
const int escPin = 10;
const int speakerPin = 2;

RF24Data MyData;
RF24AckPayload nrf24AckPayload;
extern RF24AckPayload nrf24AckPayload;

void resetRF24Data() {
  MyData.throttle = 0;
  MyData.yaw = 128;
  MyData.pitch = 128;
  MyData.roll = 128;

  //Same as the transmitter code
  MyData.AUX1 = 0;
  MyData.AUX2 = 0;
  MyData.switches = 0;
}

void resetRF24AckPayload() {
  nrf24AckPayload.lat = 0;
  nrf24AckPayload.lon = 0;
  nrf24AckPayload.heading = 0;
  nrf24AckPayload.pitch = 0;
  nrf24AckPayload.roll = 0;
  nrf24AckPayload.alt = 0;
  nrf24AckPayload.flags = 0;
}

void NRF24_Init() {

  resetRF24Data();
  resetRF24AckPayload();
  Serial.begin(9600);
  tone.begin();
  radio.begin(); radio.setDataRate(RF24_250KBPS); radio.setAutoAck(false);                    // Ensure autoACK is enabled
 //radio.enableAckPayload();
  
  radio.setChannel(100);
  radio.openReadingPipe(1,pipeIn);

  radio.startListening();  // Sets the module as receiver 

 radio.printDetails();

pinMode(ledPin,  OUTPUT);  // Set led pin as output 

pinMode(escPin,  OUTPUT);
pinMode(speakerPin,  OUTPUT);

// Play a 440 Hz square wave on the speaker pin
  tone(speakerPin,  440);
delay(100);
// Play a 261 Hz square wave on the speaker pin
  tone(speakerPin,  261);
delay(100);
noTone(speakerPin);

 // Function to move the camera up and down when board is powered on or reset 
digitalWrite(escPin,  HIGH);
delay(100);
digitalWrite(escPin,  LOW);
} 

void NRF24_Read_RC()  {

// This function blinks the led when the receiver is being powered on 
digitalWrite(ledPin,  HIGH);
delay(50);
digitalWrite(ledPin,  LOW);
delay(2000);

// Function to check if the radio is available 
if ( radio.available()) { 
 digitalWrite(ledPin,  HIGH);
 delay(1000);
 digitalWrite(ledPin,   LOW);
} 

  static unsigned long lastRecvTime = 0;

  nrf24AckPayload.lat = 35.62;
  nrf24AckPayload.lon = 139.68;
  nrf24AckPayload.heading = att.heading;
  nrf24AckPayload.pitch = att.angle[PITCH];
  nrf24AckPayload.roll = att.angle[ROLL];
  nrf24AckPayload.alt = alt.EstAlt;
  memcpy(&nrf24AckPayload.flags, &f, 1); // first byte of status flags
	
  unsigned long now = millis();  

  while ( radio.available()) { 
    radio.writeAckPayload(1, &nrf24AckPayload, sizeof(RF24AckPayload));  
    radio.read(&MyData, sizeof(RF24Data));
    lastRecvTime = now;
} 
  if ( now - lastRecvTime > 10000 ) {
    // signal lost?
    resetRF24Data();
} 

  nrf24_rcData[THROTTLE] =  map(MyData.throttle, 0, 255, 1000,  2000); //If your channels are inverted, reverse the map value. Example. From 1000 to 2000 ---> 2000 to 1000
  nrf24_rcData[ROLL] =      map(MyData.roll,      0, 255, 1000, 2000);
  nrf24_rcData[PITCH] =     map(MyData.pitch,    0, 255, 1000,  2000);
  nrf24_rcData[YAW] =       map(MyData.yaw,     0, 255, 1000, 2000);
  nrf24_rcData[AUX1] =       map(MyData.AUX1,     0, 1, 1000, 2000);
  nrf24_rcData[AUX2] =       map(MyData.AUX2,    0, 1, 1000, 2000);
} 

#endif

Wow :open_mouth:, that's so surprising coz have been thinking my receiver is bad all along but as for the spare boards, i do have 5 spare of nrf and 9 spare of boards left but another thing is that, when i power up my transmitter the buzzer keeps on activating itself indicating that it is connected to the receiver where as it has not if (radio.available() { digitalWrite(buzzerPin, HIGH); delay(100); digitalWrite(buzzerPin, LOW); delay(100); digitalWrite(buzzerPin, HIGH); delay(100); digitalWrite(buzzerPin, LOW); digitalWrite(ledPin, HIGH); } this line of the code is suppose to control the buzzer and led when the TX is connected to the RX but it is rather doing the opposite, so i am suspecting my microcontroller board becoz i had detached the nrf24l01+pa+lna from it's socket but the sequence still continues until i had to reprogram the board and cycle power to it again.

Have you posted the receiver code twice by mistake ?

Did you miss this ?

Why have you marked the topic as solved ?

after radio.begin() you should check if the device is connected, e.g.

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("ESP32_S3 > NRF24L01 Receive text");
  radio.begin();
  if (radio.isChipConnected())
    Serial.println("Receiver NF24 connected to SPI");
  else {
    Serial.println("NF24 is NOT connected to SPI");
    while (1)
      ;
  }

if NF24 is NOT connected to SPI is displayed you wiring is faulty or device is faulty, etc etc

have a look at esp32-s3-wroom1-and-nrf24l01-not-working

Oh so sorry about the inconsistent duplication of the code.
Here is the NRF24_RX.h contents :

/* Tested with 16MHz ATmega328p-AP, QuadX and https://github.com/gcopeland/RF24
Motors use pins 9,6,5,3 instead of 9,10,11,3
nRF24 connections (left is nRF24, right is arduino):q
  CE      7
  CSN    8
  MOSI   11
  MISO   12
  SCK    13
You can change CE and CSN in NRF24_RX.cpp
*/

#ifndef NRF24_RX_H_
#define NRF24_RX_H_

#include "config.h"

#if defined(NRF24_RX)

// The sizeof this struct should not exceed 32 bytes
struct RF24Data {
  byte throttle;
  byte yaw;
  byte pitch;
  byte roll;
  byte AUX1;
  byte AUX2;
  byte switches;
};

struct RF24AckPayload {
  float lat;
  float lon;
  int16_t heading;
  int16_t pitch;
  int16_t roll;  
  int32_t alt;
  byte flags;
};

extern RF24Data nrf24Data;
extern RF24AckPayload nrf24AckPayload;
extern int16_t nrf24_rcData[RC_CHANS];

void NRF24_Init();
void NRF24_Read_RC();

#endif

#endif /* NRF24_RX_H_ */
#if defined(NRF24_RX)

Where is NRF24_RX #defined in your sketches or libraries #included by your sketch ?

From the multiwii config.h file sir.


Here is my receiver schematics.

It is not the NRF24_RX file that I am asking about

The whole of the code in your receiver sketch depends on the NRF24_RX macro being #defined

As an experiment change

#include "NRF24_RX.h"

#if defined(NRF24_RX)

to

#include "NRF24_RX.h"
#define NRF24_RX
#if defined(NRF24_RX)

and try compiling the sketch

Ok ill do just that sir.


Here is my transmitter schematics sir.

Already tried this sir but nothing seems to work.