Project

General

Profile

Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode?

Added by julle.p about 2 months ago

Hi,

I have been looking into the low-power code provided in the jeelib library. I have also read the introduction:
http://jeelabs.org/2011/12/13/developing-a-low-power-sketch/

However, I'm wondering how much power does it consume to go into and out of power saving mode?

E.g. if you want to sleep for 10min, you would have to use a for-loop, because you can only sleep for up to 60s. Hence you enter the power saving mode 10 times.

for (byte i = 0; i < 10; ++i)
Sleepy::loseSomeTime(60000);

Any idea on this?


Replies (18)

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by jcw about 2 months ago

My take on this: the overhead is insignificant.

Say it takes 60 µs to go from sleep-mode to wake-up to sleep-mode again: that's 1000 CPU cycles. With 60s sleep, this is a million-to-one on/off ratio, i.e. 10 mA at run time averages out to 10 pA over the sleep phase, which is orders of magnitude less than the µC's own sleep-mode current draw.

It's actually a bit more, since even in those 60s the loseSomeTime() code does a few wake-ups internally, but still insignificant.

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by julle.p about 2 months ago

Thank you, this is interesting!

Somewhere in my code, I want to read a sensor 3 times, and check that I get the same reading all 3 times (verify the reading). I'm not sensitive to a precise timing; would you then recommend going into sleep between the readings, instead of using "delay"?

bool waterState1 = digitalRead(waterPin);
delay(100);
bool waterState2 = digitalRead(waterPin);
delay(100);
bool waterState3 = digitalRead(waterPin);

So the only drawback of using Sleepy::loseSomeTime(xxx), is the lack of precise timing?

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by jcw about 2 months ago

Absolutely - if the rough timing is no issue, I'd always go for sleep-mode.

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by julle.p about 2 months ago

Thank you for your reply. This makes sense :-)

However, I do see an issue. My code is structured like this:

loop()
{
readDigital()
printWaterStateToSerial

readTemperature()
printTemperatureToSerial

flushSerialBeforeGoingIntoSleep

loopDelay!
}

readDigital()
{
readDigitalInput
waitFor100Ms
readDigitalInput
waitFor100Ms
readDigitalInput
returnCombinedValue
}

OptionA.
Using the old method: delay. Things are working well.

OptionB.
Using the watchdog timer as loop delay, but using the old method Delay, in between digital reads. Things are working well.

OptionB.
Using the watchdog timer as loop delay, and also using it in between the digital reads. The serial output are now looking really wierd...

Any idea why the serial starts to look funny?

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by julle.p about 2 months ago

Aha, found the issue.

Actually, my loop looks like this:

loop()
{
printNewLineToSerial
readDigital()
printWaterStateToSerial

...
...

It is very important, that all serial communication is done, before going into sleep mode. Adding a serial.flush() before the readDigital() fixed the issue.

A final thought.
I can see that this library is already some years old. Has the sleep-part been updated since, or does a newer (and better?) library exists for sleep mode functionality, or would you be using this library? Seems like it is working quite good, and it is easy to use - just wanted to ask, if something else could be useful? :-)

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by jcw about 2 months ago

some years old

So is the Arduino. And C. Old ≠ not working. "Aged to perfection", as they say.

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by julle.p about 2 months ago

While is agree with you, I believe there is an exception. Old does sometimes mean outdated or depreciated :-) This is what i meant - however, as I understand your answer, you are pretty happy with the sleepy function in this library.

Thank you for your help. All seems to be working very well :-)

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by julle.p about 2 months ago

I just measured the current when using an Arduino Mega. For my final application I'm going to use an Micro Pro.

When in sleep mode, the Mega is still using 30-35 mA. This is greatly reduced from around 105 mA when using the delay function. However, 35 mA is still a lot... If running on a battery, I will have used 840 mAH in just one day (35mA * 24 h). This means, this is not really suited for a battery - I would then have to replace batteries every day or so.

Is this because the Mega is by no way optimized - would the Micro Pro perform better, i.e. have a lower power consumption?

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by martynj about 2 months ago

@julle.p,

