How to capture power button pressed signal?


I have an Orin NX 16G module, and an IIC device connected to board.
I want to capture the power button pressed signal when it going to power off, so i can terminate the IIC device properly.

How can i capture the power button pressed signal?
Looking for reply, thanks!

Are you talking about devkit or 3rd-party board? There is no power button on devkit, only a header with pwr_btn signal.

Hi, Trumany.
Thanks for your reply.
Yes, I’m using a devkit with carrier board. And a button connnected to the pwr_btn pin.
Finally, I got, and it works!
Post bellow, hope it helps who meet the same question.

$ cat /usr/local/bin/

# ansible managed

# systemd-logind prints a line of the form 
# Dez 21 11:12:10 systemd-logind[748]: Power key pressed.
# on key press, but doesn't handle the button because gnome3 blocks systemd from doing so.
# See `systemd-inhibit` for that.

# first sleep a minute so we have chance to disable this scritp if it runs amok
sleep 1m

# so we workaround gnome a bit here.
journalctl -u systemd-logind --follow --lines=0 | \
while read line ; do
    if echo "$line" | grep --quiet 'Power key pressed'
        systemctl poweroff

and the service file that starts / restarts it

$ cat /etc/systemd/system/shutdown_button_monitor.service
# ansible managed

Description=Power off the machine if the power button is pressed
# Workaround for gnomes block of the shutdown button
# Monitor these blocks yourself with `systemd-inhibit`



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