Can I wake from shallow sleep using pin1 OR millis timer during deep sleep?

Hi!
I’m trying to make a low power pulse counter for electricity consumption measurements.
The challenge is getting the consumption down so I can run it of 2/4 AA batteries.
But is there anyway to keep a timer running during deep sleep, so I can use pin1 to wake it up when there is a pulse reading? Otherwise I was wondering if there is any way of getting the imp out of shallow sleep using external input and not pre-defined periods.
Thanks in advance!

I was trying to ask if it is possible to wake it from shallow sleep using pin 1 - because i need the millis timer to continue running while sleeping (resets during deep sleep).

Pin1 can be configured to wake the imp from a deepsleep. Simply configure it as a DIGITAL_IN_WAKEUP. When pin1 is configured as a DIGITAL_IN_WAKEUP, the imp will automatically pull the pin low with it’s internal pulldown resistor when the imp goes to sleep.

Example Code:
`hardware.pin1.configure(DIGITAL_IN_WAKEUP);

if (hardware.wakereason == WAKEREASON_PIN) {
// code for wake on pin1
}

// …

// put the imp to sleep for an hour (or until pin1 goes high)
imp.onidle(function() { imp.deepsleepfor(3600); });`

You can pass a callback function to pin.configure, to be executed when the digital input pin state changes.

philmy could you elaborate a bit - not sure I understand.

You nominate a function that will be called when the selected pin’s state changes. When the function is called, the imp comes out of shallow sleep. So what you’ve done is essentially wake the imp up with a trigger. This has the benefit that you can do it with any free pin, not just Pin 1 (which is required for wake from deep sleep).

You write something like:

hardware.pin9.configure(DIGITAL_IN_PULLDOWN, myWakeupCallback)

You use the constant DIGITAL_IN_PULLDOWN (or DIGITAL_IN_PULLUP) to keep the pin low until your trigger pulse sets it high (or vice versa). myWakeupCallback() is the function you write and which calls or includes the code you want to run once the imp is awake again.

If you disable wifi whilst you’re looking for these pulses (captured with the callback as smittytone says) then you’ll minimize your power consumption there.