DigitalRead multiple pins

I have a project using a Mega 2560 and several Uno modules to control motors.

The Mega reads a file on an SD card and then sends serial data to all the Unos.
Each Uno reads the data and then moves a motor.
Pin 7, output pin, on each Uno (Pin_Move) is switched between states when the motor moves and when the move is complete.

I want the Mega to wait for all of the motors to finish moving before the next line of the file is read. Pin 6 is the input pin and tied to all of the pin 7s of the UNO modules.

If I tie all of the Uno pin 7s together and set the state to low when moving and high when done moving, will this work? Will any pin bein low keep the tied pins low?

Is there a way to make this work with resistors to protect the Uno modules?

If you tie the pins together and any one is HIGH while any other one is LOW then the magic smoke will come out of your Arduino.

Delta_G:
magic smoke will come out of your Arduino.

can I use a resistor to ground?

Is there a way to do this easily?

Since the Mega is sending all this out on Serial, why don’t the UNOs answer over Serial?

Timing is an issue. One signal goes to all the Unos. They each read the part of the data they need. The timing of the movement is calculated so that they all take the same time to move regardless of the amount they move. There are physical variables that I can not test for such as resistance, etc. that might slow a motor. I was hoping to check them all from one pin instead of needing 12 input pins as I have 12 motors

Use diodes instead of resistors. That way you can create an OR gate. You will need a pull-down resistor in your case (as the signals from the other Arduinos can only pull up the line through the diode, when all are low you need this pull-down resistor to pull the line low), 10k will be a good value for this.

wvmarle:
Use diodes instead of resistors.

something like this?
ORgate.jpg

OPs image

Exactly, that idea.
Whenever any of those inputs is high, it’ll drive the Mega pin high (to about 4.5V due to the voltage drop over the diode). Only when all of them are low, the Mega pin will be pulled low (to GND).

wvmarle:
Exactly, that idea.
Whenever any of those inputs is high...

Thank you so much!

Just ordered the diodes!

I would treat it like an open drain bus the same way I2C signals work.
If you do this you won’t need any extra parts and you simply connect all the pins together to create a “status bus”.

To do this, put the mega pin reading the bus state to INPUT_PULLUP - or add an external pullup if you want more “snap” and a quicker rise time to reduce slew rate on the bus signal.
Then for the slaves that are driving the bus status signal, all they have to do is switch their pin from INPUT to OUTPUT and NEVER set their status pin on the bus to OUTPUT and HIGH.
This will naturally happen on a pin since the output bit in the port register defaults to zero.
If you simply use pinMode() to flip between input and output it will flip from the pin output from HIz to LOW output which is what you want.

Each slave can indicate its busy status by setting its pin to output mode which will drive the bus status signal low.
When the slave is no longer busy it sets its status pin to input mode which will stop its pin from driving the bus low.
If any slave is driving the bus low, the master will see a low and
when no slave is driving the bus low, the pullup on the bus (either from the masters internal pullup or an external pullup) will cause the master to see a high.

— bill

Indeed, that will work as well.

I had to re-read the original messages - thought the pins read by the Mega were the same that operate the motors, but it's a separate one that's used for this signal

The internal pull-up should do the job very well, there's probably very little stray capacitance on that bus and a couple hundred nanoseconds rise delay is not likely to mess up OP's application.

This way you must be REALLY careful to never set any of the connected pins to OUTPUT, HIGH, as that's going to kill at least one of the attached Arduinos. The diode solution is safer for that matter.

bperrybap:
I would treat it like an open drain bus the same way I2C signals work.

I had read about this somewhere and knew it was possible, I just did not remember how. Thank you.

Mark

wvmarle:
Indeed, that will work as well.

Thank you.

I agree the diodes are safer, and for that reason, I might go that route. Plus the fact that I already ordered the diodes, lol

thanks again

Otherwise just put your diodes in your box of goodies, together with all other parts ordered for projects of which the design changed before the parts actually arrived :slight_smile: Sooner or later you'll find a use for them.