Overview

ATXRaspi is the most versatile smart power controller for RaspberryPi. It enables turning off or rebooting your Pi from the press of a button, without needing to login to run those commands through the console/ssh.

Here are the features of ATXRaspi:

  • To turn ON the Pi all you have to do is press the power button.
  • To REBOOT the Pi hold the button pressed at least 0.5s and less than 2s. When the reset hold time is met the button LED dims a little bit (after ~500ms). The SHUTDOWN signal pulses shortly and the Pi (via shutdowncheck.sh script) will detect this pulse and start a reboot sequence. The status LED blinks for up to 1 minute while waiting for the reboot to complete (and BOOTOK signal to become HIGH again).
  • To SHUTDOWN the Pi you have to hold the button pressed for at least 2 seconds. The SHUTDOWN signal goes HIGH and the Pi goes into shutdown sequence. While shutdown is in progress the button LED will pulse slowly. When shutdown is complete (BOOTOK goes LOW), the status LED pulses faster and ATXRaspi cuts power off to the Pi after a few more seconds.
  • Use with momentary buttons (R1+) or latching switches (R2.7+)
  • It’s also possible to completely power off your Pi from the command line, see this page for details.
  • To FORCE-OFF power – hold the button pressed for about ~8 seconds to cutoff power regardless of any other conditions. This may be handy when the Pi is in an unknown state or is locked up/frozen.

The ATXRaspi forum is a good place to share projects and see what others have done. Here’s a nice example of how a user integrated ATXRaspi in a home media center.

Why ATXRaspi?

To keep costs low, embedded systems like RaspberryPi don’t usually have a shutdown button like desktop computers. To avoid SD card corruption a login is required to shutdown your RaspberryPi or embedded system, instead of just pulling the power cord. This can be inconvenient when your Pi  is not easily accessible or has no keyboard. Or perhaps your Pi is inside your standalone product with no network access – common examples are retro gaming consoles using Raspberry-Pi. You would then like to offer your customer the ability to gracefully restart/shutdown from the touch of a button, without having to login, and also cut power off to the Pi. ATXRaspi solves this problem by allowing you to have a shutdown button that will issue a shutdown/reboot signal to RaspberryPi for you.

The ATXRaspi name coincidentally hints to the ATX computer form factor. However it has no implicit meaning or association to the ATX computer form factor.

Pins & I/O description

You have the option to feed power through a micro-USB as you normally would to the RaspberryPi, or through a standard spaced header.

The top header has connections for the power button and an LED that will be ON while power is ON, and will fade in and out while shutdown is in progress. The output header has INPUT and OUTPUT signals that connect with the Pi’s GPIO, and of course the power OUTPUT to the Pi. There 2x 5V and 3xGND outputs, and four standard mounting holes.

When the button is pressed the first time the LED turns ON and power will flow from INPUT to OUTPUT and turn the RaspberryPi ON. The top INPUT signal is turned HIGH by RaspberryPi by a script. This is how ATXRaspi knows that the Pi has successfully booted. The OUTPUT signal is turned HIGH when ATXRaspi is asking RaspberryPi to shutdown. Another script is running on the Pi and listening on this pin.

ATXRaspi also works as a power controller for other similar embedded systems that have a 5V power input.

Assembly & Install

To ensure stability you will need a good power supply (as recommended anyway), at least a 5V 2A power supply to power the ATXRaspi. If you plan to use the Pi touchscreen/LCD and/or fan, use a 2.5A supply (eg. the CanaKit 2.5A supply is great)

Cheap eBay/chinese jumper wire is not good for powering your Pi from ATXRaspi especially if you have a Pi3 or any other peripherals like a touch screen, fan, etc. They are very thin and poorly crimped, and will drop voltage and trigger the Pi low voltage warning.

You should use a high quality stranded jumper cable, at least for the GND and 5V connections.

You should not plug in power to the RaspberryPi directly while ATXRaspi is powering the Pi

First get familiar with the basic operation and setup of ATXRaspi. Here is a video walkthrough, showing the operation with a momentary button (this demo uses Raspbian):

