Tuesday, July 2, 2013

ATXRaspi = Automatic Power Switch for R-Pi

A while back, I did a video review of the ATXRaspi R1, but I wanted to circle back and fill in a few details on how I used the "P5" connector, instead of the GPIO pins.

But first I should mention that Felix reworked his circuit, replacing the relay with a power MOSFET, and dubbed it ATXRaspi R2.  

The (discontinued) R1 had an issue with some (whimpy!) power supplies.  When the relay closed, the immediate current draw by the R-Pi would sometimes cause the ATXRaspi to reset.  When/if this happened, you'd need to hold the power button for a second or two, the relay would click on/off/on a few times, and then everything was fine.

The new ATXRaspi R2 completely solves that issue, by using a slightly slower turn on rate, via the MOSFET.  On a related note, I posted a video about using power MOSFETs with Arduino or R-Pi, a while back.

OK, back to those build details I wanted to share.  I wanted to keep all GPIO pins open and available for other projects, Pi-Cobbler, etc.  So my solution was to use the P5 connector on the Raspberry Model B, Rev.2.  

The P5 connector is "unpopulated" which simply means they didn't install the header pins.  Which is fine by me, just made it easier to solder wires directly into the plated-through-holes.  

Here's how I connected the ATXRaspi to the Raspberry Pi P5:

  • Ground     <-> P5-7
  • +5V Output -> P5-1
  • Input           <- P5-4  (GPIO29)
  • Output        -> P5-3  (GPIO28)

And here's what it looks like:

(Observant readers might notice the ATXRaspi looks a little different.  This was an R1 board, that I retro-fitted with a power MOSFET instead of the relay.  You could call it R1.5 :-)

Note that the GPIO lines on P5 are different than any on P1, the main GPIO connector.  Which is good, that's what I wanted.  But that also meant I had to modify the shutdowncheck script:


#original from www.lowpowerlab.com
#modified by MikeT to use P5 on Rev 2 Pi
#instead of using any GPIO on P1


echo "ATXRaspi shutdowncheck script"
echo "(modified to use P5 on rev 2 Pi)"
echo "Setting P5-3 Input, Pull Down"
echo "Setting P5-4 Output, High"

gpio -g mode 28 in
gpio -g mode 28 down
gpio -g mode 29 out
gpio -g write 29 1

echo "If/when P5-3 goes high, SYSTEM WILL HALT"

while [ 1 ]; do
    if [ "$(/home/pi/wiringPi/gpio/gpio -g read 28)" = "1" ]; then
        echo "Pin P5-3 is High: SYSTEM WILL NOW HALT"
        sudo halt
    sudo sleep 0.5

exit 0

By the way, Gordon's wiringPi library is excellent.  Kudos to Gordon!

Getting Started with Raspberry Pi

I've been working with the Raspberry Pi, or R-Pi, for a couple months now, and figured it was high time I blog about it.  As usual, my goal is to give you links and references that I found helpful, and to give you a few helpful nuggets that I learned the hard way, to save you time.

For starters, I got the Raspberry Pi Model B Revision 2.0 (512MB) and a Transcend 16GB Class 10 SDHC Flash Memory Card (TS16GSDHC10E).  

Although there's a ton of info on the internet, I still like books.  I took some time reading reviews and previews before settling on three books.  They've each been helpful in different ways:

Here are some lessons learned:

1) Make sure to get an SD card that is known to be R-Pi compatible: check this list Don't waste your time on a card that others had trouble with.    

2) The SD card socket on R-Pi is very cheap and sooner or later it'll break.  I thought I was being very careful, but I managed to break it, and it was a hassle to fix.

3) The Adafruit Pi-Cobbler is great way to connect the R-Pi to a solderless breadboard.  (Actually, I would have preferred the T-Cobbler, but they were out of stock at the time.)

4) This Adafruit R-Pi case is a great value and works fine, except that it doesn't hold the R-Pi down very securely.  

One time I was unplugging the Pi-Cobbler from the GPIO pins and didn't realize the R-Pi was lifting up inside the case.  The SD card was still plugged in, and that was the demise of the cheap plastic SD card socket. 

Here's how I fixed it, without soldering.  I used some foam tape, with a smooth durable top layer, to build up the area inside the case, below the SD card slot:

Then I added a nylon standoff, to the right of the GPIO pins, to hold the R-Pi down inside the case:

Now my SD card makes good contact again.

Next up: ATX Raspi, and then direct serial com between R-Pi and Arduino...