I am currently making a two way morse code communication system, I have been able to get it working one way, but as soon as I try making it communicate back and forth I lose connection.
I have tried:
-Checking wiring (everything is correct)
-Adding delays into code
-Changing where it says radio.stopListening(); and radio.startListening();
-changing ce/csn pins
Here's my code
//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int pin = 5;
//create an RF24 object
RF24 radio(10, 8); // CE, CSN
//address through which two modules communicate.
const byte address[6] = "00001";
//set variables for inputs
int bs1;
#define bp1 2
void setup() {
Serial.begin(9600);
radio.begin();
//set the address
radio.openWritingPipe(address);
Serial.println("Begin sending");
//Set module as transmitter
radio.stopListening();
}
void loop() {
//Read buttons
bs1 = digitalRead(bp1);
delay(500);
Serial.println(bs1);
radio.write(&bs1, sizeof(bs1));
//Set module as reciever
radio.startListening();
if (radio.available())
{
//print to the serial monitor if connection is established
Serial.println("Connection established");
//decode data
boolean bs1;
radio.read(&bs1,sizeof(bs1));
Serial.println("Button stat");
Serial.println(bs1);
delay(500);
if(bs1 == 0){
digitalWrite(pin, HIGH);
delay(500);
}
else{
digitalWrite(pin, LOW);
}
}
else{
Serial.println("NO CONNECTION");
radio.stopListening();
}
}
Hmmmm. Where does your code switch from sending to waiting for something to receive? Remember, this it alternating between sending and receiving, not doing both at the same time. You likely need some code to tell the receiver to begin sending, now, while you wait for a message coming back.
Of course there is, but you must be able to tell which unit to go first and then eventually tell the second unit it is your turn to send while the first listens.
Paul
From my understanding, the "reply Payload" must already be in the TX FIFO before even receiving the message from the transmitter, i.e. the reply can't be dependent on the content of message of the transmitter.