1. Connect your RaspberryPi to ATXRaspi.

Remember: ensure RaspberryPi is disconnected from power since ATXRaspi will power your Pi. The GPIO 7 & 8 pins are given as examples, you may change them to others as convenient (update the script as well), or if you have a Rev 2.0 Pi you can use the P5 header instead.

There are a few ways to wire your ATXRaspi to your Pi. The most common and supported in all versions is the single momentary button operation – this is the out-of-box default behavior. Here is a wiring example using micro USB for input and GPIO for powering the Pi:

You can also use the optional 2.1mm jack for input and the USB-A and cable for output, instead of the micro USB and GPIO:

Slide / latching switch operation

In ATXRaspi R2.8 you have a jumper setting on the bottom of the PCB, which if shorted (bridged with solder) will put the board in latching button operation, no other parts are required. This is very useful for folks who want to incorporate ATXRaspi in their SNES consoles which have a slide POWER switch.

Here is how you would wire your latching/push-pull/slide switch to ATXRaspi:

In latching mode, if you would like a dedicated reset button, separate from the main power button, you can wire it as shown below:

In ATXRaspi R2.7 only (or R2.6 with gold dot) you can also use a slide switch (or rocker, toggle, latching switch), but you will need to solder an external 10K resistor as shown below (in R2.8 this is included on the board and only a jumper is required, see section above). In addition, you can wire a separate reset button in latching mode. Note this mode requires the additional resistor(s):

As mentioned before you should use high quality wires (especially for the power signals), and keep them short. They should make strong connections to the headers on both ends. Poor wiring of power connections may cause voltage drops, and while your Pi may run just fine at 4.65v low voltage threshold, it will trigger the annoying low voltage warning (rainbow or thunderbolt in upper corner of the screen).

2. Install required script

  • On Raspbian or Debian based distro:
sudo wget https://raw.githubusercontent.com/LowPowerLab/ATX-Raspi/master/shutdownchecksetup.sh
sudo bash shutdownchecksetup.sh
sudo rm shutdownchecksetup.sh
sudo reboot

This will install a bash script (/etc/shutdowncheck) and register it to be started at the end of the boot process (adds a line to /etc/rc.local). So once your Pi reboots it should start the shutdowncheck script and you should see this message (if you’re not booting to the GUI):

ATXRaspi shutdowncheck script started: asserted pins (7=input,LOW; 8=output,HIGH). Waiting for GPIO7 to become HIGH…

That indicates the script has started and is running, waiting for a shutdown signal from ATXRaspi. The shutdown script will take on average 0.7% of the CPU:

CPU_percent

  • On OpenElec:
wget https://raw.githubusercontent.com/LowPowerLab/ATX-Raspi/master/shutdownchecksetupOpenElec.sh
bash shutdownchecksetupOpenElec.sh
rm shutdownchecksetupOpenElec.sh
reboot

This will install a bash script (/storage/.config/shutdowncheck.sh) and register it to be started at the end of the boot process (via /storage/.config/autostart.sh). So once your Pi reboots it should start the shutdowncheck.sh script, and the BootOK LED should turn ON. Here’s a quick check via SSH that the scripts were installed and shutdowncheck.sh is running (after the reboot):

3. Done! Your Pi should now be able to turn on, reboot and shutdown from the power button.

Full poweroff from software

If you want to automatically power off your Pi when you run the shutdown command (ex. shutdown menu in xbmc), this can be done pretty easily through a small addition to the ATXRaspi circuit. Basically we need to tell ATXRaspi to issue a shutdown, from software rather than from the button press. We can simulate the power button press via any generic NPN transistor from any Pi GPIO. Below is an illustration how this can be done with GPIO10:

This only works for momentary button operation, it will not work in latching/slide switch mode.

Here’s a sample script that should run when you want to shutdown or reboot your Pi, save this script as /usr/local/bin/softshutdown.sh:

#!/bin/bash
BUTTON=10

#setup GPIO 10 as output and set to HIGH
echo "$BUTTON" > /sys/class/gpio/export;
echo "out" > /sys/class/gpio/gpio$BUTTON/direction
echo "1" > /sys/class/gpio/gpio$BUTTON/value

