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 the system with a single push button.
This tutorial has been developed by sitelec.org.
Below are detailed the circuit running steps.
Please refer to the attached schematic and simulation diagram:
X: 2s / div, Y: 0.5v / div
ATX_PS-ON (yellow) (measure)
PWR_SW (reg) (simulation)
RPI_GPIO (blue) (measure)
RPI_UART0-TXD (green) (simulation)
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.
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.
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, its PCB remains powered but the RPI_UART0-TXD pin goes to the ground, Q1 is then cutted-off and the PSU stops.
Through an SSH client, login on your RaspberryPi.
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
To allow the push button to trigger the RaspberryPi shutdown, the circuit has to be connected to a GPIO.
Download the attached rpi_shutdown.py script.
You can edit it to change the following values:
Copy the script to /usr/local/bin and make it executable:
sudo chmod +x /usr/local/bin/rpi_shutdown.py
Install its dependencies, like gpiozero:
sudo apt-get -y install python3-gpiozero python3-pkg-resources
Enable it at the system startup:
sudo crontab -e
add the following in the opening file:
@reboot /usr/local/bin/rpi_shutdown.py &
This script has been written according to the following documentation: https://gpiozero.readthedocs.io/en/stable/recipes...
Properly reboot your RaspberryPi:
sudo reboot
You can now connect the circuit to the RaspberryPi and to the PSU and test the following: