NRF24L01 - 1 Master and 2 Slaves

Hi everyone, I'm writing after 2 days to try to understand why my wi-fi network doesn't work. My intention is to use one Transmitter ( Master ) to send data to other two slaves that need just reading data and using the keyboard library to print one word.

Actually I don't receive any output even from the serial print, could you help me and suggest how to fix my problem, thanks

The code from Tx is that:

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

RF24 radio(7,8);

const byte numSlaves = 2;
const byte slaveAddress[numSlaves][6] = {"00001","00002"};

const int button_shot[numSlaves]={3}; // button set
  
bool button_state_shot[numSlaves]={0};

void setup() {

    Serial.begin(9600);
    radio.begin();
    radio.setAutoAck(true);
    //radio.setDataRate(RF24_2MBPS);                                                                      //radio.setPALevel(RF24_PA_MIN);                // You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
    radio.setPALevel(RF24_PA_LOW);
    radio.enableAckPayload();
    radio.enableDynamicPayloads();

    pinMode(button_shot[numSlaves], INPUT_PULLUP);

}


void loop() {
  for(int i=0; i<numSlaves; i++){
    button_state_shot[i] = digitalRead(button_shot[i]);
    //radio.stopListening();
    radio.openWritingPipe(slaveAddress[i]);

    if (button_state_shot[i] == LOW)                       // SHOT
        {
            const char text[] = "112!";                     // print "p"
            radio.write(&text, sizeof(text));               // Sending the message to receiver
        }
   }
}

on the other hand, the Slave code ( is almost the same for both slaves for that reason I'm gonna attach only one )

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

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";

char * key;
int keyInt;
int key1_verify = 0;

void setup() {
    Serial.begin(9600);
    radio.begin();
    radio.setAutoAck(true);
    radio.enableAckPayload();
    radio.openReadingPipe(0, address);
    //radio.setDataRate(RF24_2MBPS);                                                                      //radio.setPALevel(RF24_PA_MIN);                // You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
    //radio.setPALevel(RF24_PA_LOW);
    radio.enableAckPayload();
}

void loop() {
      radio.startListening();
    char text[32] = "";
    radio.read(&text, sizeof(text));
  
    char cmd1[6] = "-----";                                     //Space for saving the incoming data (Joistick)
    int cmd1_i = 0;
        char cmd2[6] = "-----";
        int cmd2_i = 0;
        int readvalue = 0;

    for ( int i = 0; i < strlen(text); ++i ){                   // cicle to read value from radio signal and store them 
            if(text[i] == "!"){
                break;
            }
            if(text[i] == '+')
            {
                readvalue = 1;
                continue;
            }
            if ( readvalue == 0 )
            {
                cmd1[cmd1_i] = text[i];
                cmd1_i++;
            }
            else
            {
                cmd2[cmd2_i] = text[i];
                cmd2_i++;
            }
        } 

    int key1=atoi(cmd1);

    if( key1 == 116 ){
        Keyboard.press(key1);
        delay(100);
        Keyboard.releaseAll();
        }
}

The transmitter misses a stopListening() call in setup.

The receiver should only call startListening() in setup, not each time loop repeats.
The receiver does not use available(), but just reads non-existent pachets.

Why do you enableAckPayload() without using ack payloads?
Why don't you use the length provided via dynamicPayloads?

I followed a guide that I found on arduino forum and I tried to replicate it. Anyway I move startListening() in setup and stoListening() as well but it doesn't work yet.

Tx code:

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

RF24 radio(7,8);

const byte numSlaves = 2;
const byte slaveAddress[numSlaves][6] = {"00001","00002"};

const int button_shot[numSlaves]={3}; // button set
  
bool button_state_shot[numSlaves]={0};

void setup() {

    Serial.begin(9600);
    radio.begin();
    radio.setAutoAck(true);
    radio.setDataRate(RF24_2MBPS);                                                                      //radio.setPALevel(RF24_PA_MIN);                // You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
    radio.setPALevel(RF24_PA_LOW);
    radio.stopListening();

    pinMode(button_shot[numSlaves], INPUT_PULLUP);

}


void loop() {
  for(int i=0; i<numSlaves; i++){
    button_state_shot[i] = digitalRead(button_shot[i]);
    radio.openWritingPipe(slaveAddress[i]);

    if (button_state_shot[i] == LOW)                       // SHOT
        {
            const char text[] = "112!";                     // print "p"
            radio.write(&text, sizeof(text));               // Sending the message to receiver
        }
   }
}

Rx code:

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

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";

char * key;
int keyInt;
int key1_verify = 0;

void setup() {
    Serial.begin(9600);
    radio.begin();
    radio.openReadingPipe(0, address);
    radio.setDataRate(RF24_2MBPS);                                                                          radio.setPALevel(RF24_PA_MIN);                // You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
    radio.setPALevel(RF24_PA_LOW);
    radio.startListening();
}

void loop() {
    char text[32] = "";
    radio.read(&text, sizeof(text));
  
    char cmd1[6] = "-----";                                     //Space for saving the incoming data (Joistick)
    int cmd1_i = 0;
        char cmd2[6] = "-----";
        int cmd2_i = 0;
        int readvalue = 0;

    for ( int i = 0; i < strlen(text); ++i ){                   // cicle to read value from radio signal and store them 
            if(text[i] == "!"){
                break;
            }
            if(text[i] == '+')
            {
                readvalue = 1;
                continue;
            }
            if ( readvalue == 0 )
            {
                cmd1[cmd1_i] = text[i];
                cmd1_i++;
            }
            else
            {
                cmd2[cmd2_i] = text[i];
                cmd2_i++;
            }
        } 

    int key1=atoi(cmd1);

    if( key1 == 116 ){
        Keyboard.press(key1);
        delay(100);
        Keyboard.releaseAll();
        }
}

If you want to transfer ints, why do you send them as strings?

Your polling approach will not work with four clients and a constant payload.

Why don't you care about the result of the radio.write?

Have you tested the connection of all NRFs?

I used the atoi function in order to translate byte in value so I'm able to print that signal sending through the char text. I tried using only one channel and it works, the problem is when I add another channel to the transmitter that it doesn't work

You don't answer my questions, so good luck.