Nrf24l01 two way communication

Can anyone tell me why this does not work and how I can fix it. I have tried everything I could think of and still can't get it to work. I have removed all my code except for the portions I think are pertinate.

Master:
'''

#include <SPI.h>
#include <RF24.h>
RF24 radio(9,10); // CE, CSN

const byte Master[6] = "mmmmm";
const byte Slave[6] = "sssss";
double myData [4];

void setup() 
{
/********************************************************************************************
  //Radio 
  radio.begin();
  radio.setPALevel(RF24_PA_MIN);
  radio.setDataRate( RF24_250KBPS );
  }

void loop() 
  {
   myData[0]=3;
   radio.stopListening();
   radio.openWritingPipe(Master); 
   radio.write(&myData,sizeof(myData));         //send request for data
   
   //Data Read ---   open to received data
   radio.openReadingPipe(2,Slave);
   radio.startListening();
   radio.read(&myData,sizeof(myData));
   }
'''

slave:
'''
#include <SPI.h>
#include <RF24.h>
RF24 radio(9,10);       // CE, CSN
const byte Master[6] = "mmmmm";
const byte Slave[6] = "sssss";
double myData [4]= {3, 75,76,30};
bool success;

 
void setup() 
  {
  //** Radio ************************************************
  radio.begin();
  radio.setPALevel(RF24_PA_MIN);
  radio.setDataRate( RF24_250KBPS );
  }

  
void loop() 
 {
 radio.openReadingPipe(1,Master);
 radio.startListening();
 myData[0]=0;
 
 radio.read( &myData, sizeof(myData) );
 if(myData[0] == 3)                                  // respond only if for 3
   { 
    radio.stopListening();
    radio.openWritingPipe(Slave);                    
    // note: a routine is called here to load myData
    radio.write(&myData, sizeof(myData));             //Send data to master
    }   
    delay (3000);
 }

Explanation of what works and what doesn't:

The master code will send myData to the Slave.
The slave will read it and try to send it back with new data to the Master
The send to Master fails and the Master never receives the return data

and I have studied a lot of totorial, but none do what I am attempting
and have not been any help
'''Preformatted text

Missing open brace for Master void setup()

Perhaps you can explain what doesn't work?

Have you followed the tutorials to check basic module connectivity and communication?

I would suggest post #1, followed by post #30 and then post #2.

You can also help yourself by reading the forum guidelines on how to correctly post your code.

1 Like

Thanks, but it was in the original code, I just missed it in the copy here

void setup() has no open brace.

Explanation of what works and what doesn't:

The master code will send myData to the Slave.
The slave will read it and try to send it back with new data to the Master
The send to Master fails and the Master never receives the return data

and I have studied a lot of totorial, but none do what I am attempting
and have not been any help

Why is there no if (radio.available()) { ?

I took out the if(radio.available) because the code would stop there.
it did not find the radio.available and I was simplifying the code.

There seems to be a problem with a read and then switching to
write to the same radio.

on some other iterations of code, with multiple slaves, I sometimes got
at response to the Master, but it came for a different slave than the one
communicating.

Good luck with that approach. I'm out.

The code in Robin2's tutorial (linked by @markd833) is proven to work. Proven by myself and many others. If that example code does not work for you there is a hardware problem.

Once you get the simple code to work there is a swap roles example.

I just pasted in the code from Robin2 for the 2way example and it does not work. I even tried it with another set of boards.

I give up. Lots of information here but nothing to solve my problem.
I posted a simple example of the problem and there is no solution, just
referring me to some other stuff which I pasted into my two setups and it did not work. I am using a LGT8f328P for my processor and a nrf24l01 for the radio. It is easy to refer me to other documentation. but why not simply state what is wrong with the code I included. It is short and to the point.

I have spent weeks reading of examples and tutorials, but they do not help.

How are the radio modules powered?

How are the radio modules wired?

Did you read the tutorial or just copy the code?

1 Like

radio modules are powered from the 3.3 v pin of the arduino board.
Wiring is correct. I have read many tutorials. If it is so obvious, why
can't someone just point out what is missing or incorrect in my code.

or are you saying the code is correct and something else is the problem

That might be something or it might be nothing. I'm not familiar with the 328P clone (I think that's what it is). Maybe somebody with experience of that chip could advise you further.

EDIT: What was displayed when you ran the CheckConnection.ino sketches on your hardware?

Do you think its possible the modules are faulty ?

Hi, @jmgera
Welcome to the forum.

Can you please tell us your electronics, programming, arduino, hardware experience?

Can you please post some images of your project so we can see your component layout?

Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.
NOT a copy of the circuit you are using from online, reverse engineer your projects and draw a diagram.

Can please post a link to the "LGT8f328P" processor board you are using?

Sorry for all the questions but;
You have the project infront of you, we don't.
You know how it is wired, we don't.
You know how you are powering the project we don't.

Do you have a DMM? (Digital MultiMeter)

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

@jmgera Can't comment if the code is correct (that is virtually impossible without a formal, mathematical spec), but these modules are widely believed to have peak power consumption much higher than the data sheets. The 3.3V pin may well not be able to deliver the required peak current leading to aberrant behaviour from the NRF24L01.

If you started with a series of simpler scenarios (@Robin2 's check connect, then a simple one way transmission test ... then you're whole app) you'd at least be able to identify what is wrong.

what do you mean you can't comment on the correctness of the code. It is either correct or not. If it is correct then there is a possible hardware problem.

and by the way I checked the voltage on the 3.3 arduino pin and it IS 3.3 or greater volts on each board

And when I reverse the code on each slave and master. I get the same results. it transmits in one direction ( master to slave) but fails to respond in the opposite direction (slave to master). I suspect there is a timing or buffer problem, but no one on this forum seems to be able to see that or have an answer.

I am not new to this. I have had many successful arduino projects. I asked for someone to verify or point out an error in my code. why can't anyone read the code and understand it? What you are asking for is excessive and lacks answering my original question of: is the code correct or what is wrong or missing in the code. If the code is correct THEN I can look for other posibilities. This is not my first project with arduino. I have successfully created many other projects that work.

The voltage at the pin is rarely the cause of problems. It is the available current when the NRF transmits that is the usual problem. A DVM cannot register the voltage drop during the milliseconds that it takes for a transmission to occur.
Try two AA cells in series for the NRF power with the negative also connected to the Arduino ground.