I came across a number of tutorials for adding power, reset, and shutdown buttons. That's how I came across this question; looking for a how-to.
This particular tutorial will give you reset
and shutdown
on any arbitrary pin, but I don't think it will do power on
, like using pin 5/GPIO 3 will do.
Combined Restart / Shutdown Button for Raspberry Pi
A very simple systemd service for Raspberry Pi that provides a
software-controlled restart / shutdown button. Code:
scruss/shutdown_button Use
Default behaviour is:
your Raspberry Pi will reset if the button is held for more than two seconds but fewer than five seconds;
your Raspberry Pi will shut down if the button is held for more than five seconds.
By default, the software assumes the switch is connected to pin BCM
27. Both the pin and the timing can be changed in the Python source file.
To get all three functions, it looks like you have to use pin 5/GPIO 3, like with this library (Github, blog; a different blog with the same solution) (emphasis mine):
pi-shutdown
Shutdown/reboot(/power on) Raspberry Pi with pushbutton Usage:
Connect pushbutton to GPIO pin 5 and ground then run:
sudo python pishutdown.py
When button is pressed for less than 3 seconds, Pi reboots. If pressed
for more than 3 seconds it shuts down. While shut down, if button is
connected to GPIO pin 5, then pressing the button powers on Pi.
While I was poking around pinout.xyz, it seems that WiringPi lets you do i2c on pins 8 and 9. I confirmed that by doing a DDG search and coming across this relatively recent Reddit thread where a user had a PEBKAC problem and eventually got i2c working. You could use WiringPi for your i2c needs, and then the top method for your power button.
As far as the Pimoroni board you mentioned, if you are willing to use multiple buttons, you could also use an arbitrary GPIO pin for software-based reset and power off, and then the additional button could go to the run header for hardware based reset and power on. I haven't checked out their code, but that might be what they are doing.