How to keep track of rain with photon and deep sleep?

I’m currently tweaking my photon with battery shield and solar panel to obtain the optimum timing of sleep vs wake so that it will provide a net gain to the battery during the day and in theory work indefinitely. My one question though is about the rain gauge. Obviously when the photon is in deep sleep it will potentially miss bucket tips if it’s raining and a tip occurs while sleeping. I suppose I could modify the code to insert a delay before sleeping should a bucket tip occur to see if another one happens and then if it does, delays again the sleep mode. Only problem with this is that if we have a prolonged period of rain it could potentially drain the battery completely.

Now the only solution I see is the aforementioned one with a mechanism to shut the system down before the battery gets critical or I employ a larger battery (I have a 2000maH lipo right now) with a larger solar panel and possibly a sunny buddy. My inclination is to do just that, beef up the battery and solar panel (perhaps 2 panels) and go with the MPPT functionality of the sunny buddy. On the other hand I could just go with a 6000maH battery or perhaps an additional paralleled 2000 maH battery to survive a longer period of outage. As long as I get enough sun to get a net gain in the battery I should be able to get out of the woods.

Am I on the right track or is there some way to keep track of the bucket tips even in deep sleep mode?

Could you not use an interrupt to sleep/wake instead of time? Tip fires event, Photon wakes up, does whatever logging etc you need, waits around for a bit…goes back to sleep and sets the next wakeup interrupt. Make sure you understand what could/would persist across wakeup/sleep events but seems to fit the bill here, otherwise you are keeping things awake when it is least likely to be getting good solar energy.

https://docs.particle.io/reference/firmware/photon/#system-sleep-sleep-

I like this idea to trigger the wake up on the rain bucket tip, but my next question is this then, the code used to push to weather underground keeps track of the amount of rain in the past 60 minutes, but with the photon deep sleeping how will that be possible if I need to sleep the unit say every 2 minutes for say 6-7 minutes? Because the deep sleep wipes everything and reloads the firmware every time. Maybe I don’t fully understand how that works but there must be some place that this info gets stored in a non-volatile way?

EDIT: I think I answered my own question…if bucket tip, stay awake for 60 minutes, if another keep staying awake, if no bucket tip in the meantime, go back to sleep and resume normal sleep wake cycle.

Is System.sleep(uint16_t wakeUpPin, uint16_t edgeTriggerMode, long seconds) valid for a photon or will this only work on a core? This seems like the magic bullet for me.

System.sleep(wakePin, triggerEdge, sec) should work with the Photon too, but has a somewhat higher power consumption during sleep.
But for deep sleep you could use the dedicated WKP pin for waking the device and use the retained features that allows to “save” status accross system restarts without the need to put them into flash.

If power consumption is an over all issue, you might also like to give “multi level” power saving strategies a thought.
e.g. if you know you might miss some thing when going to sleep, you can stay awake but deactive WiFi.

Ah I like that better, so things like wind gusts and rain counts I could retain across resets. I’ll have to play with this. I like the challenge of making this work as is rather than the elephant gun solution of bigger batteries and solar panels, thanks for the tip.

Yes, I’m sure it will evolve over time as the real world imposes these changes. Right now I’m just testing the unit with it in a somewhat south facing window indoors before I deploy it, so conditions for the solar panel aren’t ideal, but then again I want to tweak it for non-ideal conditions just because that’s reality…lol.

@raenrfm, there is another approach you can take which will ONLY work on the Photon. This approach uses the WKP pin to wake the Photon from STANDBY mode vs using the timed sleep or an interrupt pin which put the process in STOP mode and uses more power.

A rising edge on WKP (this implies a pull-down resistor on the pin, eg. 10K), will wake up the Photon and reset it. If power on the VBAT pin is maintained (connect it to the VIN pin which is connected to the power source), then a portion of RAM will be maintained duing deep sleep. So, every time you wake up via a bucket tip (causing rising edge on WKP), you can increment the counter (since you know the wake came from the bucket tip event) in sustained RAM and also check the RTC to see if 60 mins have gone by (keeping the last time in sustained RAM as well). When that time expires, you connect to wifi and the cloud, send your data and go back to sleep. Otherwise, you just go back to sleep.

This will keep your power consumption WAY down. :smile:

1 Like

Been there :wink:

But the extra info about pull-up and VBAT I missed out :blush:

1 Like

Just to clarify, when you say STANDBY you mean DEEP SLEEP?

NVM, I just re-read your post, obviously it’s for DEEP SLEEP…lol.

One more thing, if I tie the Vbat to the Vin, wouldn’t I be bypassing the zener diode on the photon battery shield?

Also the pull down 10k resistor, that will be from WKP pin to D2 on the weather shield (rain bucket)?

@peekay123 , connect the Vbat to Vin which is 5 volts ?, are you sure that does not sound right to me , nmore like the 3.3 volt pin .

i’m looking at the same problem of rain monitoring etc on battery , but I’m looking at some form of counter to counter to tips and spend most of it`s time asleep.

It acutally is 3V3 to VBAT. Another option might be a coin cell just for VBAT and you’d only need 1.67V to keep the retained data.
For proper use of the VBAT pin you might want to browse the docs and the forum.

And for the pull-down. Pull-down resistors need to be placed between the pin to pull down (WKP) and GND.


@peter_a: I know, I’m repeating myself, but you’re still using the wrong character for apostrophes :wink:

Yes , edited it , but missed one

I guess the 10k resistor will be tied to ground from the WKP pin because it’s active high, then tie my D2 pin (rain bucket) to WKP.

As for retaining memory wouldn’t just enabling the the backup ram be enough if I do not detach the battery? Shouldn’t it just draw the power from Vbat from the battery sheild?

Retaining memory works without using the Vbat pin , lile you say until you remove power from Vin

You could, but you also could just use WKP (=A7) instead of D2.

About VBAT, sure you can do this, I just wanted to throw in another option that would even allow retaining data and RTC when your LiPo drains.

But the rain bucket is connected to D2 so how would I wake the unit if I don’t tie this pin to WKP in some way?

I’m lost a little why use D2 at all ?

How do I trigger a wakeup with the rain bucket if the photon is in deep sleep, don’t you need the bucket to transition to pulse the WKP pin?

I guess I’m a little lost myself.

I guess basically I’m thinking I need to use the physical bucket as a switch to trigger the WKP pin, so that trigger comes via D2 does it not?

We have established that currently you have D2 wired to your bucket. And you read D2 or have an interrupt attached to it.

Assuming this was your free decission to use this pin, you could have well decided to use any other pin, or not?

And as it happens you need to use WKP to wake the device from deep sleep, you could just decide to forget about D2 and use WKP/A7 in place of it completely.
Sure you could bridge D2 and WKP/A7, but why using two pins if you can do the same thing with using only one?