Friday 16 January 2015

Raspberry Pi GPIO: mixing voltage levels

The original post has been removed because it was out of date.

The background

The original post contained input voltage and input current measurements taken on Raspberry Pi model A and model B boards. The GPIO (general purpose inputs/outputs) circuitry appears  to have changed, probably since the introduction of the A+, B+ and subsequent models.

The original post argued that the measurement data indicated that the gpio, when operated as inputs, were probably 5V safe. The input current didn't show much of an increase (with input voltage increase) until the input reached about 5.8V. So my assertion is that there is probably input protection operating somewhere around 5.8V on these early models.

Therefore using pull-up resistors between inputs and 5V supply on model A & B Pi boards should be OK, and I have not had any failures.

What about newer Pi models?

I continue to use input pull-up resistors to 5V, but I've noticed that even relatively high resistance values result in almost the full 5V level appearing at the input.

So it looks like the input impedance is now much higher on the newer models (A+, B+, Pi2 & Pi3). I've noticed that the input current is much lower (approx 2uA against maybe 60uA for the earlier models).

As there are probably more of the newer design in circulation than the original models, I've crossed out much of the original text below (it is still readable, but remember it relates to the early models).

When I can find time to do a proper evaluation on a newer Pi, I'll come back an update this page.

My take on this

The RaspberryPi was developed primarily for school age children to handle, connect and program. The board is clearly not overly susceptible to electro-static damage. If it were, the advice on the packaging would be for users to wear anti-static wrist straps to avoid damaging the circuitry.

The need for personal anti-static measures for certain equipment is due to the fact that we generate electrical charge as we move around. If I were to slide off this sofa and shuffle across our polypropylene carpet in my tartan slippers, by the time I reach the Blu-Ray player, the potential difference between the tip of my index finger and the eject button is likely to be hundreds, possibly thousands of volts. Admittedly this would be a low energy charge, and if I completed the circuit, it would be via a high resistance.

So, as the Raspberry Pi GPIO can be safely handled, it is reasonable to suggest that it can therefore be safely connected to a voltage greater than 3.3 Volts, just as long as it is connected via a suitably high resistance to limit input current.
I've seen diagrams on the web which allegedly represent the Raspberry Pi input protection circuitry, where input diodes conduct current into the supply rails if the input voltage exceeds recommended values. (I say "allegedly" because the design details are not in the public domain).

This is an old but effective way to protect sensitive input circuitry. When the input voltage exceeds the supply voltage + diode forward voltage, the diodes conduct current into the supply rails, the voltage across the input resistor rises, and the sensitive input circuit is protected from this higher input voltage.

This is a great illustration, but is it accurate?

If the Raspberry Pi includes this simple diode clamp protection, it should be possible to determine this by configuring a pin as an input, and measuring the input current as we increase the input voltage.

So I did a series of tests with different input resistors connected to 5 Volts. At each stage I calculated input voltage and current by measuring the voltage drop across the input resistor.

So, here are my conclusions from this first set of measurements:-
  • With an input voltage near to the ideal 3.3V, the input current is approx 61uA. Increasing the input voltage to 4.7V only increases the input current by approximately 3uA. Therefore I conclude that the circuit does not include a diode clamp operating in the range 3.3 to 4.7V.
  • Also, the small change in input current indicates that nothing bad is happening (i.e. nothing is conducting much more at 4.7V than it was at 3.3V, and the chip is not going to heat-up due to the extra 3uA).

If the input circuit does have input protection, it must be operating at a higher level (certainly above 4.7V) so maybe the input has been designed to be "5V safe".

Let's push it a bit further!

I decided to extend these tests by replacing the 5Volt source with 12Volts. I started testing with 12V connected via 100k to GPIO physical pin 12, while running a simple test program to ensure that this input was still functioning.

Initially I just kept swapping resistors and recording results. As the 12V supply was not especially stable, I measured both the voltage across the input resistor, and the voltage at the GPIO input pin.

Once I'd got a feel for how the tests were going, I repeated the tests using a resistor chain. This gave me better control, and enabled me to target input voltages in sensible 0.1V steps.

So, plotting the input current (i.e. calculated from Vr/r) against input voltage, I get this:-

The input current appears to rise steadily as the input voltage rises, up to around 5.8Volts. Above 5.8V the input appears to climb more quickly, so clearly something is happening.

The only conclusion I can come up with is that the Raspberry Pi GPIO inputs are 5 Volt safe, and that there is some kind of protection which kicks in around 5.8 Volts.

...but I'd be very interested to hear your interpretation!


  1. OK, this is a good analysis of what is probably going on behind the Pi's GPIO pins. I've been interfacing microcontrollers to Pi's since the Pi has been on the market, and I've been using resistor voltage dividers to get 5V talking to 3.3V. I just believed the mantra like everyone else!
    Things may change in my designs now that I've read your analysis. Thanks.

  2. The sudden rise in current at about 5.8V suggests that there is an overvoltage protection diode, but that it is tied to 5V instead of 3.3V.

    1. I agree. A silicon diode with a low current flowing through it often shows a volt drop of 800-900mV. So that fits with diode protection between gpio inputs and the 5V rail.
      It is now over 3 years since I started "abusing" the Pi gpio, and I have not damaged any of my boards (I currently have 13).

      BTW I like your article on rebuilding a valve (vacuum tube) amp:

      I need to push the rebuild of my 1950's Bush radio further up my job list!