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
//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
#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();
}
}