Not sure whether I'm in the right board, feel free to move it whereever it belongs.
I already did a battery powered project with an arduino, that is working great with a mosfet giving the power supply to the arduino board. A pushbutton momentarily gives positive battery voltage to the gate, powering up the arduino. At the moment the arduino starts, it is holding the gate voltage by an output pin by itself. The mechanical pushbutton is also read by another input pin, to enable a software shutdown by releasing the output pin. Also the software releases the pin, if the project does not recognize any user activity for some time. I took the idea and the dimensioning etc from here
Somehow with the whole boot and shutdown procedure of raspberry it's a different picture. I found out, that the lower GPIO pins (I checked GPIO4) are at high state almost immediately after USB is connected. I could use that to keep the mosfet gate positive and keep the raspberry powered if the user releases the power push button.
Somehow the pin even stays in high state after the raspberry pi has been shut down from console. I was quite surprised by that, hoped there will be no further voltage on the gpio after shutdown.
So how could I release the mosfet gate and steal the voltage from the raspberry only AFTER it is safe to do so, by a gpio pin? From this "power-LED" tutorial
I heard that the serial pin will be low after save shutdown, but I'm not keen on messing around sending serial signals to my power mosfet which is then enpowering the raspberry pi itself. Especially as it seems to change state quite often in the boot process.
The same author has also a power button tutorial, but this only triggers a shutdown from software, I want a hard cut of my power supply to prevent deep discharge of the batteries. Also I have some electronics in front of the raspberry pi (voltage regulation and similar) that will consume energy, if I do not also disconnect them from the battery. A normal switch to cut the 5V from the raspberry pi is no option, because I want a safe shutdown, no sudden death.
I heard there is a way to overwrite the default behavior of pin state at bootup, is there also a way to specifiy the behavior AFTER shutdown?