Strategies for better battery management

As a side note - we’re working on new documentation and examples - you can find them here.

I’ll make a note that we need more sleeping/power management examples :slight_smile:

Again, you guys rock. I’ll give that a try. It’s like Christmas in September waiting for answers from you guys. :slight_smile:

Of course, the agent way means that if I write code for the Imp that makes it sleep and keep WiFi OFF until it sees a reason to report back, the cloud cannot flash it, right?

Funny thing happened at the office today (just now). I updated my Imps from my desk at work. My Imps are sitting on my desk at home in the man cave. The light is not changing in the man cave because nobody is home. Therefore, my Imps are not talking to me or the cloud because they’ve been told to shut up until there’s something interesting to talk about.

This is true regardless of whether you’re using agents or not.

If you manage your power/wifi so the imp never contacts the server, the only way to flash it from the cloud is with a cold boot / power cycle (a power cycle will always force the imp to try and contact the imp cloud).

Awesome. This thread alone is excellent documentation on the basics of using a web service and keep power draw to a minimum. Thanks again!

Always happy to help :slight_smile:

And, I’m back! :wink: Everything is working AWESOMELY now! You guys have been a tremendous help and for that I thank you! Now I have a fun question, not a mission-critical one…

I’m having a heckuva time trying to calculate battery life on my project because the little buggers sleep for 5 seconds at a time, wake for a quick check on an ambient light sensor on the ADC, fire up WiFi ONLY if needed, then go back to sleep. My not-so-expensive Radio Shack DMM doesn’t get a good or stable read on the current draw quickly enough to give me good feedback. I’m going to package these little things with a LiPo battery, but want to choose as small a battery as possible to give the thing a long life on the wall while keeping bulk down. Empirical (or, shall we say, “Impirical?” [Sorry, had to do it]) evidence shows me that now that I have all of the sleeping and waking figured out, the LiPo batteries are barely being drained by the Imps. It’s quite impressive. But, I can’t get a good enough read that way to really guess at how long a certain mAh battery will last, so now I’m down to math or best-guessing.

So, just a quick theoretical question on power draw: Given an Imp on a Sparkfun BOB-11400 “Electric Imp Breakout” board, a Sparkfun BOB-08688 “TEMT6000 Breakout Board” connected to the ADC (PIN9) and a wake from deepsleep() every 5 seconds to read the ADC and during that wake time only occasionally firing up WiFi (say, every 15 minutes on an average day), any guess as to what the draw might be for a wake where there is NO WiFi and for one where there is? When WiFi is turned on, a simple JSON packet is sent and a log message is given to the agent.

Any thoughts, even theoretical, would be greatly appreciated!

If you used shallow sleep the calculation would be simple. It’s simply the same current draw that everyone uses while sleeping. It only takes milliseconds to read the ADC. Every 15 minutes would use less average current than 7ma.

But your case is different. Are you sure it is less than 7ma average? If not than it’s time to change strategies. If so than you need to find the average current somehow. Maybe with an old analog meter? Do some modern meters have the averaging feature?

This may interest someone concerning battery usage for a Quadcopter with Li-ion cells. The current usage is much higher averaging 10-20C at times. You will only get about 50% of the theoretical ENERGY capacity of the battery. 64% of the mAh. There are 3 inefficiencies that I can estimate:

20% reduction in mAh (depends on 10-40C)
20% reduction in voltage including short wires
20% reduction because you stop draining at 3v only using 80%

These are only estimates and additive but not how you might guess:
20+16+14=50%

I’ve measured all these with a digital charger. Compared slow discharge vs 70A. Most batteries have 10% more capacity than they are rated.

Questions?

