[ Note: this is the continuation of another question, the first one being my attempt to implement the same idea using an N-channel MOSFET. Based on the answers I received there, I went out, bought a P-channel MOSFET, and found myself with even more questions than before :) ]
I am trying to implement something similar to this: https://youtu.be/nbMfb0dIvYc?t=4m27s
The idea is that the microcontroller (a Wemos D1 Mini in my case) is powered up by an external switch. As soon as it starts up, it sets up a MOSFET so that it can keep its power connection until it finishes whatever job it is set up to do. In the end, it "kills itself" by cutting of the power through the MOSFET.
So I bought a P-channel MOSFET (IRF9Z34N - probably not ideal with a Vgs(th) max of -4V, but it was the best through-hole part I was able to find). And I built the following circuit:
When I press the switch, the D1 powers up correctly, pulls the MOSFET gate pin low, and goes through all of its code. In the end, it pulls the gate pin high, powering itself off.
However, something is wrong. When powering itself off (after setting D5 to HIGH), I would have expected the gate voltage to go to +5V through the pull-up resistor. Instead, it stays at around 1.25V - enough to keep the MOSFET partially open, with enough current going through it to keep the MCU in some weird, not-alive-but-not-dead-either, state (the MCU doesn't receive enough current to keep running its code, but it receives enough to prevent it from fully resetting and starting over again when I press the switch).
Based on the suggestion received from Brian Drummond on my original question, I built a dual-MOSFET arrangement:
This seems to work - but it seems needlessly complicated, especially compared to the original schematic (see youtube video above, starting at 04:24).
So my question is: is there any way to "save" the original schematic? Can I implement this using just a P-channel MOSFET? If so, how?
If it helps, here is the schematic for the Wemos D1 Mini. Note that I am powering it through the 5V line, which then goes through a power regulator.