@ 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.
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.
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.
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)...
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
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.
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.
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:
Pulling to high gives maximum possible resistance to unwanted switching because the threshold for low is usually <1V.
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.
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.
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 ??