I am having some issues trying to read 3.3v directly from the same Raspberry. I tried the next connections:

With the first case, using a direct connection to 3.3 v I did not have a problem. The problem is that if I connect a 1K resistor between the GPIO and the 3.3 v, the GPIO does not detect the signal as a "1".

The rare thing is that yesterday I changed from the GPIO 27 to the GPIO 20, and firstly it worked with that 1K resistor, but today I turned on the Raspberry and it does not work. I thought that I could have broken the GPIO, but it does not make sense because if I make a direct connection with no resistor, it still works.

Some ideas to explain this weird behaviour?

Thank you.

  • What "weird behaviour" - you have provided no evidence. What pins? Pin 27 (physical) is reserved, Pin 20 (physical) is 0V. – Milliways Apr 20 '18 at 10:24
  • To add to what @Milliways already said you have not shown us your code either. – Steve Robillard Apr 20 '18 at 10:27
  • @SteveRobillard There is no code, I've just exported the Pin, set its direction as "in" and read the value from /sys/class/gpio/gpio20/value – Daniel Apr 20 '18 at 10:34
  • @Milliways I was talking about BCM numbers, GPIO 27 and GPIO 20. I am going to edit that to clarify. – Daniel Apr 20 '18 at 10:36
  • 1
    Show us a photo of what you are doing. If what you say is correct an explanation would be the resistance is far higher than you think. – joan Apr 20 '18 at 11:05

You problem can be explained voltage divider rule. I did the following quick and dirty test to show how the pull up resistor confuses you.

My test is on the I2C SCL pin.

  1. I first googled to find that the rpi I2C pins have built in pull up 1k8 resistors.

  2. Using a multimeter, I found that at boot up the SCL pin read 3v3, meaning that by default it was pulled up.

  3. I connected a 1k2 from SCL pin to ground, thus forming a 1k8 + 1k2 voltage divider. The meter read 1.3v.

Voltage divider rule says the voltage at the connection point of the two resistors should be:

3v3 * [1k2 / (1k2 + 1k8)] = 3v3 x [1.2 / 3] =  1.32V
  1. Then I replaced the 1k2 by 4k7, and SCL then read 2.4v.

Calculation again:

3.3 * [4.7 / (4.7 + 1.8)] = 3.3 * [4.7 / 6.5] = 2.38v.  


Google says that some gpio pins have 50k pull up, and some pins no pull up resistor at all, and that at boot time, some pins are pulled up by default, some pulled down. You may like to test other pins.

  • Again this seems irrelevant to the question - the OP is NOT using I²C pins and is NOT connecting to ground. There is no mystery about initial pin state - it is documented in many places e.g. panu.it/raspberry ALL pins have a default pull state, although this can be changed in Device Tree – Milliways Apr 28 '18 at 0:25
  • Thank you very much on the default pull state. No wonder I have googled but read different config of init pull state. Now I know that the manufacturer can change the default. My problem is that I know nothing about the Device Tree. This topic is too advanced for me. Perhaps I should dig deeper before I do more tests. – tlfong01 May 1 '18 at 2:44

I guess it is rpi's hidden built in gpio pull resistor that confuses you.

To avoid the tri state input pin floating, you can pull the pull resistor to either Vdd or ground.

Suppose you pull the built in resistor to ground (0v), then if there is no input, the input pin would read 0V. Similarly, if you pull the resistor to Vcc (3V3), then if there is no input, the input pin would read 3V3.

Now if you pull the built in 1k8 resistor to ground, and your 1k to 3V3, then because there is a voltage divider which divides the 3V3 at the gpio pin to:

3V3 * 1k8 / (1k8 + 1k) == 2V

Now gpio pins reads 2v, instead of your expected 3V3.

You can pull the built in resistor to 3V3. Then if you connect your 1k to 3v, gpio pin would read 3v3. But when your 1k is connected to 0v, gpio pin would NOT read 0v! Why?

Anyway, the problem does not go away, but shifted to the other end.

One usual trick is NOT to use your 1K resistor as the input, but use a 'open drain' or 'open collector' device as the input to the GPIO pin. You also need to pull the built in resistor to 3V3. Then all should go well.

