ESP8266 How to stop premature power-off triggering

I am using an ESP8266 to run a small app and that’s working just fine. I’d like it to power off in 60 seconds to save the battery. To do this I’m using a Pololu PSW03C triggered by setting connected pin13 HIGH to the OFF pin of the PSW03C. This is all fine and works as expected EXCEPT that at power-on, there seems to be a small spike on pin13 that prematurely triggers the PSW03C to power-off. I know the PSW03C is working correctly as I physically disconnected the wire to the OFF pin, let the ESP8266 start, reconnect the wire from pin-13, let the ESP do it’s thing, then it powers-off as expected.

relevant code is:

const int offPin = 13;

void setup() {
  pinMode(offPin, OUTPUT);
  digitalWrite(offPin, LOW);
}

void loop() {

   // do stuff
  // wait one minute
digitalWrite(offPin, HIGH);   // Power off
}

Any ideas how I can prevent the premature power-off ?

not sure it helps, but try to change the order : first digitalWrite LOW and then set pinMode to Output.

Thanks paulvha, but it didn’t help. The spike seems to happen very early in the boot of the ESP8266, maybe before the init() even, as there is only a very brief flicker of the power led before shutdown.

In the mean time I have found an electronic work-around. I placed a 2.2uF cap between pin13 and a 10K ohm resistor to the the OFF pin of the PSW03C. The cap drains to GND. This way the initial “spike” is absorbed in the cap. This works just fine. and repeatedly.