Go Down

Topic: Problem in communication between NRF modules (Read 828 times) previous topic - next topic

srijay

Jun 18, 2018, 01:28 pm Last Edit: Jun 18, 2018, 01:46 pm by srijay
Hello,

I have being trying to establish communication between two NRF modules, but some reasons i am not able to rectify the problem.

According to me the program has no issues.

Please can anyone help !

Ill attach my code below for Tx and Rx.



Code: [Select]
[b]Transmitter:[/b]

#include <NewPing.h>
#include <MedianFilter.h>
#include <Wire.h>
#include <MedianFilter.h>

#define TRIGGER_PIN  3  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     4  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 450 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


#define CE_PIN   9
#define CSN_PIN 10

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

MedianFilter filter(31,0);

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

float dataToSend;
float txNum ;

void setup() {
 
   Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
   Serial.println("SimpleTx Starting");
   radio.begin();
   radio.setDataRate( RF24_250KBPS );
   radio.setRetries(4,15); // delay, count
   radio.openWritingPipe(0xF0F0F0F0FF);
 
 
}

void loop() {


  updateMessage();
  delay(50);
  send();
  delay(100);
}


void send()
{

   bool rslt;
   rslt = radio.write( &dataToSend, sizeof(dataToSend));
   Serial.print("Data Sent");
   Serial.print(dataToSend);
   
   if (rslt)
   {
       Serial.println("Acknowledge received");
   }
   else
   {
       Serial.println("Tx failed");
   }
}



void updateMessage()
{
 delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
 int txNum,uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
 filter.in(uS);
 txNum = filter.out();
 Serial.print("Ping: ");
 //Serial.print( txNum / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
 //Serial.println("cm");
 dataToSend = txNum / US_ROUNDTRIP_CM;
}






Code: [Select]
[b]Receiver[/b]
// SimpleRx - the slave or the receiver

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

#define CE_PIN   9
#define CSN_PIN 10

RF24 radio(CE_PIN, CSN_PIN);

int dataReceived;
bool newData = false;

void setup() {

   Serial.begin(115200);
   Serial.println("SimpleRx Starting");
   radio.begin();
   radio.setDataRate( RF24_250KBPS );
   
}


void loop()
{
   radio.openReadingPipe(0, 0xF0F0F0F0FF);
   radio.startListening();
   Serial.print("Pipe");
   getData();
   showData();
   delay(1000);
}


void getData() {
   if ( radio.available())
   {
       radio.read(&dataReceived, sizeof(dataReceived));
       newData = true;
   }
}


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

 [tt][/tt]



Robin2

Have a look at this Simple nRF24L01+ Tutorial.

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.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

srijay

#2
Jun 18, 2018, 02:50 pm Last Edit: Jun 18, 2018, 02:53 pm by srijay
Actually its similar to your program. There are some things which i have changed in Transmitter module. That's all.

I am not getting any errors in program.

The problem is its not able to communicate.


Whandall

Move
Code: [Select]
   radio.openReadingPipe(0, 0xF0F0F0F0FF);
   radio.startListening();
from loop to setup.

So the receiver at least gets a chance to receive something.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

Robin2

#4
Jun 18, 2018, 05:48 pm Last Edit: Jun 18, 2018, 05:49 pm by Robin2
Actually its similar to your program.
I did not recognize it because my examples don't use NewPing.

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

Also start by getting the example code to work without any changes.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

srijay

#5
Jun 18, 2018, 06:41 pm Last Edit: Jun 18, 2018, 06:45 pm by srijay
Move
Code: [Select]
  radio.openReadingPipe(0, 0xF0F0F0F0FF);
   radio.startListening();

from loop to setup.

So the receiver at least gets a chance to receive something.
Thank you for the suggestion.

Its actually working but the receiver is not receiving the exact data.

I mean it should receive some sensor value but received 0 is displayed

srijay

Hey thanks Whandall . Its working perfectly fine.

Thank you.

Appreciate you !

srijay

#7
Jun 19, 2018, 01:42 pm Last Edit: Jun 19, 2018, 01:42 pm by srijay
Hello,

It is necessary to connect 10uf capacitor to the Vcc and Gnd pin of NRF module.

In my case the connections are correct.
Problem is it only Send data for the first time. Then it automatically disconnects.

Please suggest any solution.

Thank you.

skywatch

I suggest that you post your code for both ends. Then we have something to go on. :smiley-confuse:

srijay

Receiver
Code: [Select]
// SimpleRx - the slave or the receiver

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

#define CE_PIN   9
#define CSN_PIN 10

RF24 radio(CE_PIN, CSN_PIN);

float dataReceived;
bool newData = false;

void setup()
{

    Serial.begin(115200);
    Serial.println("SimpleRx Starting");
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(0, 0xF0F0F0F0FF);
    radio.startListening();   
}

void loop()
{
    Serial.print("Pipe");
    getData();
    showData();
    delay(1000);
}


void getData()
{
    if ( radio.available())
    {
        radio.read(&dataReceived, sizeof(dataReceived));
        newData = true;
    }
}


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




Transmitter


Code: [Select]
#include <NewPing.h>
#include <MedianFilter.h>
#include <Wire.h>
#include <MedianFilter.h>

#define TRIGGER_PIN  3  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     4  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 500 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


#define CE_PIN   9
#define CSN_PIN 10

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

MedianFilter filter(31,0);

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

float dataToSend;
float txNum ;

void setup() {
 
    Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
    Serial.println("SimpleTx Starting");
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(4,15); // delay, count
    radio.openWritingPipe(0xF0F0F0F0FF);
 
 
}

void loop() {


   updateMessage();
   delay(50);
   send();
   delay(100);
}


void send()
{

    bool rslt;
    rslt = radio.write( &dataToSend, sizeof(dataToSend));
    Serial.print("Data Sent");
    Serial.print(dataToSend);
   
    if (rslt)
    {
        Serial.println("Acknowledge received");
    }
    else
    {
        Serial.println("Tx failed");
    }
}



void updateMessage()
{
  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  int txNum,uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  filter.in(uS);
  txNum = filter.out();
  Serial.print("Ping: ");
  //Serial.print( txNum / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
  //Serial.println("cm");
  dataToSend = txNum / US_ROUNDTRIP_CM;
}

srijay

#10
Jun 19, 2018, 04:36 pm Last Edit: Jun 19, 2018, 07:59 pm by srijay
Only when i press reset button on the Tx side the first acknowledgement is received.

Then no communication takes place.......

Confused......

Please find the screenshot of COM port......

Robin2

That looks very like the code in your other Thread. Why have you started a new Thread? I am not going to answer the same questions twice.

I suggest you click Report to Moderator and ask to have the two Threads merged. Then we will have all the info in one place.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Robin2

Please display your image(s) in your post so we can see it(them) without downloading it(them). See this  Simple Image Guide

If the image is simply a picture of text, then please just copy and paste the text as it makes it much easier to read.


Have you got your two Arduinos communicating perfectly with one of the examples from my tutorial with no changes and no additions to the code?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

srijay

No i m not getting the output.

But i am able to get response from the example Getting started.


Robin2

#14
Jun 20, 2018, 09:25 am Last Edit: Jun 20, 2018, 09:27 am by Robin2
No i m not getting the output.

But i am able to get response from the example Getting started.
I presume this refers to my example programs.

If so please post the two program that YOU have uploaded to your Arduinos and also post an example of the output that each program produces.

I can understand if all this seems very tedious but debugging wireless problems is not easy.


Have you tried the connection-test program? IIRC it is in Reply #29 in my tutorial?

Have you a spare nRF24 that you can use to check if one of the others is faulty?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up