Sleep mode - LEDs still lit??

Hi,
I’m investigating the sleep modes of arduino and I’ve run into a strange problem. Immediately before putting the arduino to sleep, I’m putting D13 (led) high, and even though the arduino seems to be asleep D13 is still lit? Am I actually putting it to sleep?!?

Led connected to D8 lights on wakeUpNow()
Flying lead connects D2 to -Ve - taking this out wakes arduino.

#include <avr/sleep.h>

int wakePin = 2; // Flying lead connected to -VE 
                 // pulling it out wakes arduino  
void wakeUpNow()
{
 digitalWrite(8,HIGH);
}

void setup()
{
 pinMode(8,OUTPUT);
 pinMode(wakePin, INPUT);
 attachInterrupt(0, wakeUpNow,CHANGE);
}

void sleepNow()
{
 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
 sleep_enable();
 attachInterrupt(0,wakeUpNow,CHANGE); 
 sleep_mode();
 //THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
 sleep_disable();
 detachInterrupt(0);
 delay(75);
}

void loop()
{
 digitalWrite(13, HIGH);
 sleepNow();
}

Thanks - this has got me totally baffled!

Putting the processor to sleep does not change the state of the pins.

To see an effect with SLEEP_MODE_PWR_DOWN, try using analogWrite on a PWM pin.

I have done as you say, and they are very faintly flickering! How bizarre!

So, do I need to write a low to any pins that may be high before sleeping? I thought the the sleep functions would take care of that? Also, my onboard power led stays illuminated whilst sleeping- is this normal? Thanks Coding Badly, that pwm trick made me chucle!

inboxjason: So, do I need to write a low to any pins that may be high before sleeping?

If you want them to be low then yes, you will have to set them low. In turns of power consumption, the processor itself consumes the same amount of power either way. Obviously, if there is something connect to a high pin that sinks, that something will consume power.

In addition, do not leave any pins floating. They will eat way any power savings you gain from putting the processor to sleep.

I thought the the sleep functions would take care of that?

No. It is a good thing that sleep does not work that way or it would be almost useless. How else would the processor be able to maintain the state of connected devices?

Also, my onboard power led stays illuminated whilst sleeping- is this normal?

Maybe. Which board and which LED?

Thanks Coding Badly, that pwm trick made me chucle!

Glad to be of help and I'm glad you were entertained. Not quite as attention-getting as an Allison jet engine coming up to speed but still entertaining.

Aha I thought that the the sleep function would magically take care of all of this, but it's only one pin thats sinking anything so I can just disable it before sleeping. It's a DFRduino Deumilanove and an Uno, on both boards it's the power led. This isn't a massive issue as the final build will not have a power led. Thanks for the reply, thought I was going mad, but I now know to disengage anything before enable sleep modes!!

[quote author=Coding Badly link=topic=76984.msg581684#msg581684 date=1319753990] In addition, do not leave any pins floating. They will eat way any power savings you gain from putting the processor to sleep. [/quote]

I found that setting unused pins as inputs, and turning on the pullup resistors works well.

The power LEDs have no connection to the ATmega328 processor, so sleep wouldn't affect them. Nor would it affect the regulators or USB to serial chip.

The serial-to-usb chip on Arduinos also consumes a lot of power, but I presume your final board won't have that either.

No final board will be Atmega running at 8mhz, no Uart/Serial/Voltage convertor!

Do not forget to actually turn of all things that you do not need before going to sleep. E.g. the serial interface or the AD converter. If you don't these parts of the processor may stay active and still draw current.

Also as already suggested ensure that you have no floating pins.