You wrote When in sleep mode, the Mega is still using 30-35 mA.
Did you mean μA? If you are seeing mA, it is not sleeping... Have a scan of the weblog for articles on Sleep mode and the various traps like leaving I/O pins floating etc.
When you get down to the μA, you are finally sleeping. To first order, sleep current draw (once you get there) is likely to be similar across a wide range of processor variants. Think about it - in sleep, almost nothing is running internally so it kinda doesn't matter if the inactive logic is an ATTiny or some galactic Mega, it is inactive. There are second order effects where the manufacturing process can be optimized for lowest sleep leakage (e.g. P designation), which will be directly proportional to the total number of gates on the chip i.e. fat chips gonna leak more.
It's all there in the data sheets.

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by jcw about 2 months ago

All I can say is that with JeeNodes, battery life tends to be measured in months and years. Ultra low-power requires addressing all the current drains. Attached devices, on-board regulators / FTDI, everything must be taken into account. See http://jeelabs.org/tag/lowpower/

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by julle.p about 2 months ago

I found this very interesting post.
https://forum.arduino.cc/index.php?topic=442565.0

He is measuring the same as I:
Change Voltage Awake Asleep
6. Sleep mode 7.2V 63mA 32mA

By doing some modifications, he achieves:
11. Change input to 3.3V 3.3V 13.8mA 3.9mA

So, in sleep mode, 32mA, and after modifications, he can get down to 3.9mA in sleep mode.
Seems like the mega just isn't made for low power :-)

I'll try the Micro Pro tomorrow :-)

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by julle.p about 2 months ago

I have now been testing with my Micro Pro 32U4 (5V, 16MHz).
This is the one I have:
http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=272374507509

which is a clone of:
https://www.sparkfun.com/products/12640

It comes with built-in USB programmer.

I have tested with two setups:

1) Windows driver (in Windows device manager) is using Arduino Leonardo driver. IDE is compiling code for Arduino Leonardo board.
2) Windows driver is update to use SparkFun Pro Micro driver. IDE is compiling code for SparkFun Pro Micro 5V board. This is the recommend setup (I guess) according to this guide: https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide

Both of these methods are working for a simple serial example with a flasing LED, using "Sleepy::loseSomeTime(2000);" as delay.

I am not use why I should not just use the Leonarder programmer?

I have 1 issue though (so far :-)
When using the "Sleepy::loseSomeTime(2000);" method, the serial communication stops working. I write a message at the beginning of each loop iteration, but I only receive one message. The code is still running as the LEDs are flashing as expected, but I am no longer received anything on the serial port on my computer. The serial part is working fine, if I use the normal delay method.
Any idea why this stops working?

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by julle.p about 1 month ago

Solved. See these threads:

ProMicro (ATmega32U4): Serial not working after Sleepy::loseSomeTime
http://jeelabs.net/boards/7/topics/7526?r=7545

Pro Micro: Issue with Serial1
https://forum.sparkfun.com/viewtopic.php?f=14&t=46078&p

Conclusion:
Putting an ATmega32U4 to sleep will kill the USB connection, and powering it up is most likely not enough to re-establish the connection – i.e. the serial communication cannot be used on Serial0 after a sleep. If you want serial communication, you would have to use Serial1.
In order to connect Serial1 to your PC, you need a TTL to RS232 converter, and the a USB to RS232.

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by JohnO about 1 month ago

Well done for getting to the bottom of the issue. Are you using an actual RS232 Serial port on your PC? I use a USB to TTL serial logic level adapter like this or if you have any future plans to look at the JeeNode Zero then this is compatible with both.

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by julle.p about 1 month ago

I'm using an USB to RS232 - not an USB to TTL serial :-) Thank you for your suggestions.

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by JohnO about 1 month ago

OK, so you are using PC to USB to RS232 and then converting RS232 to TTL in order to connect to the ATMega32U4.

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by jcw about 1 month ago

Putting an ATmega32U4 to sleep will kill the USB connection, and powering it up is most likely not enough to re-establish the connection

Have you tried calling Serial.begin() after sleep? Might not be that useful though, even if it works, because USB enumeration does take some time (seconds, I think).

RE: Low-power (Sleepy::loseSomeTime): Power usage for going in and out of low-power mode? - Added by julle.p about 1 month ago

I have ended up buying a USB to Serial TTL. I should get that withing a couple of days :-)
No, it does not work to use Serial.begin(). I have tested with a delay for up 10s, and the serial connection still does not become active.

    (1-18/18)