Skip to content

RaspberryPi ATX PSU control module

All ressources are on project GitHub page. This project was made in collaboration with Patrick Abati, Sitelec.org.

In a system composed of a RaspberryPi powered by an ATX power supply unit, the goal of this circuit is to allow to power on or power off properly the system with a single push button.

Schema

Functional presentation

Below are detailed the circuit running steps.

Power on

This circuit acts on the ATX_PS-ON ATX PSU pin to trigger its power on or power off. By default, this pin is set to 5V, which means the PSU is stopped.
To power on the PSU, the circuit has to set ATX_PS-ON to the ground.

When the push button is activated, the Q2 transistor sets ATX_PS-ON to the ground, which triggers the PSU power on and the RaspberryPi startup.

System running

At startup, the RaspberryPi set its RPI_UART0-TXD pin to 3.3V, acting on Q1 transistor which keeps the PSU active by keeping ATX_PS-ON to the ground.
However, it may take some time before RPI_UART0-TXD goes to 3.3V (2.6 seconds on RaspberryPi 3). The RC sub-circuit on Q2 base is designed to maintain the transistor saturation enough time.

The C1 capacitor absorbs voltage variations on RPI_UART0-TXD pin, which is useful if the RaspberryPi UART is used because it keeps the system active.

System shutdown

A new pression on the push button is detected by software on the RaspberryPi by reading an input GPIO pin, the system shutdown can then be performed.
Once the RaspberryPi is stopped, it remains powered but the RPI_UART0-TXD pin goes to the ground, Q1 is then cutted-off and the PSU stops.

Simulation

Simulation

  • X: 2 seconds per division
  • Y: 0.5V per division
  • yellow: ATX_PS-ON (measured)
  • red: PWR_SW- (simulated)
  • blue: RPI_GPIO (measured)
  • green: RPI_UART0-TXD (simulated)

The KiCAD project used for simulation is on the project GitHub page.

RaspberryPi settings

Through an SSH client, login on your RaspberryPi.

RPI_UART0-TXD pin set to 3.3V while running

First, configure the RaspberryPi to set RPI_UART0-TXD to 3.3V while running, to keep the PSU active. To do this, edit /boot/config.txt and add at the end:

enable_uart=1
enable_uart=1

RaspberryPi stop triggered by GPIO

To allow the push button to trigger the RaspberryPi shutdown, the circuit has to be connected to a GPIO.

Download this Python script:

You can edit it to change the following values:

  • HOLD_TIME: time to keep the button pressed to trigger shutdown (this value is distorted by C2 which keeps the level for a while after the button is released)
  • PIN_NB: GPIO number to use

Copy the script to /usr/local/bin. Make it executable:

sudo chmod +x /usr/local/bin/rpi_shutdown.py
sudo chmod +x /usr/local/bin/rpi_shutdown.py

Install its dependencies, like gpiozero:

sudo apt-get -y install python3-gpiozero python3-pkg-resources
sudo apt-get -y install python3-gpiozero python3-pkg-resources

Enable it at the system startup:

sudo crontab -e
sudo crontab -e

add the following in the opening file:

@reboot /usr/local/bin/rpi_shutdown.py &
@reboot /usr/local/bin/rpi_shutdown.py &

This script has been written according to the following documentation: https://gpiozero.readthedocs.io/en/stable/recipes.html#shutdown-button This script has been written according to gpiozero documentation.

Properly reboot your RaspberryPi:

sudo reboot
sudo reboot

You can now connect the circuit to the RaspberryPi and to the PSU and test the following:

  • the PSU is kept active as expected by the RPI_UART0-TXD RaspberryPi pin
  • pressing the button triggers the RaspberryPi shutdown, which stops the PSU

GitHub project page
Instructables project page
Sitelec.org project page\