Master working to send to two Receivers , now how to send back to the Master

Continuing the discussion from nrf24l01 project 4 transmitters and 12 receivers:

I have utilized this discussion and made modules that work one way with it, I now have tried many things and can't quite figure out either my addresses or how to send back from the Receivers to the Master. Here's my code so far, Im so close , Thanks

Master

//Master

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

RF24 radio(9, 10);
const byte address0[5] = {'R', 'x', 'A', 'A', 'M'};//Master
const byte address1[5] = {'R', 'x', 'A', 'A', 'A'};//Module_01
const byte address2[5] = {'R', 'x', 'A', 'A', 'B'};//Module_02
const byte address3[5] = {'R', 'x', 'A', 'A', 'C'};//Module_03
const byte address4[5] = {'R', 'x', 'A', 'A', 'D'};//Module_04

int PauseButton = 8;
int ResumeButton = A1;
int RedLed = 6;
int BlueLed = 4;

byte buttonTxData[2];
boolean PauseState = 0;
boolean ResumeState = 0;

byte button2RxData[2];
boolean RedState = button2RxData[0];//
boolean BlueState = button2RxData[0];//

void setup() {
  pinMode(PauseButton, INPUT_PULLUP);
  pinMode(ResumeButton, INPUT_PULLUP);
  pinMode(RedLed, OUTPUT);
  pinMode(BlueLed, OUTPUT);


  radio.begin();
  radio.setDataRate( RF24_250KBPS );
  radio.setPALevel(RF24_PA_MIN);
  radio.openReadingPipe(1, address2);
  radio.openReadingPipe(1, address1);  
  radio.startListening();
  radio.setRetries(5, 5);
  
  
}

void loop()
{

  ResumeState = digitalRead(ResumeButton);
  PauseState = digitalRead(PauseButton);



  send();
  Receive();
}

void send() {

  radio.stopListening();
  buttonTxData[0] = PauseState;
  buttonTxData[1] = ResumeState;

  radio.openWritingPipe(address1);
  radio.write(&buttonTxData, sizeof(buttonTxData));

  radio.openWritingPipe(address2);
  radio.write(&buttonTxData, sizeof(buttonTxData));


}
void Receive() {

  if (radio.available()) {
    radio.read(&button2RxData, sizeof(button2RxData));
    RedState = button2RxData[0];
    BlueState = button2RxData[1];
    if (RedState == LOW) {
      digitalWrite(RedLed, HIGH);
    }
    else {
      digitalWrite(RedLed, LOW);
    }
    if (BlueState == LOW) {
      digitalWrite(BlueLed, HIGH);
    }
    else {
      digitalWrite(BlueLed, LOW);
    }
  }
}

Receiver 2

//Module_02

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

RF24 radio(9, 10);
const byte address0[5] = {'R', 'x', 'A', 'A', 'M'};//Master
const byte address1[5] = {'R', 'x', 'A', 'A', 'A'};//
const byte address2[5] = {'R', 'x', 'A', 'A', 'B'};//This Module (02)
//const byte address3[5] = {'R', 'x', 'A', 'A', 'C'};//Module_03
//const byte address4[5] = {'R', 'x', 'A', 'A', 'D'};//Module_04

int ResumeLed = 4;
int PauseLed = A0;
int RedButton = 2;
int BlueButton = 3;

byte button2TxData[2];
boolean RedState = 0;
boolean BlueState = 0;

byte buttonRxData[2];
boolean PauseState = buttonRxData[0];
boolean ResumeState = buttonRxData[1];



void setup()
{
  pinMode(ResumeLed, OUTPUT);
  pinMode(PauseLed, OUTPUT);
  pinMode(RedButton, INPUT_PULLUP);
  pinMode(BlueButton, INPUT_PULLUP);

  radio.begin();
  radio.setDataRate( RF24_250KBPS );
  radio.setPALevel(RF24_PA_MIN);
  radio.openReadingPipe(1, address1);//1 is the master, Address1 is this address
 
  radio.startListening();
  radio.setRetries(3, 5);
}

void loop()
{
  RedState = digitalRead(RedButton);
  BlueState = digitalRead(BlueButton);

  //send();
  Receive();
}

void send() {
  
  radio.stopListening();
  button2TxData[0] = RedState;
  button2TxData[1] = BlueState;

 // radio.openWritingPipe(address2);
  //radio.write(&buttonTxData, sizeof(buttonTxData2));

  radio.openWritingPipe(address0);
  radio.write(&button2TxData, sizeof(button2TxData));

  //radio.openWritingPipe(address0);
 // radio.write(&button2TxData, sizeof(button2TxData));

  

}

void Receive() {

  if (radio.available()) {
    radio.read(&buttonRxData, sizeof(buttonRxData));
    PauseState = buttonRxData[0];
    ResumeState = buttonRxData[1];
    if (PauseState == LOW) {
      digitalWrite(PauseLed, HIGH);
    }
    else {
      digitalWrite(PauseLed, LOW);
    }
    if (ResumeState == LOW) {
      digitalWrite(ResumeLed, HIGH);
    }
    else {
      digitalWrite(ResumeLed, LOW);
    }
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.