I know it is complicated, but that is 'advanced' electronics!

My apologies for my wrong information about the wrong pull up/down resistor value of 1k8, and the wrong description about the 'floating' input.

I remember I often read that a weak resistor should be around 100k. So my 1k8 should be WRONG.

My description of "floating input" is misleading. I should have said that if the input to the gpio pin is tristate, say from the tristate output of a disabled cmos cricuit, then the gpio pin would see arbitrary or indeterministic values. And a pull up resistor can avoid the floating problem by pulling up or down, so that the gpio pin would either see high or low, not indeteriministic values.

Actually I wrote the above in a comment, but found I would not save it because I spent more than 5 minutes editing. I am slow in writing English, so I think I should have edited my comments using an editor and then copy and paste it here as a comment.

I googled again for the rpi pull up value. I found the forum saying rpi i2c internal pull up is 1k8. But another forum says official i2c external pull up is 1k8. However, a couple of other forums say the rpi pull up is 50k. It is indeed confusing.

* i2c pull up resistors *


... Since the RPi board already has 1.8K resistors on the I2C lines, ...

* Rpi i2c pullup configurations *


... The official I2C bus has 1K8 external pullups to 3V3 ...

I googled again and found someone saying that rpi's i2c pins have 1k8 pull up resistors.

Home→Raspberry Pi→WiringPi→Special Pin Functions


Pins 8 and 9 . . . These are the I2C pins.

. . . note that they have on-board 1.8KΩ resistors pulling the signals to the 3v3 supply.

About tristate inputs, I googled and found the following comment:


ka7ehk Posted : Mon. Apr 2, 2012 - 02:07 AM

“AVR shared digital/analog inputs are, indeed, "tri-state" of a sort. However, as mentioned, this term most often applies to outputs. The AVR documentation does not use this term with respect to inputs, only outputs.”

I now think that my saying of "tristate input" is WRONG. An input may be in the "floating state", but this state is completely different from the output's high impedance state. A shared digital and analogue input can have the analogue buffer disconnected (connection becomes high impedance) but that is not the same as the output's high impedance.

Max and min i2c pull up values.

I googled again and find the following two notes on i2c pin pull up values.

TI pull up calculation


I2C Pull-up resistor calculation


My quick conclusion is that the pull up resistor should be from 200R min up to 1k8 max.

Now I reading online tutorials on tristate circuits and pull up resistors, to clear my mind and remove my misunderstanding of some confusing technical terms. I found the following two tutorials very good.



Tristate digital buffer


  • 1
    This is a work of fiction. There is no such thing as a " tri state input". The pull resistors are ~50kΩ – Milliways Apr 22 '18 at 3:56
  • My apologies. I read the 1k8 value from a probably unreliable source. I vaguely remember that article says something about a weak pull up resistor. I remember a weak pull up means 100k. So I think you are 50k value should be correct. – tlfong01 Apr 22 '18 at 12:13
  • 2
    @Milliways Somebody better tell the U.S. patent office then: patents.google.com/patent/US6133753A/en "Tri-state" would refer to the three possible states of an input: (pulled) high, (pulled) low, (unconnected) floating. en.wikipedia.org/wiki/Three-state_logic (apparently aka. "tri-state"). – goldilocks Apr 26 '18 at 13:17
  • 1
    By "pulled" I meant if the input is attached to something with relatively low resistance this will determine it's state (high or low); this might be whatever it is supposed to be receiving a signal from, or an element of its own circuitry (pull up/down). If it is not so pulled, then it is in a floating state. While the SoC doesn't register this and divides the voltage spectrum into either high or low, that is indeterminate, which is why the concept of "high-Z" in tri-state logic is important to be aware of -- we get questions here all the time that reflect an ignorance of the possibility. – goldilocks Apr 27 '18 at 11:48
  • 1
    @goldilocks the "work of fiction" was because the whole answer was predicated on the Pi having 1.8kΩ pullup/pulldown which invalidates the whole argument. The " tri state input" was an observation, equally untrue because the Pi has no tri-state. In fact, in a real tri-state circuit the driving pin SHOULD pull the output high, before entering the high-impedance state (to discharge the bus capacitance) – Milliways Apr 28 '18 at 0:00

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.