#include <avr/sleep.h>
#include <avr/wdt.h>
const byte LED = 9;
void flash ()
{
pinMode (LED, OUTPUT);
for (byte i = 0; i < 10; i++)
{
digitalWrite (LED, HIGH);
delay (50);
digitalWrite (LED, LOW);
delay (50);
}
pinMode (LED, INPUT);
} // end of flash
// watchdog interrupt
ISR (WDT_vect)
{
wdt_disable(); // disable watchdog
} // end of WDT_vect
void setup () { }
void loop ()
{
flash ();
// disable ADC
ADCSRA = 0;
// clear various "reset" flags
MCUSR = 0;
// allow changes, disable reset
WDTCSR = _BV (WDCE) | _BV (WDE);
// set interrupt mode and an interval
WDTCSR = _BV (WDIE) | _BV (WDP3) | _BV (WDP0); // set WDIE, and 8 seconds delay
wdt_reset(); // pat the dog
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
sleep_enable();
// turn off brown-out enable in software
MCUCR = _BV (BODS) | _BV (BODSE); // <-- error was on this line ------
MCUCR = _BV (BODS);
sleep_cpu ();
// cancel sleep as a precaution
sleep_disable();
} // end of loop
When I compile I get error “BODS” was not declared in this scope about 8 lines from the bottom.
I suspect it is a problem of not finding a library file, but does the IDE not give an indication on one of the #include <avr/sleep.h> #include <avr/wdt.h>
lines.
I am lacking a bit when it come to library usage.
Thanks, Jack
Hi Jack, I have the board set to the leonardo, but did not have it plugged into the usb. I just hit compile, not upload.
Maybe you have those libraries, and I don’t ? If you did not have a library on your computer, what/when would it tell you ?
I just tried
#include <avr/wdtJWP.h>
at the top of the example blink sketch, and it compiled, with no errors. So, I guess it does not care if the included library is missing (no error, no warning). Looks like I need to learn how to download these libraries.
BTW, did you put a amp meter on there, and get any results?
Ha Larry,
I tried #include <avr/wdt.h> first, and got the error.
Then I tried #include <avr/wdtJWP.h> just to see if it would tell me that the library was not found (and it didn’t). I still got the same error lower in the code tho.
Further.
From the Arduino CookBook page 627:
A standard Arduino board would run down a 9-volt alkaline battery in a few weeks (the Duemilanove typically draws more than 25 milliamperes [mA], excluding any external devices that may be connected). You can reduce this consumption by half if you use a board that does not have a built-in USB interface chip, such as the Arduino Mini, LilyPad, Fio, or one of the Modern Device Bare Bones Boards that require the use of an external USB interface for uploading sketches. Significantly greater power savings can be achieved if your application can suspend operation for a period of time—Arduino hardware can be put to sleep for a preset period of time or until a pin changes state, and this reduces the power consumption of the chip to less than one one-hundredth of 1 percent (from around 15 mA to around 0.001 mA) during sleep.
The library used in this recipe provides easy access to the hardware sleep function. The sleep time can range from 16 to 8,000 milliseconds (eight seconds). To sleep for longer periods, you can repeat the delay intervals until you get the period you want:
Sleep mode can reduce the power consumption of the controller chip, but if you are looking to run for as long as possible on a battery, you should minimize current drain through external components such as inefficient voltage regulators, pull-up or pull-down resistors, LEDs, and other components that draw current when the chip is in sleep mode.
jackwp:
Mission accomplished, (but still don't know why I had to remark the lines using BODS).
The Leonardo's 32U4 MCU does not have the capability for software to disable the BOD, so it has no BODS/BODSE bits in the control register. Nick's page was for the 328P MCU. If I choose Board > Leonardo I can duplicate the errors.