Arduino Forum

Using Arduino => Networking, Protocols, and Devices => Topic started by: Br_italia on Jan 09, 2019, 10:35 pm

Title: NRF24L01 PA PL (Bidirectional String)
Post by: Br_italia on Jan 09, 2019, 10:35 pm
Does anyone know or have a sketch that sends a string to another arduino (A), using NRF24L01 PA PL, and the other arduino (B) "responds" by sending another string?

Example:
Arduino A sends a "test" message to the Arduino B
Arduino B "answer" by sending an "OK" message to the Arduino A

I have an example that only sends msg, but not "answer".

Regads, Bruno.


Arduino A: Transmissor
Code: [Select]


//TRANSMISSOR
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

RF24 radio(9, 10);
const uint64_t pipe = 0xF0F0F0F0E1LL;
void setup()
{
radio.begin();
radio.setRetries(2, 5);
radio.openWritingPipe(pipe);
radio.stopListening();
 
}

void loop()
{
  
        // send to arduino B
        radio.openWritingPipe(pipe);
        radio.stopListening();
        const char text[32] = "TEST";
        radio.write(&text, sizeof(text));
        delay(200);
        
        // Receive from Arduino B
        radio.openReadingPipe(1, pipe);
        radio.startListening();
        char text2[32] = {0};
        radio.read(&text2, sizeof(text2));
        Serial.println(text2);
        delay(100);
    
}



---------------------------------------------------------------------------



RECEPTOR: ARDUINO B
Code: [Select]

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


RF24 radio(9, 10);
const uint64_t pipe = 0xF0F0F0F0E1LL;


void setup()
{
Serial.begin(9600);
radio.begin();
  radio.setRetries(2, 5);
  radio.openReadingPipe(1, pipe);
radio.startListening();
}

void loop()
{

  // Receiving Arduino A
  if (radio.available())
 {
  char text[32] = {0};
  radio.read(&text, sizeof(text));
  Serial.println(text);
  delay(100);
 
    
      // Send to Arduino A
      radio.openWritingPipe(pipe);
      radio.stopListening();
      const char text2[32] = "TEST";
      radio.write(&text2, sizeof(text2));
      delay(100);
      radio.openReadingPipe(1, pipe);
      radio.startListening();
 }
}

Title: Re: NRF24L01 PA PL (Bidirectional String)
Post by: Robin2 on Jan 10, 2019, 10:09 am
Have a look at the second example in this Simple nRF24L01+ Tutorial (http://forum.arduino.cc/index.php?topic=421081)

...R
Title: Re: NRF24L01 PA PL (Bidirectional String)
Post by: Br_italia on Jan 10, 2019, 10:50 pm
Have a look at the second example in this Simple nRF24L01+ Tutorial (http://forum.arduino.cc/index.php?topic=421081)

...R

Hello R, thanks for the reply. Unfortunately the link shows the error msg :-(
Title: Re: NRF24L01 PA PL (Bidirectional String)
Post by: Robin2 on Jan 10, 2019, 11:14 pm
Hello R, thanks for the reply. Unfortunately the link shows the error msg :-(
What error message? I just tried my link now and it worked as expected.

...R
Title: Re: NRF24L01 PA PL (Bidirectional String)
Post by: Br_italia on Jan 11, 2019, 06:48 pm
What error message? I just tried my link now and it worked as expected.

...R
See the picture, it just does not work. :(

Title: Re: NRF24L01 PA PL (Bidirectional String)
Post by: Br_italia on Jan 11, 2019, 07:58 pm
What error message? I just tried my link now and it worked as expected.

...R
Can you send a print of the result in serial.monitor?

Tks !
Title: Re: NRF24L01 PA PL (Bidirectional String)
Post by: Robin2 on Jan 11, 2019, 11:40 pm
Images from Reply #4 so we don't have to download them. See this  Simple Image Guide (http://forum.arduino.cc/index.php?topic=519037)





...R
Title: Re: NRF24L01 PA PL (Bidirectional String)
Post by: Robin2 on Jan 11, 2019, 11:44 pm
Please don't post pictures of text - they are almost impossible to read. Just copy and paste the text.

I take it from your images that when you said "Unfortunately the link shows the error msg" what you really meant was that when you tried the program in my link there was a problem. Successful computer programming demands precision.

Have you tried the connection-test program in my tutorial to see if your Arduinos can successfully communicate with the nRF24 it is connected to?

...R