Master and Slave 2 way communication with 3 arduinos

So I have an Arduino mega and two Arduino unos. The unos are connected to individual stepper motors that run through a homing procedure with two limit switches. the number of steps for each stepper is counted on its respective uno (only needs to happen once). I then want to send these 2 numbers to the mega. next, I want to send 2 numbers from the mega inputted into the serial monitor which will be sent back to the unos and correspond to the step positions for each uno(needs to happen repeatedly).

At first, I tried using Serial Communication with the code below but I would just get zeros or even nothing in return. I checked the individual unos and they would print the max distance to the serial monitor so the mega was just not reading it. I believe I read somewhere that you can only use one serial com at a time so does this mean that it is not viable for my application?

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial2.begin(9600);
  
 //get the max distance of each stepper motor
 while((Serial1.available()>0) && (Serial2.available()>0)){
   int Max_Dis1 = Serial1.parseInt();
   int Max_Dis2 = Serial2.parseInt();
   }
  
 delay(100);
}

I have also been reading up on I2C since i found out that you can send data both ways however I am not sure how to manage the 3 devices

mega code:

void setup() {
  Serial.begin(9600);
  Wire.begin(1);
  Wire.begin(2);
  
  Wire.requestFrom(1,6);
  while(Wire.available())
  {
    char maxDist1 = Wire.read();
    Serial.println(maxDist1);
  }
  
  delay(1000);
  
  Wire.requestFrom(2,6);
  while(Wire.available())
  {
    char maxDist2 = Wire.read();
    Serial.println(maxDist2);
  }
  }

then in the slaves, I use the Wire.onRequest(requestEvent) function

any suggestions would be appreciated! Additionally, if you have any resources for something similar you can point me towards that would help out alot. Thank you!

The Mega has four serial ports, so you can use one port to connect to one other Arduino.

However it sounds like you don’t actually need more than one Arduino it is just that you need to program the one you have a bit better. Many beginners are quick to jump to multiple Arduinos rather than learn to code better.

I agree with @Grumpy_Mike that your Mega is probably capable of doing the entire job on its own.

If you do need to use 3 Arduinos then the business of effective communication between them is primarily a matter of thinking and planning rather than programming.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.

You can send data in a compatible format with code like this (or the equivalent in any other programming language)

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

However these techniques must be used as part of a carefully planned communication strategy.

…R

Thank you @Robin2 and @Grumpy_Mike ! you are completely right with the newbies jumping to multiple arduinos quickly. I was just concerned with being able to run both stepper motors simultaneously plus controlling 2 linear actuators at the same time but I found an example from the accelstepper library that will allow me to do just that. I'll definitely save that serial Input basic link because that was exactly the info I was looking for and I might need to implement it later on in the project. Thanks again!

Two steppers, two actuators and taking commands over the Serial interface is nothing for an Arduino. Even when it also has to monitor a bunch of end stops.
An Uno will do all this easily, the only reason to go for a Mega may be the greater number of pins, though probably an Uno has enough for this, depends on how many pins your specific stepper setup requires and what else there may be connected.