
This article as originally published on DesignSpark by DrLucyRogers on 26 Feb 2021
Part 1, Part 2 and Part 3 of this series have looked at the various outputs you can connect to your Raspberry Pi.
This article talks about how to protect your Pi.
When using a Pi to control bigger loads, it is important to prevent large currents flowing to the Pi by mistake. This is most likely to happen via ground connections. Ground loops can cause all kinds of strange things to happen, including permanent damage to the Pi. A full discussion is outside the scope of these articles but here we hope to give enough of an understanding of the subject to be able to take basic precautions to protect your Pi and be able to look for further information online or in other books.
Many parts of the Pi are connected to ground, including:
Anything connected to these will also then be connected to the ground of the Pi.
When using a Pi to switch high current loads fed from an external power source, you need to make sure the load current cannot accidentally flow through the Pi itself. One way this could happen is for the current to flow to ground through one of the above routes. This can cause damage or undesirable behaviour in a circuit (such as strange noises on audio outputs.)
At a few tens of mA, you probably don’t need to worry but once you start to control loads with hundreds of mA or several amps you need to pay attention to the path that currents can take through your circuit and the Pi.
With open-collector drivers the low-current input side and the high current output side have to share a common ground connection at the emitter of the transistor. Many motor control HATs will also have a common ground between the motor supply and the Pi.
The external power supply, which drives the load, should have its ground connected at the emitter of the open collector driver - and nowhere else. If it is connected to another place, e.g. the ground of one of the Pi’s USB connectors, another ground pin on the GPIO connector or the ground of whatever is powering the Pi itself, then the relatively large load current has to flow through the Pi’s circuit board in order to complete the circuit.
If you have more than one open collector driver, or several different loads with different power supplies, all their grounds, including those of the power supplies, should be connected together at a single point which is close to the Pi. This common grounding point should then be connected to the Pi’s ground via the ground (0V) pins on the GPIO connector. This method is called star-grounding - all the ground connections radiate out from one point like the arms of a star. A well-designed motor control HAT should do this for you and provide separate ground and power terminals for the external supply.
Star grounding means that all the currents flowing in your system have only one way to return back to the ground of the power supply. If there is more than one way for the ground return current to flow, then you have created a ground loop (or earth loop.)
To understand this a bit better, we will define the terms we are using:
DC power supplies have positive and negative terminals. This just means that the positive terminal is at a higher potential (higher voltage) than the negative terminal. The potential difference between the two is the voltage rating of the power supply. For example, in a 12V battery, the positive terminal is 12V higher than the negative terminal. If we connect the negative terminal to our circuit ground (0V,) the positive terminal will be at 12V. This may sound obvious, but it is important to keep in mind when dealing with more complex systems (e.g. consider what happens if you put two 12V batteries in series. The positive of the top battery is 24V above ground and its negative is at 12V, but the battery doesn’t “know” this, it just maintains 12V across the terminals. Likewise, we could connect the “middle” connection of the series pair to ground. Then we’d have a +12V and a -12V power rail. (This is called a “split-rail” supply, sometimes used in audio and analogue circuits but not so common in digital and IoT applications.))
Having defined some terms, we can get more of an insight into what really happens to the ground rail of a circuit. Consider the flow of current and its effects on the circuit:
Star-grounding is one weapon in the fight against ground loops. Another is galvanic isolation. Galvanic isolation (or electrical isolation) means that two circuits are able to pass power or information between each other without sharing any direct electrical connection. The power or information is instead transferred between the two circuits by a magnetic field or by light. A relay is an example of a device which provides galvanic isolation. The coil operates the contacts by a magnetic field. There is no electrical connection between the two. This means that heavy currents being switched by the contacts cannot flow through the circuit which operates the coil. Another example of galvanic isolation is an opto-isolator. This uses light to pass a signal from one circuit to another without physical connection. For more detail on opto-isolators, refer back to the Inputs article - part one.
Power supplies can also have galvanic isolation. The 5V USB “wall wart” power supplies commonly used to power the Pi are a good example. They provide isolation between the mains electricity and the Pi by using a transformer - a device which can transfer power using a magnetic field.
Some DC power supplies have their 0V (ground) terminal connected internally to the mains earth - such as desktop PC computer power supplies. If you power your Pi via the USB port of a desktop PC, the ground of the Pi is also connected to mains earth. This can cause problems if you have other outputs with their own mains power supply, connected to your Pi. Also, if you are boosting the audio output of the Pi with a mains powered amplifier you may hear noise in the speakers when no sound is supposed to be playing.
An example of a situation where ground loops can really become a problem is when you are running a Pi “in the field” from a battery and also want to drive various loads from the same battery. You may end up with multiple circuits being grounded at both the battery negative and the Pi’s GPIO ground pins. This can cause earth loops. One way around this is to use star-grounding and have one common grounding point where everything connects fairly close to the Pi. Another way of resolving this issue is to use an isolated DC-DC converter to power the Pi. This is a kind of power supply which can be fed from a (usually fairly wide) range of DC voltages instead of the mains. Internally, it changes the input DC power into AC, runs it through a transformer to get the galvanic isolation and then changes it back to DC. However, DC-DC Converters are not cheap.
For one capable of powering a Pi, the cost is nearly that of the Pi itself - but it could be worth it if it saves the Pi from getting “blown-up” or solves a tricky ground-loop problem. Physically, DC-DC converters are small (e.g. 25mm x 25mm x 10mm) black plastic or metal box with pins sticking out of the bottom. They are usually designed to be mounted to circuit boards, but if you are careful you can solder wires directly to the pins. The pin connection details, maximum ratings, etc, are all given in the converter’s data sheet. To power a Pi, aim to use a DC-DC converter with a single 5V output and a power rating of around 10W. Some converters have a really wide input range, say 9- 36V. This could be useful if you want to run a Pi in an industrial control panel where you commonly have a 24V power rail available, or to run the Pi in a vehicle where the supply is around 12V but can vary from 10-15V depending on whether the engine is running or not.
DC-DC converters are also useful if your project needs a bunch of different power supply rails for different parts of the system but you only want one incoming supply. For example, you can get DC-DC converters which will take 5V from the Pi’s GPIO connector and produce a dual +/-15V output for powering analogue circuits.
These "Inputs" and "Outputs" series of articles have discussed how you can connect your Raspberry Pi to the outside world - safely, through the GPIO pins.
It also looked at how some of those inputs and outputs work.
Now it's over to you to get your Pi doing the things you want it to do!