Electrical – Raspberry Pi GPIO Output On Startup Safety

circuit-protectiongpioraspberry pi

I'm working with a simple circuit using an infrared breakbeam sensor and a Raspberry Pi. Here's my best attempt to diagram how I have the circuit set up.

enter image description here

The Raspberry Pi will also supply both power and ground. I noticed in the Raspberry Pi 2 User Manual I got with the Pi (from Vilros) that there is a short section where it is mentioned that the Pi's GPIO pins can momentarily be set to outputs when the Pi starts up, and that if you have a circuit which connects one of the pins (as an intended input) to ground it could cause a short circuit and damage the Pi if/when the pin gets reset to an output on reboot. They recommend a 300 ohm resistor between the GPIO pin and ground pin. So I'm wondering if I can/should just put a 330 ohm resistor between the black wires (the transmitter and receiver share the same ground pin) and the ground pin to prevent a possible short circuit on startup. I was also wondering if maybe putting a diode on the white wire of the receiver would also prevent this issue.

Best Answer

You've misunderstood a couple of things, but i'll address the overall question first - Protection of the Raspberry Pi's GPIO from over-current conditions

The GPIO on the R-Pi can be subject to over-current conditions for multiple reasons, not just a start-up glitch where what should be a high-impedance (aka. resistance) input is an output instead, and could possibly be an output LOW meaning it's essentially a short-circuit to ground inside the R-PI.

As a general guideline for interfacing with ANY fancy logic/computer board like the R-Pi, CompactRIO, or pretty much any logic board that can have access to the outside world and doesn't already have its own ruggedized inputs/outputs (some boards do! always check datasheets/schematics to see how rugged they really are) you want to add some cheap protection yourself.

Typical external protection components are simply series resistors on every single GPIO in that interacts with the outside world or external voltage sources. So in this situation, a series 330 Ohm resistor between the R-Pi's GPIO pin and the rest of your circuits, as a middle-man.

The role of the series resistor is to prevent total current into, or out of, the pin to be limited and will never be able to 'short'.

The next major protection element people use to protect logic boards like these from the outside world is ESD and over-voltage (like TVS diodes) clamping diode arrays. Every single pin can benefit from having an ESD clamp from the pin to ground, to absorb static discharge events - and TVS diodes or zeners with additional resistors to allow permanent 'over voltage' situations without ever harming the logic boards on the other side of the circuit.

For your circuit you actually won't have the dangerous short-circuit condition on that pin, you have already got a pull-up resistor to the 3.3V rail which acts as the current limiting element. There is no other path to ground in your simple example to worry about, except maybe the IR sensor's output if that happens to have a proper high-current driver output (unlikely, it's most likely to be a variable resistance).

If you wanted to be super careful, and to follow the general guidelines I ranted on about earlier, you can do something like this (and add the resistor for every other GPIO which interfaces with the real world).

schematic

simulate this circuit – Schematic created using CircuitLab

With the 330 ohm resistor in there, the maximum input current to the GPIO pin if it was accidentally set to OUTPUT and LOW, assuming a 3.3V rail is connected directly to the input (but we still have the resistor there!) for whatever reason, then the maximum current will be only 10mA (3.3V/330R= 0.01A).