Hi,
I hope someone can assist with the code I have put together to lower the power utilisation for a GPS / LoRa node that I am testing.
Hardware:
Freetronics Eleven (Arduino Uno equiv)
Duinotech LoRa Shield
Neo-6m-0-001 GPS module
I utilised the following non-standard libraries:
Modified MCCI Arduino-LMIC library by Thomas Laurenson (adds Australian LoRa bands)
I had the code working utilising a timed delay (os_setTimedCallback) to control how often information was transmitted, however it was just sitting wasting power (i know the GPS is drawing a decent amount as well). But I wanted to test out the power saving functions of the processor. I initially tried the LowPower library which did not work at all and then have now tried to use the code/information from https://www.gammon.com.au/forum/?id=11497 to do it better, however the processor doesnt seem to ever go into sleep mode, it just runs through the loop.
Can anyone provide some thoughts on this?
I have attached the full code as it too large to post
void gotosleep (unsigned interval) {
Serial.println("Going to Sleep");
// keep the state of register ADCSRA
byte keep_ADCSRA;
keep_ADCSRA = ADCSRA;
// disable ADC
ADCSRA = 0;
for (int i = 0; i <= int(interval/8); i++) {
// clear various "reset" flags
MCUSR = 0;
// allow changes, disable reset
WDTCSR = bit (WDCE) | bit (WDE);
// set interrupt mode and an interval
WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0); // set WDIE, and 8 seconds delay
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
wdt_reset(); // pat the dog
Serial.print("Sleep loop: ");
Serial.println(i);
Serial.flush();
noInterrupts(); // timed sequence follows
sleep_enable();
// turn off brown-out enable in software
MCUCR = bit (BODS) | bit (BODSE);
MCUCR = bit (BODS);
interrupts(); // guarantees next instruction executed
sleep_cpu();
}
// cancel sleep as a precaution
sleep_disable();
ADCSRA = keep_ADCSRA;
Serial.println("Loop end");
}
Arduino_LMIC.ino (17.1 KB)