Barnabybear wrote:torntrousers wrote:That is interesting. I've wanted to do the same - having a PIR sensor trigger an ESP to wake up, but i didn't find a way to get it working very well.
I've not tried this yet but i wondered if you could connect the PIR output to the ESP CH_PD so when the PIR is triggered it sets CH_PD high so the ESP starts up and then have the ESP set a spare GPIO high and have that also connected to CH_PD so the ESP stays running after the PIR resets, and then when the ESP has done its stuff set the GPIO low and so the ESP powers down.
If you connected the PIR and an GPIO via a diodes to CH_PD you could pull it independantly of the other:
PIR output -->|- ESP CH_PD
GPIO -->|- ESP CH_PD
The PIR should be able to pull CH_PD high to wake the ESP, then the GPIO should be able to take over holding CH_PD high even if the PIR returns to low untill the task is completed.
We proberbly need some resistors (deffinatly if using a -01); a pull down on CH_PD and a something on the GPIO to hold it high for boot up, not enought to deliver a logic 1 after it has passed through the diode during sleep.
I have parts to test if someone wants to wip up abit of code (I haven't used sleep functions yet). Should be able to post a diagram later.
That would be great. The code to test it could be really simple initially, just something like this which should always output just 10 x "loop" even when the pir output goes low before its done:
void setup() {
Serial.begin(115200);
Serial.println();
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);
Serial.println("setup");
}
void loop() {
Serial.println("loop");
delay(1000);
if (millis() > 10000) {
digitalWrite(5, LOW);
}
}