Newbie, so please be kind. I'm doing this by trial and error..
I have a simple stripboard arduino powered by a single cell. I wanted to max battery life to years if possible.
The period of usage (game) is very short, the periods spent in 'sleep' are very long (and from a power usage point the important factor).
My idea was to use software solution only, so no external curcuits. A few leds connected to D2-D7), one switch (D8 with 'standard' 10k setup) and reset switch are the only external hardware. Wake up is only meant to be thru reset.
I use the rocket scream library to power off:
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
I originally asumed that pins where shut down when entering powerdown but found out that it is not the case.
So I added
My multimeter won't give me any readings (don't know if current it is to low?) so I'm flying blind on the current usage right now. (More correctly if I put my multimeter in serie to messure current the game does not seem to get enough power to boot at all). I am new to electronics so I might have missed something very basic here.
Using a single 3,7v li-ion 6800mAh 18650 cell with no voltage regulator.
The game takes a few seconds to play, you can play multiple times. If not used it shuts down after 30 sec. I am guessing it will be played very little during one year. Max once per day. So I asume 'on' time will be less then 2 minutes per day. Gameplay only lights up one LED at a time so I asumed the powerusage even in active play is limited.
I asumed the library did that as well, but since it leaves LED etc on even during powerdown I got unsecure...
Mattzzz:
I asumed the library did that as well, but since it leaves LED etc on even during powerdown I got unsecure...
(Thanks!)
Sounds to me like a possible code issue. Care to provide your code using the code tags?: [ code ] Code goes here [ / code]
The battery choice seems absolutely fine. 6800mAh, assuming 5 LEDs at 35mA each when on )+ a bit for the MCU) = 6800/(5*35) = about 38 hours of play at absolute worst case ish.
In sleep mode, the arduinos (assuming you have disabled the power LED or using a custom built arduino on a bread board type set up) is about 9 MICRO amps.
6800mA / 9e-3 mA = about 31,000 days. Assuming some battery drop...maybe 5-15,000 days if the unit is always in sleep.
Nice tutorial. But at least as far as if I should do something with used ports it leaves me somewhat in the dark.
As an example: Isn't there Always a Little Connection thru the 10k resistor that could draw current?
I first only used the last row but whatever LED was on (ie port in HIGH) it remained on so I added the lines to shut off all the LEDs. But the rest of the board seem to powerdown. The timer stopped as it should as an example.
Would put the board to sleep but the first LED was left on... Not what I expected. But I guessed this might be correct but it also opened my question if I needed to do something to the ports unused or used by the switch.
Powerdown leaves the I/O pins in the state they were in when the processor clocks are stopped. The rational is that external circuitry may rely on these pins being in a particular state during the power down period rather than in a open or otherwise undefined state.
To minimize power you want to leave them in a state that minimizes power drawn by the external circuitry, digitalWrite(D?, LOW) in this case.
The input pin should also be in a defined HIGH or LOW state. You don't mention explicitly the circuit on D8, but I gather that it is a pulldown resistor (thus holding in a defined LOW state) with a push button that pulls D8 to a high state to wake up the MCU.
Per this Atmel App Note, you should set unused IO to Input with internal pullup turned on.
Since the IO is disconnected, next to no current is dissipated internally by the pullup resistor.
I would do the same for D8 - internal pullup, with Low from a switch to Gnd to wake up.
CrossRoads:
Per this Atmel App Note, you should set unused IO to Input with internal pullup turned on.
Since the IO is disconnected, next to no current is dissipated internally by the pullup resistor.
I would do the same for D8 - internal pullup, with Low from a switch to Gnd to wake up.
For this application looking into your App note my plan was to do this as the last thing before powerdown since reset was the only thing that need to work after powerdown in my project:
DDRA = 0x00; // Set direction to input on all pins
PORTA = 0xFF; // Enable pull-ups on pins
delay(100);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
But verification gives me 'DDRA' was not declared in this scope. Did I missunderstand the command in the app note? It seemed like exactly what I needed (the easiest way to configure all ports to the best mode before powerdown)
Also, if this manipulates all ports, does TX/RX ports get restored to default state on next startup? Don't want to turn my 328 into a brick
Rx/Tx are on Port D, not Port A, so no issue there.
A '328P has B(0-5, with 6-7 for the crystal), C (0-5, with 6 for Reset, D (0-7).
PORTD is D0-D7, PORTB is D8-13, PORTC is D14-D19 (A0 to A5).
No PORTA, thus no DDRA.
You are not using the Port B & C pins, yes? Then you can just set them up in setup() and not have to mess with them when going to sleep.
for (byte x = 8; x<20; x=x+1){
pinMode (x, INPUT_PULLUP);
}