Raspberry Pi GPIO: mixing voltage levels

“Don’t put metal objects into your microwave” and “Don’t connect 5 Volts to your Raspberry Pi GPIO”

I consider these to be two pieces of well meaning advice for non-technical people. The idea is to help avoid mis-haps by offering generalisations, without going into long explanations.

But we are not non-technical people, are we?

The background

The Raspberry Pi GPIO (general purpose inputs/outputs) operate at 3.3 Volt, which can be a bit awkward. I say awkward because many devices (such as sensors, logic and functional chips) run on 5 Volts.

The popular advice, as mentioned above, attempts to be black-and-white, with lots of Raspberry Pi forum buffs passing on the same message, and recommending the use of potential dividers and level shifters when interfacing 5 Volt devices with the Raspberry Pi

I started thinking about this issue once again as a result of re-working the controller circuit from last years birdbox.

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.

 Raspberry Pi GPIO mixing voltage levels

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.

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.

 

For more detail:

Scroll to Top