Eating Batteries

  1. @ Coding Badly, is there a typo in your original post, re: 28ma vs. 25ma? I reckon that as a 10-12% difference

No typo. I've measured the current using a few applications and the difference seems to be fairly consistent.

Bear in mind I'm using a multimeter to measure the current and, when the inputs are floating, the current can fluctuate wildly so it's a little difficult to get a accurate number. In other words, your milage may vary.

, or 6-7 minutes per hour of battery life.

How do you get that?

would it be better for minimal power consumption to set the internal pull-ups or set all unused pins to output

When I have time and if I can remember, I'll do some testing.

  • Brian

or 6-7 minutes per hour of battery life.

How do you get that?

10-12% of 60 minutes

If you're using a multimeter, I can do that here too. I'll race you... :wink:

10-12% of 60 minutes

Dang! I must be sleep-reading. :-[ Somehow I missed the "per hour" part of your message. Sorry about that.

I'll race you...

You'll definately win! Our new puppy arrived yesterday. Last night she kept us up all night and, from the look in her eyes, she is planning to do the same tonight. :cry:

  • Brian

In my case, by enabling the internal pullup resistors, my project went from consuming about 28ma to consuming a steady 25ma.

I assume this is on a 14-pin Duemilanove? Can you imagine what it would be on a Mega? :slight_smile:

Did you set just the digital pins, or the analog pins as well?

Did you compare setting to OUTPUT and LOW vs HIGH?

I myself have not gotten around to answering that question with my multimeter. I may not get to it right away either. In any case, we should have a number of independent measurements to compare to. I'll keep the thread posted with my results when I get to it.

Currently, I have a Teensy w/ Pins and a Teensy++ w/ Pins for testing...

http://www.pjrc.com/teensy/

The Teensy(++) has an onboard LED at pin 6 which is always turned off. For testing, neither Teensy was connected to anything except the USB port on a laptop.

The code used (which has some Teensy specific things in it)...

#define TEST_NOTHING    0
#define TEST_INPUT      1
#define TEST_PULLUP     2
#define TEST_OUTPUT     3

#define WHICH_TEST      TEST_OUTPUT

#define EXTRA_PINS      3

void setup( void )
{
  #if WHICH_TEST != TEST_NOTHING

    #if WHICH_TEST == TEST_INPUT
      const uint8_t pm = INPUT;
    #elif WHICH_TEST == TEST_PULLUP
      const uint8_t pm = INPUT_PULLUP;
    #elif WHICH_TEST == TEST_OUTPUT
      const uint8_t pm = OUTPUT;
    #endif

    #if defined(__AVR_AT90USB162__)
      const uint8_t dp1 = 0;
      const uint8_t dpN = 20;
    #elif defined(__AVR_AT90USB646__)
      const uint8_t dp1 = 0;
      const uint8_t dpN = 45;
    #else
      #error Put code here!
    #endif


    #if defined(__AVR_AT90USB162__) || defined(__AVR_AT90USB646__)
  
      uint8_t i;
    
      for ( i=dp1; i <= dpN; ++i )
      {
        if ( i != 6 )
        {
          pinMode( i, pm );
        }
        else
        {
          pinMode( 6, OUTPUT );
          digitalWrite( 6, HIGH );
        }
      }

      #if WHICH_TEST == TEST_OUTPUT
        #if EXTRA_PINS >= 1
          digitalWrite( 7, HIGH );
        #endif
        #if EXTRA_PINS >= 2
          digitalWrite( 5, HIGH );
        #endif
        #if EXTRA_PINS >= 3
          digitalWrite( 4, HIGH );
        #endif
      #endif

    #else
  
      #error Put code here!

    #endif

  #endif
}

void loop( void )
{
}

WHICH_TEST can be set to...

  • TEST_NOTHING - don't touch the pins
  • TEST_INPUT - set all digital pins except pin 6 to INPUT
  • TEST_PULLUP - set all digital pins except pin 6 to INPUT with the internal pull-up resistor enabled
  • TEST_OUTPUT - set all digital pins to OUTPUT driven LOW; pin 6 is driven HIGH to turn off the onboard LED

EXTRA_PINS can be set to zero, 1, 2, or 3. This is the number of pins beyond pin 6 that are driven HIGH.

Results...

  • There doesn't seem to be any difference between configuring the pins as INPUT w/ PULLUP vs OUTPUT set LOW. The current was consistently stable at 20.02 mA on the Teensy and 40.5 mA on the Teensy++.
  • Floating inputs are bad news. The highest current consumed by the Teensy was 27.72 mA (28.5% higher than pins set to INPUT w/ PULLUP). The highest current consumed by the Teensy++ was 47.9 mA (18.3% increase).
  • If the LED on pin (6) is configured as an INPUT w/ PULLUP an extra 200 uA is consumed (20.04 mA vs 20.24 mA)
  • Unconnected OUTPUTs seem to consume the same (low) power regardless of their state

The conclusion for these two boards is the same. To reduce power consumption...

  • Unused pins should be set to INPUT w/ PULLUP or OUTPUT
  • Pin(s) connected to an onboard LED should be set to OUTPUT with the LED turned off

Good luck,
Brian

Was it ever established if enabling pullups in INPUT is better or worse or the same as setting unused pins to OUTPUT?

while a newbee to Arduino i have a little experience. It is generally good practice to define all pins not used as outputs set low. this will not cause any power consumption and after the intial writing of the registers, should not use any additional processor time. the problem with floating inputs is that the comparitors are still running as input buffers and using some ampunt of power, just in case you want to read the pin.

Lepton_man,
That makes sense. Thanks!

Just read this thread, very interesting, but I have a question
" by enabling the internal pullup resistors"
how is this done?
Thanks in advance from a new person.

There is a good write-up on this topic at http://arduino.cc/en/Tutorial/DigitalPins.

The basic code is

pinMode(pin, INPUT);       // set pin to input
digitalWrite(pin, HIGH);       // turn on pullup resistors

The effect is well known in electrical engineering / digital circuit design. The well known book of Horowitz and Hill (The art of electronics) has a section called "Some comments about logic inputs" (must be 9.06 or 9.07). They highly recommend to default unused logic inputs to high and give a very good explanation why this is a good idea. And they explain why this will use up less power.

Basically the reasoning is as follows:

  1. Pulling to high gives maximum possible resistance to unwanted switching because the threshold for low is usually <1V.

  2. Switching consumes much more power than not switching.

So if you leave a pin floating it will cause internal switching thus consuming unnecessary power. Sometimes it will cause even worse effects.

Cheers, Udo

Very interesting. I must have a look at this myself. I have a project that only uses 3 digital inputs that leap about somewhat fast, but no outputs, and I left the unused ones floating :-[

I'll try to check this out tomorrow (if the boss lets me) and report back.

Not had time to do exhaustive checks but initial testing suggests you can get the same results by physically tying unused inputs to +VE. This I actually prefer, as it is safer if there's any nasty ESD around.

I opened up a request here http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1251090339/0#0 for an improvement in the wiring libraries. In my opinion it would be very good if the libraries would default input pins to enable the pullups.

Cheers, Udo

Umm, correct me if I'm wrong, but wouldn't switching them to input default be a bad thing...

My understanding of default OUTPUT is that it essentailly makes unused pins "inhert" - signal changes etc are irrelevant, any spurious voltages that may be picked up are ignored, and everything works as one would expect.

But with a default INPUT, wouldn't that cause issues with potentially having the Arduino act upon those signals - even if only to measure them ?? This could cause all sorts of whacky things in a sketch on pins you aren't even using ?? What happens if its an Interrupt pin ??

I always thought the default-output, thus 'ignoring' a pin unless you write to it, was the most logical default ??

I do not suggest to default them to input. I suggest to default inputs to enable pullups. Sorry If this was not clear enough.

Chears, Udo

Adr1an, Arduino pins already default to input. See http://arduino.cc/en/Tutorial/DigitalPins.

Indeed you are right and I was mistaken -- sorry !

Could have sworn they defaulted to output...