those are new and i have just written them.
transmitting code
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9 , 10);
const byte slaveAddress[5] = {"BBBBB"};
char dataToSend[12] ={"Hello World"};
void setup() {
Serial.begin(9600);
radio.begin();
radio.setDataRate(RF24_2MBPS);
radio.openWritingPipe(slaveAddress);
radio.stopListening();
}
void loop() {
bool test;
test = radio.write(&dataToSend , sizeof(dataToSend) );
if(test)Serial.println("slave received the message");
else Serial.println("Failed");
delay(1000);
}
Receiving code
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9 , 10);
const byte theslave[5] = {"BBBBB"};
char dataReceived [12];
void setup() {
Serial.begin(9600);
radio.begin();
radio.setDataRate(RF24_2MBPS);
radio.openReadingPipe(1 , theslave);
radio.startListening();
}
void loop() {
if(radio.available())
{
radio.read(&dataReceived , sizeof(dataReceived));
Serial.print("you received ");
Serial.println(dataReceived);
}
else Serial.println("No Radio Available");
delay(1000);
}
so both of these worked as expected and on both arduino i switched the transmission and receiving on both of the arduinos and worked as expected.
now i tried a two way transmission
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9 , 10);
const byte slaveAddress[5] = {"BBBBB"};
const byte theslave [5] = {"AAAAA"};
char dataToSend[12] ={"Hello World"};
char dataReceived[3];
void setup() {
Serial.begin(9600);
radio.begin();
radio.setDataRate(RF24_2MBPS);
radio.openWritingPipe(slaveAddress);
radio.openReadingPipe(1 , theslave);
}
void loop() {
// doesnt work
//this should receive HI
radio.startListening();
if(radio.available())
{
radio.read(&dataReceived , sizeof(dataReceived));
Serial.print("you received ");
Serial.println(dataReceived);
}
else Serial.println("No Radio Available");
delay(1000);
// work
//this should transmit Hello world
radio.stopListening();
bool test;
test = radio.write(&dataToSend , sizeof(dataToSend) );
if(test)Serial.println("slave received the message");
else Serial.println("Failed");
Serial.println("");
delay(1000);
}
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9 , 10);
const byte theslave[5] = {"BBBBB"};
const byte slaveAddress[5] = {"AAAAA"};
char dataReceived [12];
char dataToSend[3] = {"HI"};
void setup() {
Serial.begin(9600);
radio.begin();
radio.setDataRate(RF24_2MBPS);
radio.openReadingPipe(1 , theslave);
radio.openWritingPipe(slaveAddress);
}
void loop() {
// doesnt work
// this should transmit HI
radio.stopListening();
bool test;
test = radio.write(&dataToSend , sizeof(dataToSend) );
if(test)Serial.println("slave received the message");
else Serial.println("Failed");
delay(1000);
// work
// this should receive Hello World
radio.startListening();
if(radio.available())
{
radio.read(&dataReceived , sizeof(dataReceived));
Serial.print("you received ");
Serial.println(dataReceived);
}
else Serial.println("No Radio Available");
Serial.println("");
delay(1000);
}
now this is confusing the first few statements doesn’t work but after it switch the mode of the nrf it works perfectly so the conclusion is that the first mode doesn’t work but it works after it
oh and it’s save to say that i have tested your two way transmission on both of my arduino switching roles between them and it worked , probably i am doing something silly that i cant see
Thank You <3.
EDIT:
yea i knew it i was doing something silly that i don’t really understood so i carefully read your code about two way transmission when i am sending the data i didn’t switch back to listening mode so i can see that the data has been sent or not i was still in stoplistening mode as you can see in my code so of course it wont know if the data has been received.
tell me if i am correct or not at this point? , now this code works fine on both of arduinos i am adding things up and i will hope to not be as silly as this time