Connecting GPIO1 to GPIO2 Raspberry Pi

I have this idea of setting modes by connecting IOs.

This is just some pseudo code as example.

gpio.init_out(21,22);
gpio.set_high(21);
gpio.set_low(22);

gpio.init_as_pull_down(13);
If (gpio.get(13).get_state_bool()) {
   println("connected to gpio 21");
} else {
   println("connected to gpio 22"); // or maybe disconnected.
}

Instinctual I feel like I need a resistor, or some kind of load between each pin.
Not entirely sure what a sensible value would be, or even if I’m seeing ghosts and I can connect them dry.
I couldn’t see anything on the RPi Docs either.

Anyone done this before?

1 Like

If we think about what we normally do with the pins we should be about to work out what will or wont work.
Lets start with the “pin as input”. With this it should end up in high impedance thus allow very little current to flow. You then have 4 Main choices.

  1. External Pull up
  2. External Pull Down
  3. Internal Pull Up
  4. Internal Pull Down.
    The use of external pull up/down give you more control over the strength as you can set the value of the resistor, when using internal it will be what ever is inside the controller.

So if we stick with internal pull up/down, we now need to work out which one.
If you use a pull down, then the default state will be “low” and with a “pull up” the default state will be “high”. defaults states can be good as floating will lead to an unknown state.

So now if we look at the “Set/Output” Pin. as an output it will either be high Vcc or low Gnd.

So if we use the internal pull up - what does this look like