I’m currently using 2,000 mAh single-cell LiPo batteries from Sparkfun (https://www.sparkfun.com/products/8483) and last night they got a full charge and the DMM showed about 4.2V, give or take a fraction. Prior to configuring the Imps the way I have them now, they weren’t sleeping correctly and kept calling back to home every 5 seconds, but the batteries still survived an entire week and only dropped to about 3.6V from the previous charge, which was from the factory.

The current firmware, thanks to Hugo and imensor, is sleeping properly and it is deepsleep(), as I stated above. So, I’m not as concerned about the battery as I am the draw. I’ve read up on the batteries, but I really need to know roughly what I’m looking at as far as draw. It seems that in deepsleep() they’re doing very, very little, like in the µA range. The info I’m trying to find is what the ADC might be doing when it’s being polled and what the WiFi adds to that for the brief one second or so that it’s all on.

Like I said above, doesn’t have to be perfect, just looking to get a better idea of the draw when it does wake up, both with and without WiFi, both way with the ADC being read. I can then calculate out what it would draw over X days or X months.

These devices I’m building sit in rooms and watch light cans in the ceiling. They only send over WiFi if the delta from the current reading and the previous reading cross a threshold, otherwise they just go back to deepsleep() for 5 seconds again.

The overall idea here is to NOT have to run power over wire to these little guys but to use a right-sized LiPo rechargeable and HOPEFULLY only have to recharge them once a year or even less frequently. Also, if I can get a year or even 6 months our of a 1,000 mAh LiPo, I can make the device smaller than a pack of gum and that would be REALLY awesome.

Thanks again for everyone’s input!

Traditionally 5 sec is not long enough to make deepsleep worthwhile. But let’s go thru the calculations to find out. How long is the total cycle from wake to the next wake? That would be 5 seconds plus how long it takes to wake. Of those 5 seconds part of it should be microamps, and part of it a few milliamps, and perhaps more while it’s waking. Take a guess at the readings and length of time, by measuring. Don’t worry about the Wifi every 15 mins for now.

Seems to me that if a device is on solidly 24/7 vs. 1 second at a time every 5 seconds, that should equate to a much lower draw per (for instance) hour. Maybe I don’t really understand this stuff as well as I thought I did, but in a perfect world (just to keep math easy)…

All hour long, each hour, a bright white LED has a draw of 20 mA @ 3.4V and let’s say we have a super-efficient CCR in series with the LED instead of a resistor to keep the losses to a minimum. That’s a 20 mAh, right? A 2,000 mAh battery should be able to power the device for roughly 200 hours, correct?

Back to my Imp-based device (and let’s assume it draws 20 mA while awake, again for easy math): If the device deepsleeps for 5 seconds and then is awake for, say, 1 second, it will draw 20 mA for 10 seconds of each minute (5 seconds sleeping + 1 second awake = 6 seconds, 60 seconds ÷ 6 = 10 seconds). That’s 600 total seconds of drawing 20 mA each hour. That looks to me like it’s a 83% reduction in power consumption. 17% of 20 mA = 3.4 mA, so the Imp device should be able to survive on a 2,000 mAh battery for roughly 588 hours (24 days), correct? If the draw is actually only down around 5 mA with no WiFi going on (I’m just pulling a number out of the air that seems decent), then 17% time of 5 mA in an hour makes for 0.85 mA, so 2,000 mAh ÷ 0.85 mA should be roughly over 2,350 hours, or almost 100 days.

What I’d LOVE to hear is that the process of the Imp waking from deepsleep, reading the ADC, deciding to NOT call home over WiFi and then going back into deepsleep again takes 1 mA or even µAs.

It’s also possible for me to extend that 5-second cycle to upwards of 10 seconds. It’s monitoring the occupancy of a room by way of the lights turning on and off. If someone leaves the room and another person walks right in behind the first person and that all happens in less than the frequency of the reading, the result is still the same.

This stuff is so cool. :slight_smile:

You’re on the right track. Let’s assume it takes 3 secs to wake up. Let’s say it’s using 80ma during that time. The average is then 3/8*80. In this case the average is 30ma. This is more than 7ma you could achieve using a different method.

The question is how much does it use (average) during those 1 or 3 seconds?

Don’t forget to subtract 20% of the battery capacity in mAh since you’re not going to go below 3.0v.

Don’t forget self-discharge about 10%/mo or 1ma.

Excellent and thanks for the extra info. I’m going to try to find a way to get a more accurate reading on the draw, but I think the idea will work the way I have it set up and I think the batteries will last quite a long time. Pretty good for being homemade, either way.

When I power my imps directly from a battery they often keep running with wifi down to 2.5 volts.

WITH wifi? Interesting. What kind of battery? My results show 2.9V. Which is correct?

I cannot do this with Li-Ion because it starts at 4.2v which is too high and will cause damage, so I go thru April regulator. It works down to 2.9V measured after the V Regulator, which is perfect, because the battery voltage is just over 3v. It would go much lower without Wifi, but then I would harm the battery. This test was done with an old tiny Li-Ion 80mAh battery. A big one would be slightly different results. It will boot and connect 10x AFTER the Vcc gets to 3.3v. I send the Low battery warning message when it gets to 3.1v giving me 2x more reserve.

Here’s the important part of the experiment with April board. Normally it takes 20ua during sleepfor, but when the Vin < 3.5v it uses 200ua. Has this been fixed in the new firmware? Will it be? I think not, as it’s the regulator causing the “problem”. Have I misunderstood anything? Please let me know.

I bet 3x 1.2v NiMh could be hooked directly, as long as they were not completely charged. 2x 1.2v would not be enough for long. 4x 1.2v is the ideal solution going thru Hannah regulator. In this case the 200ua problem will not occur.

I’m using 2x Lithium/Iron Disulfide (Li/FeS2) to an April via 3.3v pins which bypasses the regulator stuff. http://www.farnell.com/datasheets/9583.pdf
They can be a bit high when first installed 3.6v but the imp card specks say 3.6v max

I don’t quite believe this but trace is when the imp gave out last down to 2 volts I’m logging hardware.voltage() http://industrialinternet.co.uk/eimp/battery/imp_battery_trace.png

I’ve been looking at these http://uk.farnell.com/varta/6117101301/battery-lithium-cr-aa/dp/8636192

Your 9583 link shows 2x 1.6v = 3.2v much less than 3.6v max.
I like your LI/FeS2 batteries but they’re not rechargeable?
Is your 2.0v experiment repeatable? I don’t quite believe it either. Hugo?

Wait I get it! My 2.92v is measured immediately after a warm boot, but before agent.send(). There is no current draw before the measurement, and the sleep time is long enough, so that’s the floating voltage. Your 2.0v is possibly measured AFTER a Wifi connection? My battery is tiny, so it immediately drops to about 2.2v. Another digit of precision is needed.

Hugo says 3.0v so that agrees with my experimental results of 2.9v.

@Andy- I have done some tests. There is no overhead for waking from deep sleep without Wifi. Therefore your current draw should be about 15ma x the number of milliseconds to take the ADC reading. Your biggest drain will be self discharge of 1ma.

Your 9583 link shows 2x 1.6v = 3.2v much less than 3.6v max
Yep but have seen 3.6v

Is your 2.0v experiment repeatable?
Yes in so much as as the series plot has the imp running for days at >2.5v

is possibly measured AFTER a Wifi connection
Not sure but will try using server.isconnected() and then do hardware.voltage() and then post to DB

like your LI/FeS2 batteries but they’re not rechargeable?
No their not :frowning: