Enerlib for Arduino by E.P.G. - 11/2010
1.0.1) 2012/12/29 First revision.
1.0.0) 2010/11/03 Initial Release
1.0.1) 2012/12/29 Added compatibility with Arduino 1.0.x
Enerlib is a easy-to-use wrapper for AVR's Sleep library for Arduino. (Needs to by tested in Arduino Mega)
It makes easier the use of low power modes.
Download here: Enerlib 1.0.1
Put the Enerlib folder in "libraries\".
In the Arduino IDE, create a new sketch (or open one) and select from the menubar "Sketch->Import Library->Enerlib".
Once the library is imported, a "#include <Enerlib.h>" line will appear at the top of your Sketch.
There's an example included which demonstrates the Enerlib usage.
Creates an instance for an Energy object called energ.
For more information about power modes, look at ATMega's datasheet. ATMega328P datasheet
Puts Arduino in PowerDown mode.
Puts Arduino in Idle mode.
Puts Arduino in SleepADC mode.
Puts Arduino in PowerSave mode.
Puts Arduino in Standby mode.
Check if Arduino was sleeping. Use it in any ISR which IRQ wakes up the microcontroller to see if the ISR was called by a wake up event.
/* Enerlib: easy-to-use wrapper for AVR's Sleep library. By E.P.G. - 11/2010 - Ver. 1.0.0 Example showing how to enter in Idle mode and exit from it with INT0. */ #include <Enerlib.h> Energy energy; void INT0_ISR(void) { /* The WasSleeping function will return true if Arduino was sleeping before the IRQ. Subsequent calls to WasSleeping will return false until Arduino reenters in a low power state. The WasSleeping function should only be called in the ISR. */ if (energy.WasSleeping()) { /* Arduino was waked up by IRQ. If you shut down external peripherals before sleeping, you can reinitialize them here. Look on ATMega's datasheet for hardware limitations in the ISR when microcontroller just leave any low power state. */ } else { /* The IRQ happened in awake state. This code is for the "normal" ISR. */ } } void setup() { attachInterrupt(0, INT0_ISR, LOW); /* Pin 2 will be the "wake button". Due to uC limitations, it needs to be a level interrupt. For experienced programmers: ATMega's datasheet contains information about the rest of wake up sources. The Extended Standby is not implemented. */ energy.Idle(); } void loop() { }