Wake up ESP8266 with multiple GPIOs

Hi!

I am building a ESP-07 based IOT device, that detects the status of 4 doors. The device must connect to WiFi and send an http request, when 1 of 4 doors is opened. The battery consumption should be minimal, so I thought of using deepsleep () or something similar to keep the device asleep most of the time, or keep it completely off (like most Dash buttons does).

I have studied several options, but almost all use a single GPIO to wake up the device. For example, this option wakes the device up if D3 goes high, and sleep if D3 is low.

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#define WAKE_PIN D3

const char* ssid = “SSID”;
const char* pass = “PASSWORD”;

extern "C" {
    #include "gpio.h"
}

extern "C" {
    #include "user_interface.h"
}

void setup(){
    WiFi.begin(ssid, pass);
    uint8_t i = 0;
    while (WiFi.status() != WL_CONNECTED && i++ < 10) delay(250);
    Serial.begin(115200);
    Serial.println("Setup");
    pinMode(WAKE_PIN, INPUT_PULLUP);
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, LOW);
    gpio_init(); // Initilise GPIO pins
}

void loop(){
    Serial.println("Do something...");
    if(!digitalRead(WAKE_PIN)){
        sleep();
    }
    delay(1000);
}

void sleep(){
    Serial.println("Going to sleep...");
    delay(10);
    wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); // set sleep type
    gpio_pin_wakeup_enable(GPIO_ID_PIN(WAKE_PIN), GPIO_PIN_INTR_HILEVEL); 
    wifi_fpm_open(); // Enables force sleep
    wifi_fpm_do_sleep(0xFFFFFFF); // Sleep for longest possible time
    delay(100);
    Serial.println("Woke up!");
}

Here, GPIO_ID_PIN(2) corresponds to GPIO2 on ESP8266-01 , GPIO_PIN_INTR_LOLEVEL for a logic low, can also do other interrupts.

My question is:

Can I use more than one GPIO, that is, one of 4 GPIOs to wake up the device?

I have the problem of knowing which of the four doors has been opened!

The other option I have thought is to use a latch circuit that turns on the (previously turned off) device using a single GPIO. Something like this:

Can I use more than one GPIO, that is, one of 4 GPIOs to activate the latch circuit?

Thanks in advance!

Follow this thread in Stack Overflow.

I am very good with esp8266 but this is really not a esp question your question is a bit vague but I am assuming you have sensors on each door?

and these sensors are able to tell your esp8266 they are open???

I just re read this you are interested in waking up the esp. In my opinion yes you would use one pin to wake it up and then you read the status of all doors after awake and take appropriate action.

I would have an easy way to check status of all doors and if any door is opened or closed I would use a gpio to wake up the chip and then take a door status check send results and go back to sleep

Mark

DON'T CROSS POST!!!!!!!!!!!!!!!!!!!!

I HAVE REPORTED THIS THREAD TO THE MODERATORS

ingalfsan:
-1
down vote
favorite

Looks like a sloppy copy paste from Stack Exchange.

If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.

Threads merged.

pert:
If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.

Thanks for the info.

In fact, I copied one of my publication sloppily.

From now on I will be more careful.

As I requested, please add a link here to your Stack Exchange question and also edit your Stack Exchange question to add a link to this forum thread.

mtalent:
I am very good with esp8266 but this is really not a esp question your question is a bit vague but I am assuming you have sensors on each door?

and these sensors are able to tell your esp8266 they are open???

I just re read this you are interested in waking up the esp. In my opinion yes you would use one pin to wake it up and then you read the status of all doors after awake and take appropriate action.

I would have an easy way to check status of all doors and if any door is opened or closed I would use a gpio to wake up the chip and then take a door status check send results and go back to sleep

Mark

Thanks for answering.

My question is a bit vague, actually.

I want to place sensors on each door. A reed switch, for example.

I tried with one single door connected to the GPIO that wakes the chip up. I want to extend the functionality of my program so that any of the four doors wake the chip up.

