1
\$\begingroup\$

I'm working on piece of software for Raspberry Pi and I'm writing an integration test. One of the cases requires that I'm able to read a state of one pin on another (basically if one output pin is high - another input pin should also be high, and vice-versa).

What's the safest way to connect one pin to another so that:

a) Regardless of software settings (Pin is out/in, high or low), there's never a dangerous short.

b) The state of the IN pin is never "floating" (which is the reason for using pull-downs/pull-ups from what I understood)

schematic

simulate this circuit – Schematic created using CircuitLab

Basically is R2 needed?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ This site features a schematic editor. Press CTRL+M while editing, or press the schematic editor button in the editing toolbar. \$\endgroup\$ – efox29 Sep 27 '15 at 4:22
  • \$\begingroup\$ I copy pasted the schematic from software documentation, but thanks for the tip! \$\endgroup\$ – Marcin Raczkowski Sep 27 '15 at 4:23
  • \$\begingroup\$ You need to explain what you're trying to protect against. What in particular do you mean by 'floating state'? You're worried you might accidentally tristate an output? Hard to comment because it's hard to understand your goals. \$\endgroup\$ – Daniel Sep 27 '15 at 4:37
  • \$\begingroup\$ Ok. So there are two things. one is to protect a RPi against shorts (which can result for example when both pins are set to out and one is High, second is Low), and to make sure the state on input is correct high or low, and it's not floating. I assume that's the reason you attach pull down in case of switch. \$\endgroup\$ – Marcin Raczkowski Sep 27 '15 at 4:41
1
\$\begingroup\$

You connect pin b "Input" to a pull up or pull down to force a known state incase pin A "output" is in a floating state. You connect pin a with pin b with a high ohm resistor of 10k~100k ohm resistor to prevent a high current flow if pin a and b are both accidently outputs with different levels. That's to prevent a high to low short.

As most systems can deal with the temporary floating pin, just the precautionary resistor between pin a and b is needed. A pull down/up pin can result in a unnecessary battery drain.

\$\endgroup\$
2
  • \$\begingroup\$ So there's no way for in pin to be in floating state once output is set to LOW even if pull-down (R2) is missing? \$\endgroup\$ – Marcin Raczkowski Sep 27 '15 at 5:47
  • \$\begingroup\$ If pin A output is in a known state, pin b, through the series resistor, will be in the same state, if pin B is in input/high z mode. \$\endgroup\$ – Passerby Sep 27 '15 at 5:55
1
\$\begingroup\$

Your schematic should work fairly well for the isolation between two GPIOs. (R2 is a good idea but not absolutely needed).

There are some considerations to take into account though.

  1. If some GPIO Bs on your MCU board already have existing pullups it can make the series R1 resistor act as the lower resistor in a voltage divider when GPIO A is in a low state. This could cause the "low" seen at GPIO B to be too high to be reliably detected as a '0'.

  2. If some GPIO Bs on your MCU board already have existing pull downs it can make the series R1 resistor act as the upper resistor in a voltage divider when GPIO A is in a high state. This could cause the "high" seen at GPIO B to be too low to be reliably detected as a '1'.

  3. If some of the GPIO Bs are connected to other logic on the board there could be conflicts with trying to get the signal through the isolation circuit.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.