arduino / arduino/ArduinoCore-megaavr
Sleeping does not decrease current draw
- Dominant language
- C++
- Stars
- 111
- Forks
- 65
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to get my Arduino Nano Every to go into a low-power / deep sleep mode. Even while sleeping, the board still draws ~20mA. I'm trying to get the consumption to (hopefully) <5mA if not less.
I've tried using the Adafruit_SleepyDog library, but MegaAVR seems to be incompatible with that library.
Here's the code I've tried, which does sleep but actually increases the mA draw and still stays at >20mA:
(I found most of this code from a forum post, and added a CPU prescaler in an attempt to decrease power draw)
```
#include
uint8_t loopCount = 0 ;
void RTC_init(void)
{
while (RTC.STATUS > 0) ; /* Wait for all register to be synchronized */
RTC.CLKSEL = RTC_CLKSEL_INT1K_gc; // Run low power oscillator (OSCULP32K) at 1024Hz for long term sleep
RTC.PITINTCTRL = RTC_PI_bm; // PIT Interrupt: enabled */
RTC.PITCTRLA = RTC_PERIOD_CYC8192_gc | RTC_PITEN_bm; // Set period 8 seconds (see data sheet) and enable PIC
}
ISR(RTC_PIT_vect)
{
RTC.PITINTFLAGS = RTC_PI_bm; // Clear interrupt flag by writing '1' (required)
}
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
CPU_CCP = CCP_IOREG_gc; // write access for four CPU instructions
CLKCTRL_MCLKCTRLB = CLKCTRL_PDIV_16X_gc | CLKCTRL_PEN_bm; // prescaler 16, enable prescaler
RTC_init();
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set sleep mode to POWER DOWN mode
sleep_enable(); // Enable sleep mode, but not going to sleep yet
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(200 / 16); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(200 / 16); // wait for a second
if( ++ loopCount == 5 ) {
loopCount = 0 ;
sleep_cpu(); // Sleep the device and wait for an interrupt to continue
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the supplied sketch on an Arduino Nano Every and inspect the AVR sleep entry points, RTC_init(), and ISR(RTC_PIT_vect). Compare the observed current draw with the intended sleep behavior and the reported Adafruit_SleepyDog incompatibility. Done means identifying whether the core or the sketch causes the excess draw and documenting or fixing the confirmed cause.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100