Two arduinos, making one wait for the other

Hi all! This is my first time working with i2C communication and I have been googling a lot about it but can't seem to find the answer to one of my questions.

I have two arduino UNOs, one that communicates to a bunch of stepper motors and the other communicates to some sensors and one motor.

I wish to have the arduino with the sensors to communicate to the arduino with the motors to tell it which motors to run. But I wish to stop the arduino with the sensors from continuing with it's code until the motor has finished running. I wanted to do this using the sensor arduino as the master and the motor arduino as the slave. I can't find anywhere about making one arduino wait until the other one finishes anywhere and I was wondering how I would go about doing this.

Thank you for any input in advance!

You can always add an extra wire and use digitalWrite() on one Arduino and digitalRead() on the other Arduino.

The Master can tell the Slave if the Slave needs to wait or to stop.
When the Master should wait, then it can poll the Slave. For example 10 times per second.

rllohr:
I wish to have the arduino with the sensors to communicate to the arduino with the motors to tell it which motors to run. But I wish to stop the arduino with the sensors from continuing with it's code until the motor has finished running. I wanted to do this using the sensor arduino as the master and the motor arduino as the slave. I can't find anywhere about making one arduino wait until the other one finishes anywhere and I was wondering how I would go about doing this.

What is the reason you would like the master to wait? Do you struggle with the communication while the motor is running or do you want to ensure the motor moves to some set position before you continue.

The master should be able to write to the slave whenever it wants. The slave should be able to at least receive the commands and ether modify the behavior or ignore them. If you want application level control you could implement a "motor active" state variable that the master can read. That way the master can read the value after it sends a new command and only continues after the slave returns ready.

You could just send say for example ~ over the I2C line from the slave to the master when the stepper is turned to the desired spot. Then on the master side you could wait for the ~ and when it is received it would continue on.