Hello!
I am interested in the sleep mode of Arduino. I read a part of the Atmel datasheet: http://www.atmel.com/Images/doc2545.pdf. In section 14.2.6, they say "...floating inputs should be avoided to reduce current consumption...". How do floating pins waste current? I thought that setting the pins LOW or high impendence would reduce power consumption by external loads in sleep mode, because they can't draw current that way? They are isolated (high impendance) from the circuit! Is that actually true, and if it is, would this be ideal in a sleep mode?
I measured the least current with them as output and low, or inputs and low.
But I presume that as an input and low it is possible the device may be trying to "read" whatever the noise is on the floating pin. That might consume current.
Input and LOW means that the pin is floating. That means that it won't make a difference, according to Nick Gammon's experiments. Pulling the pins HIGH use more power!
dkl65:
Input and LOW means that the pin is floating.
Correct.
That means that it won't make a difference, according to Nick Gammon's experiments.
In my testing (typically ATtiny processors running from batteries) it makes a huge difference: milliamps versus microamps.
Pulling the pins HIGH use more power!
Wrong. If the pin is not connected to anything, how would electricity flow?
The bottom line is that enabling the internal pullup on an unconnected pin costs nothing. If my testing is correct, it saves electricity. If Nick's testing is correct, you've lost nothing.
Wrong. If the pin is not connected to anything, how would electricity flow?
I just refered to Nick Gammon's experiments. It said that setting all the pins HIGH with no load will consume more power, even if it is a pull-up.
The bottom line is that enabling the internal pullup on an unconnected pin costs nothing.
It will if I have loads attached to some pins, which I do (i.e. LEDs).
I will do my own testing on my Arduino UNO SMD Edition when I have time. I know how to measure currents now.
When you are talking about power minimization then I guess even microamps can make a difference, but I don't think it's all that added a load. However the reason a floating input can consume power even when not wired to something is that the random switching from input noise can cause input transistors to change state and this switching in itself does consume some energy.
dkl65:
I just refered to Nick Gammon's experiments. It said that setting all the pins HIGH with no load will consume more power, even if it is a pull-up.
My tests were done in the specific environment shown in the photo. In other words the pins were not connected to anything. Quite possibly having them connected via wires to something, which collects noise, could alter the results.
Oh, I did do it right before when testing; I was changing, copying and pasting stuff (organizing my code) then posted it to Arduino Forum, and messed things up by accident. XD I remember the L LED on pin 13 lighting up when I did:
PORTB = 0x2f;
Looks like your Arduino is more power efficient (or it's the multimeter's fault)! I was using my new multimeter. I realized that my new multimeter always gave higher readings than my old one. My old multimeter's current measurement mode is messed up now. The 8.26V was a partially drained Energizer non-rechargeable 9V battery. When I turned the Arduino on, the current draw for the blank sketch was about 60mA, then it dropped, and became stable at 53.9mA.
To take the voltage regulator and other stuff out of the equation, I tested again with my "bare bones" board fed straight from 5V.
empty sketch: 15.56 mA
Various pin configurations:
all pins output and low: 125 uA
all pins output and high: 323 uA
all pins input and low: 126 uA
all pins input and high: 201 uA
I think your sleep_mode() call might have not put it into brown-out disable, because of the extra function call. If you replace sleep_mode() with sleep_cpu() you get lower current:
all pins output and low: 118 uA
all pins output and high: 315 uA
all pins input and low: 118 uA
all pins input and high: 192 uA
Then with sleep_cpu () and adding in this line:
ADCSRA = 0;
You get even lower current:
all pins output and low: 0.1 uA
all pins output and high: 196 uA
all pins input and low: 0.1 uA
all pins input and high: 75 uA
However it still seems that having the pins as LOW saves more current than HIGH.
(edit) Tested with a different meter ... the lowest reading is 0.1 uA (100 nA).
This is the sketch that gives 100 nA:
#include <avr/sleep.h>
#include <avr/power.h>
void sleep(){
delay(100);
sleep_enable();
set_sleep_mode(SLEEP_MODE_PWR_DOWN); //set sleep mode
// disable ADC
ADCSRA = 0;
power_adc_disable();
power_spi_disable();
power_timer0_disable();
power_timer1_disable();
power_timer2_disable();
power_twi_disable();
byte i;
for (i = 0; i <= 13; i++)
pinMode (i, OUTPUT); // as required
for (i = 0; i <= 13; i++)
digitalWrite (i, LOW); // as required
MCUCR = _BV (BODS) | _BV (BODSE); // turn on brown-out enable select
MCUCR = _BV (BODS); // this must be done within 4 clock cycles of above
sleep_cpu();
}
void setup()
{
sleep();
}
void loop() {}
Grumpy_Mike:
Because they pick up interference in the form of oscillations which drive other FETs inside the chip. This takes power for no reason.
I think that this is the reason for the internal pull-ups saving energy. The pin state detectors are on; rapid oscillation may cause the pin state change detectors to take more energy. If I have loads attached, I can set the pins that the load is attached to LOW, so they can't steal power. Oh yeah, I used 8.26V through Vin pin, not power-in jack. I did this:
Connect 9V battery connector black wire to GND
Connect 9V battery connector red wire to multimeter red lead
Connect multimeter black lead to Vin
DC flows from battery negative (-) terminal to GND, goes through the load (Arduino), comes out of Vin, goes into multimeter negative (black) terminal, out of multimeter positive (red), and into the battery positive (+) terminal, where the electrons are re-energized by the chemical reaction, and the cycle happens again. That's a complete circuit (science).
Even better may to not turn pull-up pin 13, because I can see the L LED on pin 13 light up very dimly. I will edit my post when I get the result for pulling up pins 2-12. You can do that, too.
You can see from the figures on page 1 that the most massive saving can be made by simply using a board that doesn't have the voltage regulator, "power" LED, USB interface, and so on, on it. Around 40 to 50 mA drain with the Uno, running a blank sketch, compared to 15 mA on a "bare bones" board.
So either run purely on batteries, or use a voltage regulator with high efficiency.