Imp.sleep(), server.sleepfor() and power consumption

Hi,
I am making a weight scale, the imp is the only controller. Everything works great, except it take couple seconds to download the code before start reading sensor and drive digital LCD display. So basically I need to step on scale to wake imp though Pin1, as long as the imp’s light is green, everything start to work.

(also a naive question here, how can we end shadow sleep? Since deep sleep need download code again, maybe I can use shadow sleep for now.)

Any update for the squirrel in flash thing please?

Longyi

Squirrel is in flash as of release-5 - and hence you can have much bigger programs than you could previously - but right now we still establish the server connection before the code is run.

This will be addressed in the next couple of months, but until then there aren’t any other options.

Not sure what shadow sleep is? Shallow sleep happens constantly any time the CPU is idle, however power is still quite high due to the wifi not being in power save mode. We’ll also be adding options to put wifi into powersave.

by pull up pin1, we can exit server.sleepfor(), but how can we exit imp.sleep()?

I read the document: imp.sleep(Float) “This method causes the impee to enter a low power mode (“shallow sleep”)”

My guess is, the recovery time after imp.sleep(60) should be much shorter than server. sleepfor(60), since there is no need to download the program again, right? But on power consumption wise, I am still not sure how much power imp will consume in imp.sleep(). The Spec mentioned without shutdown radio, it would be 15mA, which is not that bad.

happend to go though drazvan’s question, and saw your following answer

“if you use a UART we have to keep most of the busses up in order to ensure we don’t miss data, so you won’t get down that low.”

does it mean if I am able to disable UART, I can save more power?
Currently UART is only used to send data in my project.
will something like:
imp.configure.pin5(DIGITAL_OUT);
imp.configure.pin7(DIGITAL_OUT);
can disable UARTon pin5 and pin7?
Thanks Hugo.

You cannot ‘exit’ an imp.sleep, it has to complete.

To clarify things: imp.sleep() just pauses the code. This is definitely not something you should be doing for more than tiny fractions of a second, as events are not processed during these sleeps.

If you want to wait 60 seconds, then do something else, the correct way to do this is to use imp.wakeup(time, function-to-call) - for example:

function woken() {
do something;
}

imp.sleep(60.0, woken);
(fall off the end of your code here)

The imp environment is event driven; you should not have infinite loops in your code. Code should do whatever it needs to, then fall off the end of the function/main code block. The OS will call functions that you have registered handlers for (pin changes, wakeups, messages from the server) when needed, and will quiesce the system into the lowest power mode between these calls.

As I’ve said in other threads, the current main power consumer is wifi. There’s currently no way to enable low power mode for wifi in your code, but this will be coming. Until then, you’re going to be around 80-90mA with no way (apart from sleepfor) to reduce this.