RPi Tutorial EGHS:GPIO Protection Circuits
- GPIO Protection Circuits
- Basic Circuits: LED output - DC motor - Switch Input - Analogue Sensor
- Intermediate Circuits: Shift Registers - Analogue to Digital - Driving Circuit - Alpha-Numeric Display
- Advanced Circuits: Control Hardware Over The Internet
This page is part of a work in progress.
While most of these circuits may interface directly to the RPi, the use of a buffered interface (such as the one supplied by the Gertboard) is recommended which will help protect against damage. Alternatively, experiment with one of the Alternative Test Platforms.
Extreme caution should be exercised when interfacing hardware at a low level, you may damage your RPi, your equipment and potentially yourself and others. Doing so is at your own risk!
In order to protect the Raspberry Pi hardware, it is highly recommended that the GPIO pins are protected in some form to avoid damage. This page will introduce some circuits which can be used to protect the pins.
Note: Until RPi devices are available, I can not confirm this will work on a real RPi. For now, I shall be using the TI LaunchPad (see Alternative Test Platforms for details) to test the hardware on (as it is cheap and the logic levels similar).
THIS PAGE IS UNDER-CONSTRUCTION AND UNTESTED ON RASPBERRY PI HARDWARE
Why protect the pins?
While the GPIO pins can provide lots of useful control and sensing ability to the Raspberry Pi, it is important to remember they are wired directly into the internal core of the system. This means that they provide a very easy way to introduce bad voltages and currents into the delicate heart of the Raspberry Pi (this is not good and means it is easy to break it without exercising a little care).
Things we need to protect:
1) Drawing excess current from the pins (or short-circuiting an output)
2) Driving over-voltage on an input pin (anything above 3.3V should be avoided). The PI has protection diodes between the pin and 3V3 and GND, negative voltages are shorted to GND, but positive voltages greater than 3V3 + one "diode drop" (normally 0.5V) will be shorted to 5V, this means that if you put a 5V power supply on the GPIO pin you will "feed" the 3V3 supply with 4.5 Volt (5V - the diode drop) and that may damage 3V3 logic if the 5V source succeeds in lifting the PI's 3V3 supply to an unsafe value. Note that if you limit the current (for example with a 10K resistor) the samll amount of current flowing into the 3V3 supply will probably do no harm.
3) Static shocks, from touching pins without suitable grounding (often called ESD - ElectroStatic Discharge, occurs when your clothes etc build up an electrical charge as you move around)
All of these can potentially break your Raspberry Pi, damage the GPIO circuits or weaken it over time (reducing its overall life).
Physical Pin Protection
You must remember that the GPIO pin connections ( General Purpose Input/Output (GPIO)) also carry 3.3V, 5V and GND on the same 2x13pin header, so care must be taken when connecting and disconnecting wires that you don't accidentally connect these pins (i.e. 5V passed onto the GND or connected to 3.3V is likely to cause problems - if you are lucky the Polyfuse will kick in (can take an hour or so to reset), if you are unlucky you may break something permanently.
There are a number of ways to do this (depending on your requirements), such as using some jumpers (see photo) set to one side, strips of wire insulation (ideal for the NC - non-connection pins) or by using a full ribbon cable connector (like those used on IDE hard drives).
There are many ways to protect the GPIO pins electrically, below explains some of the methods.
In many cases, the selected IC will also have electrical limits of their own (hopefully less restrictive than the Raspberry Pi), so you may end up blowing them instead. However, it is preferable to replace an IC (of less value and greater availability) which has been blown than to break your Raspberry Pi.
Please expand these sections with more information about options available and why some are better than others.
If you are planning on using some of these circuits, it is recommended you research similar circuits to determine the best configuration for your needs.
Zener Diode Protection
This method uses a 3.3V Zener diode to limit the voltage which will be applied to the GPIO pins. By placing the diode between the GPIO pin and Gnd, any voltage applied which is greater than 3.3V will cause the Zener diode to "break down" (allow current to flow) through diode to Gnd (ensuring the voltage that reaches the GPIO is no more than 3.3V. Although there are cases where this protection won't fully save the GPIO from damage, it is highly recommended to protect from common wiring errors.
See the second part of the LED Driving Circuit (using Transistor Switching Circuit).
Transistor Logic Shifters
As well as providing protection, logic shifters will allow you to safely mix circuits which use different logic voltages. For instance many I2C (a common protocol) devices use 5V logic, so a level shifter is required to interface them with the RPi. If you always intend using the level shifter with the RPi, then using Zener diodes as mentioned above, on the low-voltage supply is probably a good idea too.
Other information on Logic level shifters (use only as a guide, particularly regarding the "out-of-specs" section):
Sparkfun's Logic Level Converter - Product linked only because they also provide schematics so you can make your own if you don't wish to buy.
Buffer/Line Driver IC
These ICs provide an in-line connection which is buffered via an internal transistor switch to isolate the input from the output. Depending on its type, they can provide conversion between 3.3V logic and 5V logic, as well as the ability to switch the I/O direction.
74HC245 - 8 line driver, with direction control.
74HC244 - 8 line driver, with 4 channel enable/disable.
ULN2803 - 8 line Transistor Array - Also some will allow switching of high currents, so are suitable for driving motors or other devices.
Opto-Isolators work by using an internal photo-LED and photo-sensitive transistor to transfer a digital signal (the LED is switched on, the transistor senses it and switches the circuit on).
This allows each side of the circuit to be fully isolated from each other, they can even be at different voltage levels if required (this is why they are often used in PSUs). Care must be taken when selecting a suitable IC as many it require a reasonable driving current to drive the internal photo-LED.
ISP621-4X - 4 line (although the RPi may have issues driving this directly due to 10mA input).
An alternative route, it to allow the Raspberry Pi to digitally interface over it's SPI or I2C connections to a purpose built I/O Expander chip. These chips are designed to allow multiple inputs/outputs to be fed to a processor over a few I/O pins (multiple I/O chips can be addressed separately too), they often have multiple high current channels available and can also include analogue to digital converters.
Protection is provided by allowing you to connect a wider range of circuits directly to the I/O Expanders pins, while the Raspberry Pi will send and receive standard logic level signals.
Much like using the above I/O Expanders, it is possible to interface directly with other microprocessors, for instance the TI LaunchPad or Andrino. Any additional features of the microprocessor will be at your disposal, such as built in ADCs and PWMs, timers or comms interfaces etc.
The external processor will need to be configured so that you can communicate with it, but you can also allow additional processing and control to be handled within the external processor as required. Also care must be taken to ensure suitable logic level conversions are done (3.3V to 5V and back again).
Similar to using an external processor or I/O expander, normal logic levels can be used between the raspberry pi and the transceiver, clearly if the input/output is not physically connected, then there is good overall protection.