Re-connection of Input and Output pins during operation

Hi!
I don't know much about electronics - but I am trying to find my way through the internet as much as possible.
Today:) I have an idea for a childrens-toy by connecting 2 to N Arduinos, this is the reason for the peculiar query.

As a prototype I am thinking of connecting two Arduinos (A and B) together by assigning two pins on each: Input and Output.

It is a requirement, that during operation, it can be (re-)connected three wires
from the Output of A to the Input of B and
from the Input of A to the Output of B and
from GND on A to GND on B.

This connection can be plugged an unplugged frequently during operation.

I wish to send some simple signals back and forth between A and B - when these are connected.
The arduinos will frequently set the Output pin High/Low in an attempt to signal any receiving Arduino.

My idea at the moment, is that regarding the Input pins - I will chose to create a circuit on the receiving Arduino as if it was a pushbutton there.
(like this: https://www.arduino.cc/en/Tutorial/Button)
I will just let the signal flow from Output of one arduino into the Input of the other as if the other Arduino was a pushbutton.

Then, I am wondering if I need to do something special with the Output pins on the Arduinos to cope with this "connect-disconnect" scenario.

The distance between the Arduinos can be like 5m - 10m. I can chose to use rather thick wires.

I am aware that I can use WiFi - and I am thinking to use it together with this somehow, but these "cables" are a part of the game.

My question is if such a circuit can work? Will I ruin any of the pins by doing this? Do you have some other robust circuits to propose to deal with re-connections?

Medhu

This can be done, you don't really need to do anything if
a) You can't interchange the connections
b) Both Arduino's are always powered at the same time.

b is the biggest trick because otherwise you may phantom power the off Arduino which can damage it.

Second is the cable length, that will pick up noise. Thick cables will not help you there. I would add propper filtering in the input.

To combine those two I would add a nice RC filter at the input and a reasonable pull up resistor. Last mainly to pull the pin to a known state when the other Arduino is disconnected. Someone will probably have a schematic on hand for you, I don't at the moment :stuck_out_tongue:

But what are you trying to send over? If it's just a simple state (like on or off) then yes, this can work. But if the data gets more complex I would rather use communication hardware like serial or I2C. But both are not designed for long cables! But there are chips to extend it like going to RS485 for the serial.

Thanks for answer.

a) I was thinking to arrange so that you can't plug Input to Input or Output to Output, by "clever choice of plugs".

b) I didn't think about this ... and I don't think I can guarantee that they are both powered
and I cannot guarantee that one of them run out of battery.

Lets see if someone can guide me to a circuit that can be helpful. In meantime I check what I can do with the RS-485.

If I could manage to stagger accross 8 bits somehow during 1-2 seconds that would be plenty cool.

Medhu

b) I didn't think about this ... and I don't think I can guarantee that they are both powered
and I cannot guarantee that one of them run out of battery.

Then put a 10K in series with each I/O line pair.

To overcome b, there must be a large enough resistor inline with the output so it's not able to phantom power the other.

OR, don't drive the output high ever. This might sound silly but it is not :stuck_out_tongue: Think about it, this is what a switch with a pull up does. Only drive the input high via a pull up resistor on the input Arduino side. Add a cap to GND for filtering and let the output Arduino only switch between low and floating. Last can be done by calling pinMode(pin, INPUT).

Or with this function I used

enum digital3State_t{FLOAT = 2}; //place this somewhere global

void digital3State(byte pin, byte mode){
  switch(mode){
    case 0:
      digitalWrite(pin, LOW);
      pinMode(pin, OUTPUT);
      break;
    case 1:
      pinMode(pin, OUTPUT);
      digitalWrite(pin, HIGH);
      break;
    case 2:
      pinMode(pin, INPUT);
      break;
  }

//now you can call it like
digital3State(pin, LOW); //or
digital3State(pin, HIGH); //or
digital3State(pin, FLOAT);
}

This has the advantage of not requiring a lot of components and the system will default to high when nothing is connected (aka, make that the inactive state). Although an extra resistor inline would not hurt (if you pick it an order of magnitude lower then the pull up).

How do you plug in N units? I created a system once which had 4 ports per unit on some devices and only 1 port on the 'end' devices. I had to put in a lot of the 4 port ones because adding one only added 2 additional ports. (I had to pull out one end device to add a 4-port and plug that into the new one, so the net addition was only 2.)

It would have been much better to use a bus type system like CAN Bus where an unlimited number can connect to one wire.

I didn't explain that "N" very well.

What I had in mind was to dedicate 2 pins to one cable going to one another Arduino B - and another 2 pins for another cable going to an Arduino C...These 3 Arduino could be connected and know by the signals what other Arduino they were connected to...

The idea is to create some childrens toy - so don't insert common sense / good design etc here :smiley:

I have actually started to think that the signal through the cable is not necessary at all... I might just need a way for each Arduino to figure out exactly which cable it is connected to - and based on this two Arduino can agree over wifi if they are connected to the same cable..

(Apologize for talking to myself....)
Medhu

So it's always a line? -B-A-C- (with unconnected ports hanging off the ends of the line)?

What if they plug enough together to make a circle? Why can't they make branches and choices?

If the main communication is WiFi, then I'd have them touch to set the order/priority and then they can be uncoupled and operated independently.

I doubt that using Wifi will simplify things...

Why not use something like RS485? That even makes data transfer possible very easy :slight_smile:

Thanks all for showing interest in my question.

I am reading into RS485; it might be the wheel I need to re-invent :slight_smile:

Does RS485 cope with the re-connections/re-plugging, units that are turned off etc?

Medhu

That is something I'm not 100% sure but I think it does. It's also used in DMX lighting and I never came across a problem when a turned off light is connected to a DMX source.

Only thing is, you do need to think the circuit layout trough.

Another option would be to go for wireless (but I think I would go for nRF24L01+ instead of WiFi and missing with SSID's). And instead of real communication between the Arduino's you fake it :smiley: You just make a cable which has GND, Vcc and a sense and on the other side you just make a resistor divider to send a voltage back over the sense wire. But this sense and Vcc are not connected to the actual Arduino aka no possibility to phantom power anything. And the received voltage can be an identification for the connected Arduino (just read it with analogRead()) and then use wireless for the data.

This works well if Arduino A is kind of the main Arduino and all others only connect to A, not to each other. Does your system have a "main" Arduino which can take the roll of a master?

But yeah, doing things wireless is a new can of worms so I might just stick with RS485 of some sense.

Perhaps use opto-couplers? No danger of phantom powering and no need to share ground either.

For a 10m wiring run standard logic signals will bounce and reflect and pick up crosstalk - standard
opto-couplers act as mild low-pass filters which will reduce reflections and crosstalk a lot.

(Standard logic signals have rise times of a few nanoseconds, opto-couplers are a few microseconds)