#keep GPIO 10 high for at least 4 seconds for shutdown, 1s for reboot (same as pressing ATXRaspi button)
SLEEP=${1:-4} #default to 4 seconds if no delay value was passed

re='^[0-9\.]+$'
if ! [[ $SLEEP =~ $re ]] ; then
   echo "error: sleep time not a number" >&2; exit 1
fi

echo "ATXRaspi button press for: $SLEEP seconds..."
/bin/sleep $SLEEP

#restore GPIO 10
echo "0" > /sys/class/gpio/gpio$BUTTON/value

Make it executable with sudo chmod +x softshutdown.sh, then the permissions on this script should be the following:

pi@raspberrypi3:/usr/local/bin $ ls -la
-rwxr-xr-x  1 root staff  580 Dec 29 17:59 softshutdown.sh

Since /usr/local/bin is in your PATH variable (check with printenv command) you can now execute/edit the softshutdown.sh from anywhere). Also note this script takes a single decimal/numeric variable which represents the delay of the “button press”, if no value is given then the default is 4 (seconds), and this simulates a shutdown. For a reboot, pass a value of 1: softshutdown.sh 1.

Let’s do something cool and create aliases to execute shutdown and reboot in raspbian, run the following (use your own custom alias if you’d like):

$ printf "%s\n" "alias atxshutdown='sudo softshutdown.sh'" >> ~/.bashrc
$ printf "%s\n" "alias atxreboot='sudo softshutdown.sh 1'" >> ~/.bashrc
$ source ~/.bashrc

This adds permanent aliases to your .bashrc file and activates them. Now you can run these commands from anywhere:

  • atxreboot to trigger a reboot – ATXRaspi status LED will blink and wait for Pi to reboot
  • atxshutdown to trigger a shutdown – ATXRaspi button status LED pulses until Pi is halted, then it cuts power off as usual!

Using with XBMC

For XBMC you can do it somewhat simpler since there is a shutdown menu which invokes a shutdown command that can be replaced with invoking a custom script. You can use the following equivalent script, save it as /home/pi/softshutdown.sh:

#!/bin/bash
sudo gpio -g mode 10 out;
sudo gpio -g write 10 1;
sleep 4;
sudo gpio -g write 10 0

Next modify this file: /opt/xbmc-bcm/xbmc-bin/share/xbmc/addons/skin.confluence/720p/DialogButtonMenu.xml, and in the “Shutdown description” section replace XBMC.Powerdown() with System.Exec(“/home/pi/softshutdown.sh”). You may need a reboot for this to take effect. Now when you shutdown XBMC, the transistor will simulate shutting down from ATXRaspi, and will power off your Pi as usual !

This guide was inspired from this forum thread, thanks to all contributors!

Load tests

People often ask: How much load can the ATXRaspi support?

So some tests were done using the following hardware.

Here are the 3 supplies used for testing, and while all could run this setup without instability issues, the Under Voltage Warning (UVW) would come up at times, especially on the Apple supply which would show it constantly and the 5V GPIO rail would stay at ~4.8V. The best was the CanaKit 5V/2.5A, with this supply the UVW would only appear intermittently during boot, and would settle at ~5.05V after boot. So the CanaKit supply was used for the following tests.

The trusty Fluke 87V was used to measure the LCD amps and the GPIO 5V rail during boot to a console. Here is the setup and average mAmps used by the LCD at boot time:

Here are the peak recorded mAmps used by the LCD, note that this MAX was registered during (re)booting. The Pi LCD settles to ~450mA after booting is complete.

And here are the measured Volts with the CanaKit 5v/2.5A supply, again note that the 4.93V was recording during booting, after which it settles to ~5.0V:

A basic scope roll measurement was done to look at any MIN/MAX peaks and overall 5V rail behavior, note how the voltage starts at ~5.2V then the LCD starts up and voltage goes to a stable ~5V where it settles during/after boot, otherwise no odd dips or spikes:

Here is the Under Voltage Warning that might show up. With the CanaKit supply this showed intermittently only during boot. With the other supplies it was more apparent and with the Apple supply it was constantly showing all the time. Without the LCD this warning would never show with the CanaKit supply, but would show with the others.

Even so, the Pi behaved normally with all these supplies and there was no observed instability.

According to official Pi release notes, the UVW shows when the 5V voltage rail drops below 4.65V. In the tests above this condition could not be recorded with any of the supplies tested, either with an oscilloscope (roll 128ksps) or with the Fluke87V in Voltage Peak Detect Mode (1ksps+). Even with the worst performer (Apple supply) the MIN peak  was around 4.7V and settled around 4.85V after boot.

The conclusion is that ATXRaspi supports quite a hefty load, but to avoid the Under Voltage Warning you really need a very good supply, at least 2.5A.

Fuse option

There is now the option to add a fuse directly on ATXRaspi, by cutting this trace and soldering your fuse of choice on the provided footprint:

fuse_circled

Possible issues

1. Low Voltage Indicator shows up during boot. This could happen for several reasons – usually poor wiring or power supply quality. Be aware that by adding ATXRaspi to your setup you insert a lot of extra cabling and this can be a factor. During ATXRaspi load tests this indicator can show up intermittently (usually during boot, and varies with load and supply quality) but it’s usually not a problem and there was no instability.

  • Use the best power supply you can get – we recommend using something like the CanaKit 2.5A supply which was load tested with ATXRaspi and is performing great
  • Use good quality jumper wires if you power via GPIO
  • Try to keep wires/cables short
  • According to official Pi release notes, the warning shows when the 5V voltage rail drops below 4.65V. In our load tests this 4.65V condition could not be recorded with any of the supplies tested, either with an oscilloscope (roll 128ksps) or with the Fluke87V in Voltage Peak Detect Mode (1ksps+).

2. Disconnecting ATXRaspi and powering up the Pi directly will cause it to shutdown soon after boot up. This is because the signal ATXRaspi was using is setup as an input without a pull-up/pulldown resistor which might be floating and be picked up by the shutdowncheck script. To eliminate this problem – comment out or remove the line you added in the /etc/rc.local file before you disconnect ATXRaspi (otherwise you might not have another chance to do it with ATXRaspi disconnected – because of repeated shutdowns).

3. ATXRaspi does not cut off power to RaspberryPi after a shutdown is initiated. This can happen if the shutdown process takes longer than the “shutdown time window”. In this time of about 50 seconds, the power LED pulses and ATXRaspi waits for the BOOTOK signal to go LOW. If that does not happen, ATXRaspi assumes something prevents the Pi from shutting down properly, or the shutdown script is no longer running. It will therefore keep power ON if the BOOTOK is still HIGH after this time window. This was discussed in this forum thread, and the user was able to speed up the Pi by using a faster SD card.

Dimensional drawing

ATXRaspi_R2_Outline_dimensions

RetroPie Nin10do game console

Retro gaming enthusiast Daniel Spies has put together a wonderful RetroPie game console that can emulate popular consoles like NES, MEGADRIVE, PLAYSTATION and has shared his project for posterity. He designed a 3D printed case in Autodesk123D with a stepper motor operated front cover, indicator LEDs, ATXRaspi for power and reset control, and of course the RetroPie for the RaspberryPi OS. It’s one of the most polished projects I’ve seen from an amateur maker/hacker and it includes a series of very detailed youtube walkthroughs of the entire hardware+software setup.

Due to copyright reasons, Daniel’s shop was forced to be closed, and all his guides, video materials, and even Hackaday.io project page were removed. What a bummer. The rest of this information is kept here for reference.

Here are some snapshots I captured that highlight some of the details of the project:

Older version (R2)

Older revision (R1)

ATXRaspi is a smart power controller for RaspberryPi or similar embedded systems running from a 5V input. It allows you to have an external shutdown button to turn off your target system without a need to login or to issue manual shutdown/sudo halt commands. Here’s a nice example of how a user integrated ATXRaspi in a home media center.

compared2_small

