How can connect 2 bluetooth masters with 2 bluetooth slaves?

Hi.

my project has problem about bluetooth connection (multiple) with arduino.

In my project, 3 'arduino pro mini boards'(hereinafter referred to as the "Board") and 4 HC-05 bluetooth modules are used.

I had want to connect one master bluetooth module with two slave module before.

But I soon found out that 'HC-05' was not having 1:n connection function.

Therefore, i had decided to use 2:2 bluetooth connection as shown in attach image file 'circuit'.

And actually, it was almost done.

When i confirm that 1:1 connection between each slave and master, each slave had been send character signal ('A') well to each master.

But, problem was appeared when i control two masters at the same time.

in my code, master board could receive data from slave 2 only when 'bluetooth1.begin(9600)' was declared after 'bluetooth2.begin(9600)'

on the contrary, master board could receive data from slave 1 only, if 'bluetooth2.begin(9600)' was declared after 'bluetooth1.begin(9600)'

I tried to search for some examples of 2:2 Bluetooth communication or 1:n communication, but I couldn't find a suitable example.

But I can't find the right solution, i decide to asking for help to arduino forum.

Attached are the associated codes.

Master's board code

#include <SoftwareSerial.h>

SoftwareSerial bluetooth1(3,4);
SoftwareSerial bluetooth2(11,10);

#define LEDpin1 5
#define LEDpin2 6


char data1;
char data2;

void setup(){
  pinMode(LEDpin1, OUTPUT);
  Serial.begin(9600);
  bluetooth1.begin(9600);
  bluetooth2.begin(9600);
}

void loop(){
 if(bluetooth1.available() > 0){                                                                                                                                                                                                                                             
    data1 = bluetooth1.read();
    Serial.print("data1 = ");
    Serial.println(data1);
    if(data1 = 'A'){  
      digitalWrite(LEDpin1,HIGH); 
      delay(200);
      digitalWrite(LEDpin1,LOW);
      }
    }
 else if(bluetooth2.available() > 0){ 
    data2 = bluetooth2.read();
        Serial.print("data2 = ");
    Serial.println(data2);
    if(data2 = 'A'){
      digitalWrite(LEDpin2,HIGH); 
      delay(200);
      digitalWrite(LEDpin2,LOW);
      } 
}
}

Slave 1's board code

#include <SoftwareSerial.h>

SoftwareSerial bluetooth1(3,4); //slave1
#define button 2

char clicked = 'A'; // SLAVE1
unsigned long pre_time = 0;
unsigned long cur_time = 0;
const int duration = 30 ; 

void setup(){
  pinMode(button, INPUT_PULLUP);
  Serial.begin(9600);
  bluetooth1.begin(9600);
  attachInterrupt(digitalPinToInterrupt(button), CLICKED, RISING);
}
void loop(){
  }

void CLICKED(){
    cur_time = millis();
   if(cur_time - pre_time >= duration) {
    bluetooth1.write(clicked);
    Serial.write(clicked);
    pre_time = cur_time;
   }
}

Slave 2's board code

#include <SoftwareSerial.h>

SoftwareSerial bluetooth2(11,10); // slave2
#define button 2

char clicked = 'A'; // SLAVE2
unsigned long pre_time = 0;
unsigned long cur_time = 0;
const int duration = 30 ; 

void setup(){
  pinMode(button, INPUT_PULLUP);
  Serial.begin(9600);
  bluetooth2.begin(9600);
  attachInterrupt(digitalPinToInterrupt(button), CLICKED, RISING);
}
void loop(){
  }

void CLICKED(){
    cur_time = millis();
   if(cur_time - pre_time >= duration) {
    bluetooth2.write(clicked);
    Serial.write(clicked);
    pre_time = cur_time;
   }
}

koriente:
I tried to search for some examples of 2:2 Bluetooth communication or 1:n communication, but I couldn't find a suitable example.

No surprise there, it is a really bad idea, and using software serial twice is probably an equally bad idea. You are probably better off ditching Bluetooth, and using an NRF24 network, which is made for this sort of thing.

If you insist on using Blueteeth, you might consider having one master, and that is powered from a digital pin, thereby being under software control. It also requires another wire to the Key pin, also under software control. This means you can put it into AT mode, and configure it to automatically connect to each slave in turn.

If sequential connection to the slaves is not a proposition, you could try retaining the second master, but running it on hardware serial.