I could connect all doors to the same GPIO, but I would not know which of them woke him up. I do not know if I can connect each door to two GPIOs at the same time, with some auxiliary circuit. The fact is that I know how to activate or wake up the chip using a GPIO. But I don't know how to wake it up using four different interruptions.

A circuit that turns on the chip instead of waking it up would be great, too. I could connect each of the doors to this circuit, which keeps the chip on for a while. I thought that the chip could send a HIGH to the ENABLE pin of my low-dropout regulator, and LOW when the chip ends the job. But I want to know which of the doors woke it up.

pert:
As I requested, please add a link here to your Stack Exchange question and also edit your Stack Exchange question to add a link to this forum thread.

I just added a link to my original post in Stack Overflow.

Let me explain the schematic a bit more.

I think that ESP-07 can latch its own power on (and off) using an MOSFET pair connected in parallel with the physical (momentary contact) power switch. When the power switch is pressed (or a door is opened), one of the first things the ESP8266 needs to do is latch the power on. When the current iteration of this programm is done, it simply turns it's own power off again.

#define POWER_SW   2   // GPIO connected to POWER_LATCH
 
void LatchOn() {
    pinMode(POWER_SW, OUTPUT); 
    digitalWrite(POWER_SW, HIGH);
}


void LatchOff() {
    digitalWrite(POWER_SW, LOW);
}

This circuit is made to work connected to a GPIO. What I do not know how to do is connect it to the 4 doors using the same GPIO so that I can know which one of the doors was opened, or if I have to use a different circuit connected to each one of the doors.

Also posted to Arduino Stack Exchange at:

Really not sure if you can have multiple pins doing a wake up, but you can always use a bunch of diodes to have all door switches trigger two pins: the shared wake-up pin, and a unique one for each switch.

wvmarle:
Really not sure if you can have multiple pins doing a wake up, but you can always use a bunch of diodes to have all door switches trigger two pins: the shared wake-up pin, and a unique one for each switch.

That is a great idea!

As simple as using a set of diodes. I had not really thought about it. I'm going to try it.

Thanks!

If it works out please write answers for your Stack Exchange questions.

pert:
If it works out please write answers for your Stack Exchange questions.

Off course! I will do that!

A friend from Stack Exchange tolds me and idea:

"Wire the four door-GPIOs together with an OR gate, connect that to your wakeup pin, but still connect all door-GPIOs to 4 different GPIO pins on your ESP8266."

I don't know if an TTL-CMOS OR gate like CD4072 works with 3V3 logic. A simple circuit with diodes or resistor looks better. Any ideas?

And what if I use the ADC or analog input of the ESP-07? I think that with an array of different resistors I can determine which of the 4 doors has been opened.

The 74HC32 is rated to work at 3.3V

You could use a resistor ladder - remember that the ADC input is 0-1V, if your module's analog input is 0-3.3V (such as the NodeMCU) it has its own on-board voltage divider as well, which means it will mess up an external voltage divider.

wvmarle:
The 74HC32 is rated to work at 3.3V

You could use a resistor ladder - remember that the ADC input is 0-1V, if your module's analog input is 0-3.3V (such as the NodeMCU) it has its own on-board voltage divider as well, which means it will mess up an external voltage divider.

Great! I will try that! Thanks a lot!

Hello!

I have an idea. What if I connect each door using a DPST (double pole single throw) switch?

This would be the scheme using two single switches.

My idea is to use the same switch to connect at the same time the RESET PIN and the corresponding pin to each door (for example, GPIO12).

Would there be problems if two doors open at the same time? Would not the RESET pin be overloaded when two switches are connected to VCC?

It won't be overloaded.

But don't mix up a reset state with a power down state. They're not the same. Holding the reset at GND doesn't switch off the ESP, it just lets it sit there waiting for reset to go high again (probably using less power than when fully active but still it's not power down or deep sleep).

If you are willing to use an "external" chip, may I suggest a MCP32008 MCP23008 I2C expander? 3 pins (SDA, SCL, interrupt) for up to 8 switches, interrupt on change of any pin, has internal pullups, very low power. MCP23017 has 16 I/O pins, and there are SPI versions of both chips.