Go Down

Topic: UNO Power down (Read 4307 times) previous topic - next topic

HexadecTom

May 08, 2011, 01:33 am Last Edit: May 08, 2011, 01:37 am by HexadecTom Reason: 1
Is there a way to power down or sleep mode the uno ? I'd like to write different Sketches with the board plugged in without it continually running another program. I know this may sound silly but it's just a personal preference. I've looked over the forum for about an hour now and the only thing I come up with is >running an empty Sketch< which I tried but it doesn't work. Unless empty Sketch means a Sketch with some type of end command, then can someone point me to that end command Sketch ? Thanks

PS I'm sure the answer is either in my book or on the site somewhere but if someone can point me to it I promise I'll research much more before posting in the future.


Actually I'm pretty pleased, I'm new to Arduino but I've been goofing around with MC's for about three years now. I purchased the UNO about 9 months ago but ran into a brick wall getting it to work with XP. I recently purchased a new notebook with Windows 7 and decided to give it another try and this time it was a piece of cake so I'm looking forward to tons of fun.

Jack Christensen

#1
May 08, 2011, 02:06 am Last Edit: May 08, 2011, 02:09 am by Jack Christensen Reason: 1
That's not at all silly and yes these things are tons of fun! The ATmega328P is pretty serious about power management. There are six sleep modes, plus many of the built-in peripherals (an oxymoron, but that's what Atmel calls them! ... e.g. the ADC or comparator, watchdog timer, etc.) can be turned off.

The Arduino IDE is built on WinAVR. By using #include <avr/sleep.h> in a sketch, functions like sleep_enable() and sleep_cpu() will be available. You may need to manipulate some of the ATmega328's registers directly, depending on what you want to achieve, but that is simple and straightforward as they have standard names that are basically manipulated like variables from the C code.

See also the AVR-Libc manual and the Atmel datasheet. Another thing to consider, slowing the clock down will reduce power consumption, e.g. use 1MHz instead of 16MHz, assuming of course this is compatible with the application.
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

CrossRoads

The 'end command' can be a simple thing:
x = 0
while (x==0)
{//do nothing}

and since nothing will change x to 1, the while loop will just spin away.
Or you could have it go into powerdown sleep mode, and not wake up until reset occurs with the start of a new download.

put this at top of sketch
#include <avr/sleep.h>      // powerdown library

use this to go to sleep
Code: [Select]


set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // setting up for sleep ...

sleep_enable();                       // setting up for sleep ...

ADCSRA &= ~(1 << ADEN);    // Disable ADC

PRR = 0xFF;   // Power down functions

sleep_mode();                         // now go to Sleep and waits
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

James C4S

Keep in mind whether the microprocessor is running a complex set of instructions or just running in a loop, it draws the same amount of power.  Also, the on board regulators probably waste more power than a running ATmega328.

If you didn't want to include the sleep functions, you could just wire the reset pin to gnd when you aren't doing anything.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

HexadecTom

#4
May 08, 2011, 04:30 am Last Edit: May 08, 2011, 04:34 am by HexadecTom Reason: 1
Huh, tried all of the code in many different configs since it failed to compile on first try,............nothing, I must be doing something wrong.

This is the code I used:

Code: [Select]

#include <avr/sleep.h>      // powerdown library


set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // setting up for sleep ...

sleep_enable();                       // setting up for sleep ...

ADCSRA &= ~(1 << ADEN);    // Disable ADC

PRR = 0xFF;   // Power down functions

sleep_mode();                         // now go to Sleep and waits


Blink and other library code all work, what am I doing wrong.


Thanks for the help, much appreciated.

CrossRoads

Did you run it just like that? Or did you build it into a proper sketch?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Jack Christensen

The code below compiles fine for me (didn't try to run it). James makes a very good point about other stuff on the Uno board consuming as much power as the AVR. Probably the best application of power management will be in conjunction with purpose-built hardware. Being a general prototyping platform, absolute minimum power consumption certainly wasn't a design requirement for the Uno (nor should it be).

Code: [Select]
#include <avr/sleep.h>      // powerdown library

void setup() {
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // setting up for sleep ...
    sleep_enable();                       // setting up for sleep ...
    ADCSRA &= ~(1 << ADEN);    // Disable ADC
    PRR = 0xFF;   // Power down functions
    sleep_mode();                         // now go to Sleep and waits/*
}

void loop() {
}
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

CrossRoads

Minimal power consumption wasn't the goal tho; the goal stated goal was to have the arduino not run a program while sketches were being written:

"I'd like to write different Sketches with the board plugged in without it continually running another program."

So if its in powerdown sleep mode, its not really running another program in my mind.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

HexadecTom

Ran it like that.

Sorry, three things are going on................

1) I'm used to a language that uses this command :                End                      to get to low power or or sleep mode

2) I'm being lazy and looking for a quick fix to my problem without doing my homework and using you guys to get the answer but in my defense I'm just looking for a power down command.

3) I'm looking for a power down code that will compile and power down the uno not one that will execute a Sketch program, then power down the uno.

Thanks again.

HexadecTom