To keep costs low, embedded systems like RaspberryPi don’t usually have a shutdown button like desktop computers, so to avoid potential issues when shutting power off you have to log in and issue a shutdown command instead of just pulling the power cord. This is sometimes inconvenient when your Pi  is not easily accesible or you don’t have network access to it, and even if you do it’s sort of a pain to always have to login just to do a shutdown or restart. Or maybe you have a product based on RaspberryPi or a similar embedded system and you’d like to offer your customers the ability to gracefully shutdown without having to first login. ATXRaspi solves this problem by allowing you to have an ATX style shutdown button that will issue a shutdown signal to RaspberryPi for you.

To turn ON the Pi all you have to do is press the power button. To trigger a shutdown to the Pi you have to hold the button pressed for ~4 seconds (the delay is there to avoid accidental shutdown). A shutdown sequence then begins. While a shutdown is in progress the LED will pulse at a slower rate. When shutdown is complete, the LED pulses faster waiting for all Pi activity to stop and finally cuts power off.
There is also a “Forced-Shutdown” mode that requires you have to hold the button pressed for about ~10 seconds to cutoff power regardless of any other conditions. This may be needed when the Pi is in an unknown state or has freezed.

Diagram

diagram_inkscape_12_OUT

You have the option to feed power through a uUSB as you normally would to the RaspberryPi, or through a standard spaced header.

The top header has connections for the power button and an LED that will be ON while power is ON, and will fade in and out while shutdown is in progress. The output header has INPUT and OUTPUT signals that connect with the Pi’s GPIO, and of course the power OUTPUT to the Pi. There are also two extra common GNDs and four standard mounting holes.

When the button is pressed the first time the LED turns ON and power will flow from INPUT to OUTPUT and turn the RaspberryPi ON. The top INPUT signal is turned HIGH by RaspberryPi by a script. This is how ATXRaspi knows that the Pi has successfully booted. The OUTPUT signal is turned HIGH when ATXRaspi is asking RaspberryPi to shutdown. Another script is running on the Pi and listening on this pin.

ATXRaspi also works as a power controller for other similar embedded systems that have a 5V power input.

Mike from mikesmicromania.com has put together a review/demo on ATX-Raspi, thanks Mike. Here’s his setup:

Installation guide and source code

First things first:

! IMPORTANT ! To ensure stability you will need a good power supply (as recommended for it anyway), at least a 5V 1A power supply to power the ATXRaspi. This is to avoid any voltage drops when you turn power on to your RaspberryPi and consequently cause ATXRaspi to loose power.

! MORE IMPORTANT ! Make sure you DO NOT plug in power to the RaspberryPi directly while ATXRaspi is connected. This might cause damage to any of the boards involved.

1. Install the WiringPi library (I installed mine from the /home/pi directory).
This library gives you easy access to RaspberryPi’s GPIO.

First install git if you don’t have it installed:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install git-core

Download WiringPi from github and build it:

$ git clone git://git.drogon.net/wiringPi
$ cd wiringPi
$ ./build

2. Copy the shutdowncheck bash script to your home directory – /home/pi/ and add the proper execute rights:

$ cd ~
$ wget https://raw.github.com/LowPowerLab/ATX-Raspi/master/shutdowncheck
$ sudo chmod 755 shutdowncheck

The script is located at: https://github.com/LowPowerLab/ATX-Raspi/blob/master/shutdowncheck

NOTE: Someone reported some corruption when copying the scripts from github. This is not apparent because newlines are interpreted differently on different OSes. If you experience problems with the script not running or generating errors, try typing the script yourself using “sudo nano schutdowncheck”.

3. Edit your /etc/rc.local file (sudo nano /etc/rc.local) and add the following line before the last line (exit 0):

(cd /home/pi && exec ./shutdowncheck) &

This should start the shutdowncheck script during initial booting and you should see these messages towards the end of the Pi’s startup (if you’re not booting to the GUI):

ATXRaspi shutdown script starting…
Asserting pins (7=in,low; 8=out,high)

The shutdown script will take on average 0.7% of the CPU:

CPU_percent

That indicates the script has started and is running, waiting for a shutdown signal from ATXRaspi.

 

