0

I want to use a GPIO-out to talk to a GPIO-in... two different programs running on the same pi.

The program with the GPIO-in can be activated by either a button, or the other program... with the GPIO-out.

Right now I am using a relay module. The GPIO-out of activates the relay, relay's output, in parallel to the button, can send a signal to the other program.

Or should I be using an optocoupler? The only problem is it sometimes works and sometimes doesn't. I found a 3V relay module (because I was using a 5V before) and it doesn't seem to be much more reliable.

Right now I have something like this:

enter image description here

except my current iteration is using this 3V relay module that I found:

enter image description here

Is there a better way to connect an output to an input? Can I do it directly? To do that I guess I would have to make the input "active high" (if I am using the term correctly). Is it safe to go like this:

enter image description here

or should I be working harder to figure out when to pull up or down the input or output of the relay?

4
  • Why not combine the two programs into one?
    – CoderMike
    Nov 19, 2021 at 12:57
  • because I wrote the two programs in order to figure out how to connect an output to an input... so combining them into a single program would take away their reason to exist
    – Alex028502
    Nov 19, 2021 at 13:17
  • 1
    "Can I do it directly?" -> Yes.
    – goldilocks
    Nov 19, 2021 at 15:02
  • The great answers and comments I got to this question led me to this question: raspberrypi.stackexchange.com/questions/133537/…
    – Alex028502
    Nov 26, 2021 at 17:50

1 Answer 1

1

You can quite safely connect one Pi GPIO to another Pi GPIO.

To prevent all possibility of damage I suggest you have a 1k ohm or more resistor in series. This will limit the current to a safe level if you mistakenly set both GPIO to be outputs with one high and one low (in effect creating a short circuit).

4
  • In my diagram, the connection between the 3.3V pin and the input has no resistor... but really if you accidentally set the purple pin to low output (even though it is meant to be an input) the same thing could happen right? However, if I put a big resistor on both (the GPIO out and the the 3.3V connected to the switch) then the switch won't "win" when it is pressed, and the output is low... Do I just use a bigger resistor for the blue connection than the switch? like 1k between 3.3V and the switch, and 5k between the blue GPIO out and the purple?
    – Alex028502
    Nov 19, 2021 at 13:35
  • Or is it possible to switch the GPIO out between "floating" and high, rather than low and high, so that when it is not high, it doesn't interfere with the high signal coming from the swtich?
    – Alex028502
    Nov 19, 2021 at 13:37
  • 1
    If a GPIO is set as an output it must be high or low. If you leave the GPIO as an input you can set it a pull-high or pull-low or pull-none.
    – joan
    Nov 19, 2021 at 16:37
  • Thanks. I have asked another follow up question raspberrypi.stackexchange.com/questions/133537/…
    – Alex028502
    Nov 26, 2021 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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