GPIO - assign poweroff command to a button

Hello folks,

I have a little button that I connected to pins 5 & 6 on my RPi and was wondering how I could assign a script that on button press the simple command "poweroff" is executed.

I have installed gpiod-tools.

Thank you in advance for your input !

Nevermind, someone on reddit was nice enough to answer the question:

For everyone wanting to do the same:

1 - connect your power key to physical pins 5 (GPIO 3) and 6 (Ground).

2 - install kmod-gpio-button-hotplug

3 - in /boot/config.txt, at the bottom of the file, add: dtoverlay=gpio-shutdown,gpio_pin=3,active_low=1,gpio_pull=up

(I think everything apart from dtoverlay=gpio-shutdown is redundant since the rest are default values anyway. If you're using a different pin than 3 (physical 5) you have to state that though).

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.