I discovered^ that floating pins can, relatively speaking, consume a significant amount of power. This is particular important for battery powered applications. In my case, by enabling the internal pullup resistors, my project went from consuming about 28ma to consuming a steady 25ma.
Brian
^ "Discovered" in the sense that it's news to me; a newbee. I searched these forums for a similar post but couldn't find one.
Pins do default to inputs, and it is generally NOT a good idea to leave digital inputs unconnected to anything; they can float "in between" the allowed digital states, which can cause excessive power consumption. Turning on the pullups is a good solution, actually...
Why not have the Arduino in the next bootloader version set all inputs to have the pull-ups enabled as default?
Probably best to not mess with the AVR default for input pins, say if interfacing with 3.3volt logic levels or other obscure interfaces the pull-ups be a problem.
@ Coding Badly, is there a typo in your original post, re: 28ma vs. 25ma? I reckon that as a 10-12% difference, or 6-7 minutes per hour of battery life.
Keeping retrolefty's caveat in mind, would it be better for minimal power consumption to use setup() to consciously set the internal pull-ups on unused pins, or set all unused pins to output? (output LOW? HIGH?)
@ 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.