Go Down

Topic: NRF24L01 PA PL (Bidirectional String)  (Read 880 times) previous topic - next topic

Br_italia

Jan 09, 2019, 10:35 pm Last Edit: Jan 09, 2019, 10:50 pm by Br_italia
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();
 }
}


Robin2

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

Br_italia

Have a look at the second example in this Simple nRF24L01+ Tutorial

...R

Hello R, thanks for the reply. Unfortunately the link shows the error msg :-(

Robin2

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
Two or three hours spent thinking and reading documentation solves most programming problems.

Br_italia

#4
Jan 11, 2019, 06:48 pm Last Edit: Jan 11, 2019, 07:21 pm by Br_italia
What error message? I just tried my link now and it worked as expected.

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

Br_italia

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 !

Robin2

Images from Reply #4 so we don't have to download them. See this  Simple Image Guide





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

Robin2

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
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up