Sunday, October 25, 2020

Pi Board Automated Testing - Part 2 Power Control

One of the early challenges I encountered with my Pi board testing was how to power up to 6 of the test boards safely and efficiently. I decided that I effectively had two options:
  1. Set up a shared 5 volt power supply that each device can be connected to with it's appropriate power connector (Micro USB, USB-C, or Barrel plug)
  2. Set up 120 V wall outlets that each device can plug it's appropriate power converter into
Initial I was leaning toward a shared 5 volt power supply, but I soured on this for a few reasons. The first reason was that I acquired a RockPi4 board, which recommends a power supply that supports USB quick charging (meaning it can negotiate up to a higher voltage to get more power). The second was that I had trouble sourcing an acceptable power supply, switching, and distribution mechanism that could handle the power requirements I had; namely that I wanted to be able to deliver at least 3A@5V to each board (although, not all at the same time). In the end, I decided to use 8 household outlets, and control each from an 8 channel USB relay. Each board then plugs into an outlet with its normal power converted and I am able to turn them on and off independently using the USB relay. This has a number of distinct advantages:
  1. Everything is off the shelf, cheap, and available at the hardware store. I was even able to easily add a "master switch" to turn off the entire device for less than $1 by using a simple light switch.
  2. I don't really have to worry too much about the power ratings. The wires and relay I'm using are sufficiently rated such that I'm not worried about transiently drawing 15A through them, and I was careful to select higher rated components for the main power feed and terminal blocks which have to handle powering all devices.
  3. The wiring is simple. Household wiring is designed to be connected with screw terminals, no soldering required.

Here is a picture of the bottom of the device, where most of the interesting things are happening. If you are an electrician or at all aware of wiring codes, I apologize for what you are about to see:

The black cable going toward the bottom of the image is a "dead-mans plug"; the other end terminates in a standard 3 prong plug and is how power comes into the device. The hot (black) wire from this cable goes up through the light switch (acting as the "master" switch), and then up to the upper terminal block. The upper terminal block has a (red) bus bar that connects all the terminals together, and from there it splits out 8 ways and goes to the 8 relays on the other side of the board through two holes. You will note that I did a terrible job color coding my wiring, as the four wires on the left of the terminal block are obviously hot, but I used white wire instead of black. This was because I ran out of black wire, and was too lazy to get more. I don't recommend doing this, as it caused a bit of a problem for me later. From the relays, the wires go back through the holes and then to the hot side lugs of the wall outlets. I turned all my outlets into split outlets by removing the tab that would normally attach the top and bottom hot lugs so that they can operated independently.

The neutral wire (white) and ground wire (bare copper) from the power feed cable both go to the lower terminal block. It's hard to see from the picture, but there are actually 2 (black) bus bars attached to the lower terminal block, each one connects alternating terminals together. This makes the lower terminal block alternate between neutral and ground terminals (note, I wouldn't recommend doing this; use two smaller bus bars). From the lower terminal block, the neutral and ground wires split out to each outlet. Only four neutral wires are needed because I left tab that connects the top and bottom lugs on the neutral side of each outlet in place.

The cable that runs off to the right wraps around to the top of the board to power 12V power converted, used to power the USB HUB and Ethernet switch. I "cheated" and taped its hot wire off of the screw lug on the light switch which is unused because the upper terminal block is connected using the friction tap. The neutral and ground are attached to the lower terminal block.

The entire bottom of the device is covered with two pieces of polycarbonate (Lexan); despite my atrocities against the household wiring code, I do have a healthy fear of 120V wiring, and I want to make sure there is no way an errant finger or bit of metal debris can find its way to the 120V wiring.

Here is the view from the top:

Note the wires running up from the two holes to either side of the relay. Remember that the wires come up from the terminal blocks through the holes, through the relays, and black down to the back of the outlets. The 12V power brick is right below the frame, on the left. Also note that I wrote a number on each outlet, indicating which relay controls that outlet. I wasn't really trying to have an ordering that makes sense and succeeded; it doesn't matter to much because I refer to each relay by a name with software. Also note that the relay is covered with a sheet of polycarbonate to prevent any inadvertent touching.

When I'm not actively using one of the outlets, I use a simple plastic child outlet cover to keep things from falling in the receptacle holes. I originally intended to cover the outlets with wall plates to protect the lugs from the top, but I poorly planned the spacing of the outlets, and they don't fit. I might still cut a piece of polycarbonate to fit over the outlets.

Overall, I'm quite pleased with the results, and it has worked really well. I highly recommend using the terminal blocks to distribute the electricity; they are easy to use and pretty safe since this is what they are designed to do. If I were going to make another, I would probably use 2 separate smaller terminal blocks for the neutral and ground. If necessary, I think you could also use a smaller terminal block for the hot wire, since you might be able to double up and put one wire on each side of the screw lug to get two per terminal, in which case a 5 terminal block would cover the 8 outputs (this way, you could use the same size terminal block everywhere, which is nice size I've only found them for sale in lots of 8 to 10).

I would also do a much better job of color coding my wire. As noted, I ran out of black wire, and switched to using white wire for the hot lines. This actually caused me to damage the first relay I was using. The white wires confused me and I mis-wired one of the outlets such that one of the relay switches would short the hot and neutral wires when activated. This subsequently caused quite a spark and you can clearly see where the copper trace on the relay board evaporated:

In the end I wasn't too upset because I didn't like this relay for reasons I might cover in another post. Were I to make another one, I would make sure to only use black wire for hot, white wire for ground, and probably red between the relay and outlets.