Skip to main content
shopping_basket Basket 0
Login

What outputs can I use with my Raspberry Pi? Part 4 - Protecting Your Pi:

DrLucyRogers
0

This article was written by James Macfarlane and Lucy Rogers

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.

Grounding and Ground Loops

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:

  • Metal casings of the USB and Ethernet connectors
  • Ground pins on the GPIO connector
  • 0V of the USB power inlet
  • 0V of the USB outlet sockets
  • Ground of the audio connector
  • HDMI casing and ground
  • Ground of the camera and the DSI display connectors.

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:

  1. The ground of a circuit is whatever we define it to be. Usually, we decide that ground means the point of the circuit with the lowest potential (lowest voltage) i.e. 0V. You will see the terms 0V and ground (abbreviated to GND) used almost interchangeably in schematics and data sheets. Some circuits use voltages below ground (i.e. negative with respect to 0V) but these are rare in IoT applications.
  2. The word “Earth” refers to the Earth connection of the AC mains supply. The ground of a DC power supply is not necessarily connected to mains Earth (although it could be, see below.)
  3. The term “rail” or “power rail” just means part of the circuit which stays at a well defined voltage and is used to power other parts of the circuit. A circuit might have several different power rails. For example, the Pi has a 5V rail and a 3V3 rail. It also, of course, has a 0V (ground) rail. It is usually assumed that all parts of a rail are at the same potential, but this isn’t strictly true in practice - more on this below.

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:

  1. Current must flow in a circuit from the positive connection of the power supply, through the load (and through whatever switch is controlling the load, e.g. an open-collector driver) and finally back to the ground (or negative) connection of the power supply.
  2. If there are multiple paths for the current to flow from the load back to ground, the current will always take the path of least resistance (or at least the bulk of it will.) This path may be quite different in reality compared to how a circuit was intended to work “on paper.” As described above, a “ground loop” is what happens when there are multiple paths for the current to return to ground - and can result in the current taking a path the designer didn’t intend.
  3. When you see a connection drawn as nice black line on a schematic or wiring digram, it is tempting to think of it as “perfect” connection. It is easy to forget that all electrical conductors (wires, tracks on circuit boards, etc.) have a certain resistance, even if it is quite low. If the current is high enough, or the connections are too thin, a voltage drop will develop across the conductor. But not only do all conductors have some resistance, they also have some inductance. Without going into a lot of electrical theory, this means that rapidly changing currents (e.g. from PWM-controlled motors) have a larger effective resistance than steady currents do. Making the conductor wider, or making lots of smaller parallel connections, will reduce the inductance. This is why, if you are using a lot of GPIO pins, you should connect multiple GPIO ground pins back to your common grounding point.
  4. Point (3) is as true in the ground rail as it is in any other part of a circuit. So even though you’d like all the different parts of your ground rail to have the same potential of 0V, they actually end up at different voltages. Normally, the difference may only be a few mV (a few 1000th of a volt) but if the ground current is high enough, this could rise to some 100’s of mV (tenths of a volt). This is high enough to cause the circuit to start doing strange and undesirable things. Star-grounding side-steps this issue by ensuring that there is only one “official” ground connection. The voltage drops are still there, but they don’t matter so much.
  5. Circuits (including the Pi itself - a computer is, after all, just a big complex circuit) generally have to be designed on the basis that the ground is the ground - i.e. all points on the ground rail are at the same potential of roughly 0V. This means it’s important to try to keep it that way.

Galvanic Isolation

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.

Mains Power Supplies and DC-DC Converters

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.

Mains Earth

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.

DC-DC Converters

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.

Conclusion

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!

I am an inventor, engineer, writer and presenter. Other stuff: Royal Academy of Engineering Visiting Professor of Engineering: Creativity and Communication at Brunel University London; Fellow of the Institution of Mechanical Engineers and have a PhD in bubbles; Judge on BBC Robot Wars.

Related Content

DesignSpark Electrical Logolinkedin