The code below compiles fine for me (didn't try to run it). James makes a very good point about other stuff on the Uno board consuming as much power as the AVR. Probably the best application of power management will be in conjunction with purpose-built hardware. Being a general prototyping platform, absolute minimum power consumption certainly wasn't a design requirement for the Uno (nor should it be).

Code: [Select]
#include <avr/sleep.h>      // powerdown library

void setup() {
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // setting up for sleep ...
    sleep_enable();                       // setting up for sleep ...
    ADCSRA &= ~(1 << ADEN);    // Disable ADC
    PRR = 0xFF;   // Power down functions
    sleep_mode();                         // now go to Sleep and waits/*
}

void loop() {
}



Thanks so much Jack, that one worked, that's exactly what I was looking for. Thanks everyone for all of your help, I am a happy camper now. Now the learning begins. Wish me luck.

HexadecTom

This is great...............I went from banging my head against the wall a few months ago to actually completing a few tasks with my UNO  XD.

Thanks a bunch again guys, I can now move forward. should be some good fun.

Jack Christensen


Minimal power consumption wasn't the goal tho; the goal stated goal was to have the arduino not run a program while sketches were being written:

"I'd like to write different Sketches with the board plugged in without it continually running another program."


I see what you mean, guess I saw "sleep mode" and jumped to "AVR sleep mode". So maybe I'm fuzzy on the goal. If we just want to stop the sketch, a toggle switch from the reset pin to ground will do that, if flipping a switch is acceptable. But then that's not power down.

Been at this too long, g'night all. Always fun. Have a good time Tom and be sure to show off what you come up with!
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

HexadecTom




Been at this too long, g'night all. Always fun. Have a good time Tom and be sure to show off what you come up with!


Will do, for sure.

I'm in heavy duty towing. Ive developed several lighting brains over the years. I keep it light hearted, just goofing around, if I do that I can get pretty elaborate............serial monitors, remote controls, servo directional selection, directly and remotely operated, it's good fun. My first completed incandescent system got built 17 years ago with 555's and relays, since then I've just proto-ed brains that I can run on LED test platforms.

Nick Gammon

I had an example sleep sketch here:

http://arduino.cc/forum/index.php/topic,60334

A minimal Atmega328 processor (no LEDs, no voltage regulator, no USB chip) used 17 mA while "doing something" (looping) and only 0.131 mA while in power-down mode. If you change the clock speed to 8 MHz the power-up state drops to 13.8 mA, whilst the sleep mode is the same.

If you powered it off a 1200 mA/H battery, by my calculations it could run for 381 days in sleep mode. So if you only want it to occasionally "do something" (like a TV remote, most of its time is spent not having buttons pushed) then it could last over a year on a set of batteries. If that was your design goal.

In my test I didn't try to aggressively turn off the "peripherals", I presume if I had the sleep mode consumption could be somewhat lower. Although an eighth of a milliamp sounds pretty good.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics


I had an example sleep sketch here:

http://arduino.cc/forum/index.php/topic,60334

A minimal Atmega328 processor (no LEDs, no voltage regulator, no USB chip) used 17 mA while "doing something" (looping) and only 0.131 mA while in power-down mode. If you change the clock speed to 8 MHz the power-up state drops to 13.8 mA, whilst the sleep mode is the same.

If you powered it off a 1200 mA/H battery, by my calculations it could run for 381 days in sleep mode. So if you only want it to occasionally "do something" (like a TV remote, most of its time is spent not having buttons pushed) then it could last over a year on a set of batteries. If that was your design goal.

In my test I didn't try to aggressively turn off the "peripherals", I presume if I had the sleep mode consumption could be somewhat lower. Although an eighth of a milliamp sounds pretty good.


Sorry to raise this thread from the dead, but low powered ATmega is an important topic and this thread returns with a Google search.  Using Teensy 2.0 (Arduino compatible), it's quite easy to go as low as 0.06mA.  That same 1200mA/H battery now lasts 2 and a quarter years.

Alone, that's not really that special, as it's not doing anything.  However, you can use the watchdog timer to wake back up or the external pin interrupts to wake when a button is pressed.  When designing ultra-low powered circuits, I use the Teensy 2.0 as it can run in ultra-low power mode, it's cheap ($16), easy compile switches to run at as low as 1MHz,  and, well, it's teensy so it will fit anywhere.  It could be made into a watch, it's really that small.

When doing ultra-low powered circuits, your friend is the multi-meter.  And with it you can squeeze quite a bit out of the ATmega with creative ideas.  For example, replace delay() with a sleep() function that powers down the ATmega to 0.06mA.  Even if it's for 15ms, it adds up.  Also, you can power down external devices/sensors when not in use.  An example is a circuit/sketch I built that uses an Ultrasonic sensor, two buzzers, two LEDs, a 3 way switch, pot, and button.  It also reads the battery voltage.  It polls the ultrasonic sensor every 90-180ms, monitors all other inputs, yet only uses 1.48mA average.  With a 2000mA/H AA battery pack, it runs for over 50 days between charges.  As it only draws 1.48mA, adding a solar cell easily makes it run forever, even with interior lighting.

In any case.  The ATmega is a fine microcontroller for ultra-low powered systems (when using a Teensy 2.0, not an Arduino Uno).  With a bit of creativity and a modest solar cell, you can seriously create systems that virtually run forever without additional power.

Tim
Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

Go Up