LowPowerLab Forum

Hardware support => Low Power Techniques => Topic started by: RYAKEL on January 09, 2018, 09:57:02 AM

Title: LowPowerLibrary Deep Sleep Not Working? [SOLVED]
Post by: RYAKEL on January 09, 2018, 09:57:02 AM
Hello,

I'm new to Moteino, and I have a Moteino R6, RFM69CW - 433 Mhz, with flash.

I have successfully loaded the deep sleep example to the Moteino using arduino 1.8.5 (at least arduino IDE says it uploads). The problem is that the LED does not flash every 8 seconds as it should, and I'm seeing current draw at about a constant 10 or 11 mA! I've tried more than one Moteino too.

Code:
https://github.com/LowPowerLab/RFM69/blob/master/Examples/DeepSleep_usingLowPowerLibrary/DeepSleep_usingLowPowerLibrary.ino

I'm sure its something silly that I'm missing. I'm going to poke around with some other examples - but I'm struggling to crack it so far.

Thanks!
Title: Re: LowPowerLibrary Deep Sleep Not Working?
Post by: RYAKEL on January 09, 2018, 10:18:39 AM
Just wanted to update this...I tried a generic lowpowerlibrary example...

Code: [Select]
// **** INCLUDES *****
#include "LowPower.h"

void setup()
{
    // No setup is required for this library
}

void loop()
{
    // Enter power down state for 8 s with ADC and BOD module disabled
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); 
    delay(4000);
    // Do something here
    // Example: Read sensor, data logging, data transmission.
}

With this simple example the Moteino fluctuates between 1.3 mA for 8 seconds (sleep), and about 8 mA for 4 seconds (awake during delay). I assume this simple sketch does not turn off radio or flash, and possibly does not set the unused pins to outputs as I believe we need to do?

Thanks!
Title: Re: LowPowerLibrary Deep Sleep Not Working?
Post by: RYAKEL on January 09, 2018, 11:10:17 AM
Hi All,

I think I solved my own problem - the solution is probably obvious to the experts but figured I might as well post the solution if it helps other noobs. The problem was that I had not defined the a couple properties of the radio, and did not initialize it prior to sleeping in the setup. The following is identical to the code at Felix's github from my first post, except I added the following:

      #define NETWORKID 100
      #define NODEID 123
      #define FREQUENCY RF69_915MHZ

And in setup:
  radio.initialize(FREQUENCY,NODEID,NETWORKID);



Code: [Select]
//***********************************************************************************************************
// Sample sketch that achieves the lowest power on a Moteino of ~6.5uA
// Everything is put to sleep including the MCU, the radio (if any) and the FlashMem chip
//**** SETTINGS *********************************************************************************************
#define WITH_RFM69              //comment this line out if you don't have a RFM69 on your Moteino
#define WITH_SPIFLASH           //comment this line out if you don't have the FLASH-MEM chip on your Moteino
//***********************************************************************************************************

#include <LowPower.h> //get library from: https://github.com/lowpowerlab/lowpower
                      //writeup here: http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/

#ifdef __AVR_ATmega1284P__
  #define LED           15 // Moteino MEGAs have LEDs on D15
  #define FLASH_SS      23 // and FLASH SS on D23
#else
  #define LED           9 // Moteinos have LEDs on D9
  #define FLASH_SS      8 // and FLASH SS on D8
#endif

#if defined(WITH_RFM69) || defined(WITH_SPIFLASH)
  #include <SPI.h>                //comes with Arduino IDE (www.arduino.cc)
  #if defined(WITH_RFM69)
    #include <RFM69.h>            //get it here: https://www.github.com/lowpowerlab/rfm69
    RFM69 radio;
      #define NETWORKID 100
      #define NODEID 123
      #define FREQUENCY RF69_915MHZ
  #endif
  #if defined(WITH_SPIFLASH)
    #include <SPIFlash.h>         //get it here: https://www.github.com/lowpowerlab/spiflash
    SPIFlash flash(FLASH_SS, 0xEF30); //EF30 for 4mbit  Windbond chip (W25X40CL)
  #endif
#endif

void setup () {
#ifdef WITH_RFM69
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  radio.sleep();
#endif

#ifdef WITH_SPIFLASH
  if (flash.initialize())
    flash.sleep();
#endif

  for (uint8_t i=0; i<=A5; i++)
  {
#ifdef WITH_RFM69
    if (i == RF69_SPI_CS) continue;
#endif
#ifdef WITH_SPIFLASH
    if (i == FLASH_SS) continue;
#endif
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }
}

void loop ()
{
  //optional blink to know radio/flash sleeping went OK
  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
  delay(5000);
  digitalWrite(LED, LOW);

  //sleep MCU for 8seconds
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}

I guess one needs to initialize the radio prior to sleep is the moral of the story? Maybe the radio properties were intentionally left open because there are different radios? Experts feel free to correct further, but now I'm getting sleep for 8 sec @ 6.5 uA, and wake for 5 seconds (long enough to measure current) at around 8 mA as expected.

Thanks to those who are supporting the Moteino, looking forward to using this uC in other projects!
Title: Re: LowPowerLibrary Deep Sleep Not Working?
Post by: TomWS on January 09, 2018, 11:18:00 AM
...now I'm getting sleep for 8 sec @ 6.5 uA, and wake for 5 seconds (long enough to measure current) at around 8 mA as expected.

Thanks to those who are supporting the Moteino, looking forward to using this uC in other projects!
I'm changing the original post subject line to state [SOLVED], but if you want a more accurate measure of your sleep currents while using WDT wakeup method, it would probably be useful to run enough sleep/wake cycles BEFORE doing your 5 second current measure.  This way your measure will include the brief, but significant measure of current overhead in waking and going back to sleep.

Tom