Wednesday 28 January 2015

How To Power Your Raspberry Pi With a PC's PSU

Introduction

Well, putting a Raspberry Pi inside a PC case is not that difficult. But that's not what this tutorial is about: the main goal is to power the Pi with a standard PC power adapter.
I did this because I wanted to build a home server for file and printer sharing, but the tangled up cables attached to the Pi annoyed me. 

The Plan

Since I wanted to share files, I also needed a quite big storage space, so my plan includes a USB hard disk attached to the Pi. 
The idea is to power both the Pi and the hard disk with the same adapter. This is easily accomplished through a USB Y cable for external hard drives: that's a cable that can be attached to the hard drive on one side, while on the other side it forks into two type A USB plugs. 
One of the plugs carries both power and data, while the other only carries power. Since the power lines are shared by all of the plugs, it's sufficient to connect only one of them with the power source: that will be the power-only plug, while the power and data plug will be connected with the RaspPi.



The Raspberry Pi will be back-powered through its type A USB receptacle: the fuse protection will be bypassed, because the fuse is located right after the micro USB socket, but in my experience this should not be a problem. I think that a standard PC power supply should have this kind of protection built-in anyways.

I used the PC's power supply to power the Pi, but the latter is not tied to the PC's power state: the PC can be turned off and the Pi will still function correctly. The idea is that the Pi will be shut down infrequently, mainly because of its low power consumption and its use as a server.

I attached a USB receptacle to the power supply by modifying a couple of cables. This step requires some basic soldering skills.

All in all it's not a dangerous process, but you may be worried about the stability of such a system, and possible fires or short-circuits or who-knows-what. As always I don't take any responsibility and you do everything at your own risk. As long as you're a bit careful though, you won't need to face these catastrophic circumstances.

Requirements

Since this project requires a hardware modification, you will need specific tools and components:
  • Soldering iron
  • Solder supply
  • USB extension cable
  • Wire cutters or strong scissors
  • Heat-shrink tubing
  • Heat gun
You will also need some basic soldering skills.

USB receptacle

One of the forked USB cable plugs must be connected to a USB receptacle to receive power, so the first step is to get a USB receptacle with wire. 
The easiest way to get what you need is probably to buy a USB extension cable, that is a cable with a USB type A receptacle at one end and a USB type A plug at the other end: just cut the plug away with a pair of scissors, and expose the four internal wires. The black wire is intended to be ground (negative side of the circuit) while the red one should bring positive voltage.

I didn't want to buy a new USB extension cable or use one that I had, so I made my own cable. I desoldered the receptacle from a non-working USB power adapter, and I soldered two wires to it. I applied some glue in the area between the joints in order to round its shape, then I enclosed everything with heat-shrinking tubes.
The result, more or less equivalent to a USB extension cable with the plug cut off, is shown in the picture.
Note that I connected only two wires: that's because this cable is never going to transfer any data, so the data wires are not necessary.

If you cut the extension cable, you will find four wires inside it. You are only interested in the red and black ones, which are respectively for positive voltage and ground. This picture I found on the web shows the wires:
Free the ends of the red and black wires from their plastic casing, because you're going to solder them.

ATX cable

Now let's take a look at the PC's PSU (Power Supply Unit). The first thing you want to know is the amount of standby current it can provide. You can usually find this information on the PSU's label:
The standby voltage is 5 V, and it's labeled as +5Vsb. In my case, the maximum current amounts to 3 A, for a total of 15 W max power-draw. To power a Raspberry Pi and 2.5" hard disk you will need at least 1.5 A, let's say 2 A to be on the safe side. If you won't use a hard disk then 0.5 A will be sufficient.
The PSU has a cable with many connectors, but for this task you're interested in only one of them: the one that is attached to the motherboard. Nowadays most desktop PSUs and motherboards follow the ATX design standard. Connectors can have 20 or 24 pins, but the location of the wires that you're going to modify doesn't change. Pay some attention to the following diagram, which shows the pin disposition of the male connector (the PSU's end as opposed to the motherboard's).

Pin 9 (marked as +5VSB in the picture) is the one carrying the standby current. Mark the wire that ends in this location, so that you can easily identify it later. The other wire should be one whose pin is marked as COM in the picture. It doesn't matter which one you pick, as long as it's marked as COM: that's a ground wire and it's usually black. I chose pin 7, because it's the nearest one with respect to pin 9.
Since I didn't want to directly modify the PSU's wires (who knows what could go wrong?), I bought an ATX extension cable for just a few bucks and I modified it instead. The process is the same: you have to identify the wires based on their pin location. An ATX extension cable looks like this:
If you search on the Internet for schemes of the wires, you may find a reference to the wires' colors. Since the colors are not always standard (an example is my extension cable, as seen in the previous photo), I suggest you don't rely solely on this information.
Here I marked the wires/pins of interest:
Once you have identified the two wires, cut the Vsb one with a wire cutter and remove insulation at the cut ends. Insert a heat-shrinking tube of appropriate width on one end, and get ready to solder together three wires: the two ends of the Vsb wire and the red wire from the USB receptacle we prepared earlier. The next picture shows a black wire, but let's just pretend that it's red for now.

Carefully apply some solder with your soldering iron...
 ...hopefully doing a better job than I did.
When the joint has cooled, slide the heat-shrinking tube over it.
 Finally apply heat with a heat-gun.
A
Repeat this process to join the other wires together.
This is the resulting item:
Now you just have to connect the cables the right way. Remember to attach the power-only plug of the Y cable to the USB extension you just made:
Finally connect the USB cable and the Raspberry Pi. This is the final result:
If you have a Model B+, a cleaner solution might be to connect the Raspi with a micro-USB cable and power the hard disk through the Raspi. If that's what you intend to do, be sure to add one or both of these flags to config.txt in the SD card's boot partition:

 safe_mode_gpio=4
 max_usb_current=1 


Conclusion

I just showed you how I connected my Raspberry Pi to my PC's power supply unit. Now it can also benefit from the UPS that I attached to the PSU. I like this solution mainly because this way there are less cables around (just one for ethernet) and because of the increased power stability (lots of amps and UPS).

4 comments:

  1. It's great, thanks!

    ReplyDelete
  2. Nice. Why didn't you draw power from the +5V cable, but chose the stand by one? Just because you plan to keep the PI running while the PC is off?

    ReplyDelete
    Replies
    1. Thanks. That's right, I didn't want the Pi to power off alongside the PC. The standby power line is always active, so it allows the Pi to run independently from the PC's power status.

      Delete