4. Connect your RaspberryPi to ATXRaspi. But remember: make sure the RaspberryPi is disconnected from power since ATXRaspi will power your Pi (no cable going to the micro USB). The given GPIO pins are given as examples, you may change them to others as convenient (update the script as well), or if you have a Rev 2.0 Pi you can use the P5 header instead. Here’s how I wired ATXRaspi:
  • GPIO7 (input to Pi) to outgoing arrow pin on ATXRaspi.
  • GPIO8 (output from Pi) goes to incoming arrow pin on ATXRaspi.
  • Connect power from output header (+/-) of ATXRaspi to GPIO power pins (5V/GND) on RaspberryPi
  • Connect a momentary button and status LED to ATXRaspi’s top header (no resistor needed for LED).

When done, the wiring should look something like this

ATXRaspi_wiring_to_RaspberryPi!! NOTE !! You should use good quality wires (especially for the power signals), ideally stranded and not longer than 6 inch. They should make tight/strong connections with the headers on both ends. This is very important because at startup the Pi will draw a lot of current for a short period of time. If the wires cannot handle the inrush of current, a drop in voltage might occur, causing ATXRaspi to reset and power to be cut-off from the Pi. The symptom will be this: you will press the button, power is turned on for an instant, then turned off, and may require several button presses before power will stay on.

5. Done!

Possible/known issues

1. Need to push button a few times before power up. This could happen for several reasons. Rev 2.0 Pis are more prominent to having this issue. A few things will help eliminate such behavior:

  • using a good power supply that will handle the big current spike at power-up. In other words a supply that will not drop voltage significantly upon the power-up current surge. Phone charger type supplies tend to be flaky, unless you got good brand ones rated at 0.8-1Amp.
  • using a ferrite bead around the + supply line going into the Pi (also see Mike’s video above). This helps with the inrush of current or possible harmonics introduced by high energy spikes when the Pi starts up. Wrap the + wire through a ferrite bead several times, that will increase the inductance and slow down the current, avoiding a big voltage drop
  • using heftier jumper wires for the power lines going to the Pi
  • soldering the wires to your Pi (Mike did it in his setup using the P5 header)

2. Disconnecting ATXRaspi and powering up the Pi directly will cause it to shutdown sonn after boot up. This is because the signal ATXRaspi was using is setup as an input without a pull-up/pulldown resistor which might be floating and be picked up by the shutdowncheck script. To eliminate this problem – comment out or remove the line you added in the /etc/rc.local file before you disconnect ATXRaspi (otherwise you might not have another chance to do it with ATXRaspi disconnected – because of repeated shutdowns).

Soldering Steps

1. Start with the smallest part, the micro USB connector. Align it with the pads and hold it with a clip or helping hand. Solder one side pad, then continue to solder the rest of the pads. This may be challenging if you are not comfortable soldering SMT components:

Solder one side pad first

Solder one side pad first

Then solder rest of pads

Then solder rest of pads

2. Insert the resistors matching them with the silkscreen markings for their values. Use a resistor color code map if you need to. Spread their leads on the other side so they don’t fall out when you flip the PCB, then proceed to solder each joint. When done clip all the leads with a flush cutter:

 DSC02560_ DSC02562_

3. Repeat for the rest of the larger parts, again spreading the leads to keep them from falling out when soldering. Make sure you match the large electrolytic capacitor negative lead (silver stripe on side) with the “-” on the PCB. Also match the silver stripe on the diode with the direction of the arrow (cathode). Also match the notch on the chip holder with the notch on the PCB silkscreen.

 DSC02565_2 DSC02564_ DSC02566_

4. Gently bend the ATTiny microcontroller pins to make them parallel and insert them in the holder, making sure you match the notch on the holder/PCB with the pin marked with a dot:

DSC02570_

5. Using a pair of pliers clip the male header into 3 headers: 1×2, 1×4, 1×6. Insert them one by one and hold them in place with your helping hand while soldering:

 DSC02572_ DSC02574_ DSC02578_

6. Complete:

DSC02674_

 

Outline/dimension diagram

Dimensions