When the output pin is High
Vcc → Internal Resistor → GPIOx (As input) → GPIOy (As output) → Vcc (So no current flow and Input will see “high”

When the output pin is low
Vcc → Internal Resistor → GPIOx (As input) → GPIOy (As output) → ground (So current flow as the “output” GPIO will pull down the voltage and drain to ground via the pull up resister. The Input pin will now see a low

So if we use the internal pull down - what does this look like

When the output pin is High
Gnd → Internal Resistor → GPIOx (As input) → GPIOy (As output) → Vcc (So current will flow from the output pin to ground via the pull down resistor. this will let the input pin see a high level.

When the output pin is low
Gnd → Internal Resistor → GPIOx (As input) → GPIOy (As output) → ground (So no current flow. The Input pin will now see a low level

So that seems OK, BUT we need to keep in mind what could happen.

Let say at boot or a coding error.
If Both are output, then nothing should sink any power.
If Both are input, no pull up/down then to power to flow anywhere.
If Both are output, with a pull up/down then that’s via the internal resistor.

Edit:
The main thing I can see as not a good idea would be connecting two output GPIO together. If one was High and the other low, that would be a short to ground. This is where an inline resister would provide some protection to some bad code..
Just need to consider the values to ensure safe currents and the voltage divider you would create is ok so the input pin will still see a “high” voltage.

Note: any current draw / sink must be writhing the safe range for the controller you are using; so always check the datasheet.

1 Like

Hi @Michael99645
Are you trying to illustrate that the internal resistor is always somewhere in the chain and so it’s safe to not to include any external components?

1 Like

HiMichael., Pix
Wow. Pull ups, downs, sideways, back. You name it you will probably get it.

GPIO configured as OUTPUT. I think this would depend on what type of output. Common Collector (or Drain) certainly needs a pull up somewhere. BUT I think most are push pull and are DRIVEN high and low with the GPIO being high impedance when configured as input. Now I don’t know what a pull up or down would do here. It could upset something else, these chips seem to be full of constant current supplies for bias purposes so I would not like to guess. With pull ups (downs) all over the place you could have some phantom voltage dividers preventing a transition fully high or low.

In a nutshell I don’t think you should use Pull ups or downs on an output. Being driven they should not be required as they should never be floating.

It follows then that in all probability the output will be connected directly to an input so pull ups should not be required or used here either.

If Pull??? are used as Michael says look out fore device current and voltage limits. Also for divider problems.

It could be argued that I2C “Requires” pull ups. I think that is because at the slave end something is open collector (Drain). Don’t know for sure. Mostly details on these devices is pretty sketchy or non existent. It would seem most if not all I2C devices are fitted with these and some without any easy way to remove them. 10k and 4k7 being popular values. Now the I2C system might be able to handle 127 addresses but I bet it won’t handle 127 pull ups without smoke from somewhere or some other sort of failure or problem.

Cheers Bob

1 Like

Hi Pix

It is there but does not have to be used. Arduino needs to declare its use with INPUT Pull up and I think RPi is the same. Not sure about that.
Cheers Bob

1 Like

I tried to go over the way I look at it, but final checks with the data sheet for your specific controller should happen.
When a GPIO is set as input, the actual “measurement” part should be high impendence and just check if the voltage is at some limit and then tags it as H or L.

the Pull up/down on the Input Pin is added to ensure there is no float depending on how the external circuit works. e.g. If you thing Pin → Button to Ground. when they button is NOT pressed the pull up will ensure a high level, then when the button is pressed, it will pull down that Voltage close to 0 and the pull up limits the current from Vcc.

So all of that is ok… BUT, and this may or may not be protected.

GPIO when set as output and set to low, could just be a “short” to ground (or close enough). and when set high is a short to Vcc (or close enough. IF the controller has current limit that may protetect it, but you may want to have “less” current to keep the totals low.
If we assum the above to be true (and it may very from controller to controller), then if you have 2 output pins, one set High and the Other set low, then THAT becomes a short from Vcc to Ground and if the controller does not look after that, that will fry something.
So if you think that will never happen, well maybe. but you need to consider what happens at boot time and/or if some other firmware got flashed…

So I would say that if everything is configured OK, then you may not need one, but for safety, I would consider some form of current limiting just in case.

edit:
While not for the pi, the concepts to look out for with some nice images.

1 Like

Hi Michael

Very true. Pix original query is connecting a GPIO output to another GPIO input. In a perfect rose coloured world 2 output GPIO connected together SHOULD not happen.

BUT!!! We don’t live in a perfect world and as you rightly point out the big unknown is boot time and any other flashing that might happen. According to Murphy anything can and will happen to make things awkward.

So you could say as a blanket statement DON"T DO IT until you are sure of EXACTLY what happens with different scenarios.

That is what an adjustable current limiting bench power supply is for. If you have this facility that is what your prime power source should be during any experimental or development phase. Wiring up, connecting everything including power and switching on can often be a disaster and provide plenty of magic smoke. Can be a trouble shooting aid too when looking for obscure short circuits. Set a convenient (and safe) current level, connect up then run around a board or other DUT and check for hot components or area of board. This usually isolates the problem area. Your finger as a sensor is OK.
Cheers Bob

1 Like

Lot’s to read through here.

Looks like my instincts were on point and an external resistor is required particularly because the I don’t have any control over the environment code or otherwise.

What I’m looking for in the datasheets is a diagram like this.
Something where the Raspberry pi datasheets shows the values I’m working with.
They do clarify the value of the pull-ups = 47k but they don’t mention anything else.

1 Like

Just surfing and this could be old


src: GPIO Electrical Specifications, Raspberry Pi Input and Output Pin Voltage and Current Capability

2 Likes

Op Amps.
Source looks reputable.

With op amps on the circuit external resistor would be redundant.

Thanks @Michael99645

p.s.
This is the best I have from RP official

1 Like

Yeah, maybe :slight_smile: I think for others reading, what is important is to check how “their” controller of choice works. I do know the pin to pin when both are outputs is a high level caution on the ESP32

Hi All

Should be high level caution on everything.
Cheers Bob

1 Like

There is that one case when both are outputs.
If I were paranoid I could try to think of some weird transistor gate.

I have the advantage that outputs are always HIGH, never low.

Like maybe I could do this, where I’m simulating GPIO 22&23 as input, and 21 as out.
I’m using low logic levels to simulate an input.
Works fine.
Screen Recording 2025-09-22 at 3.36.14 pm-Animated Image (Large)

But if I accidentally set both 22 & 23 as output the PNP seizes up.
Screen Recording 2025-09-22 at 3.36.30 pm-Animated Image (Large)

Not sure this is required but then raspberry pis are expensive and it would suck to break one. Cheaper to fork out $8 for a couple of dozen transistors.

Hi Pix
Not rocket science.
In the top pic (22 & 23 low) the PNP transistor is ON. The voltage at the collector will be almost 3.3V
In the top pic (22 & 23 high) the PNP transistor will be OFF or very close to it. The voltage at the collector will be 1.99V assuming the “H” is 3.3V. This is because the 2k, 4k6 and 10k form a voltage divider with the 1.99V across the 10k.
Cheers Bob

What does the sim do if you have 2 output pins connected to each other, then set one to High and one to Low ?

Falstad doesn’t like it for some reason. Treats it like a short and refuses to run.
If a GPIO is outputting low into the base of the transistor I can confidently say bad things will happen :frowning:

I’d love to buy a nicer sim some day :slight_smile:

Yep and that was the “gotcha” in the docs. one output High connected to an output Low. and output to an input should be ok but…

I haven’t been concerned because my idea never has low outputs.

I might need to think of a circuit to enforce that behavior.

Hi Pix

That is because it IS a short. Michael already flagged that earlier.

The transistor will turn on. If that is what you want then that is how to do it. That is how PNP transistors work. The opposite to NPN. The PNP and NPN reversed is the clue here.

KiCad has a rudimentary one built in. I don’t know how good it is or how complex you can go. Will look into it one day.
You can pay thousands for complex packages but I think some are pretty reasonable. Analog devices have I think a free one which is geared for their devices. You can make up your own models I think but that is past my pay scale.

I have a Windows version of TINA which is pretty good. My version is a bit old now but I really can’t justify upgrading. Does what I need so is OK for the moment. My PC of choice these days is a Mac so to use TINA on this I would have to subscribe to the cloud version which as I say for my use I can’t justify.

I think some of the third party Sims use TINA as a base engine. Some of the user interfaces are suspiciously similar.
Cheers Bob

1 Like

Hi Pix

There is a logic gate device that may interest you. Particularly for this application. I still haven’t figured out what you are trying to do or just as important why you want to connect 2 GPIO together.
It is an EXCLUSIVE OR gate, expressed as XOR.
This differs from an OR gate in the following way.
An OR will have a HIGH output when either one or both inputs is HIGH.
An XOR will have a high output when ONE and ONLY ONE input is HIGH. That means that if both inputs are the same (HIGH or LOW) the output is always LOW.

You might (probably will) think up a use for this useful little gem.
Not terribly common but very useful.
Cheers Bob

4070, 74LS86, 74HC86