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