Author Topic: Moteino M0 deep sleep too high [fix: power thru JST]  (Read 1991 times)

c@cwb.no

  • NewMember
  • *
  • Posts: 3
Moteino M0 deep sleep too high [fix: power thru JST]
« on: October 13, 2020, 05:47:52 PM »
Hi!

I can not for the life of me get the Moteino M0 to use less than 403uA avg in deep sleep. The board has nothing connected, and has flash with no RF. I use the code provided in the example. I have 3.6v connected to the VIN and using an CurrentRanger and Otii Arc as measuring units. What could I be doing wrong? Code below for ref.

Thanks, Christopher.

Code: [Select]
//Standby sleep example for MoteinoM0 with external interrupt wakeup
//expected current in standby sleep: 7.5uA
const int pin = 0; //pin to use as interrupt (can be any digital pin)

//#define WITHRFM69  //comment this out if you don't have a radio installed on your MoteinoM0

#ifdef WITHRFM69
  #include <RFM69.h>    //get it here: https://www.github.com/lowpowerlab/rfm69
  #define NODEID        2   //must be unique for each node on same network (range up to 254, 255 is used for broadcast)
  #define NETWORKID     100  //the same on all nodes that talk to each other (range up to 255)
  #define GATEWAYID     1
  #define FREQUENCY     RF69_915MHZ
  #define IS_RFM69HW    //uncomment only for RFM69HW! Leave out if you have RFM69W!
  RFM69 radio;
#endif

#include <SPIFlash.h> //get it here: https://www.github.com/lowpowerlab/spiflash
SPIFlash flash(SS_FLASHMEM, 0xEF30); //EF30 for 4mbit  Windbond chip (W25X40CL)

//replace Serial with SerialUSB
#if defined (MOTEINO_M0)
  #if defined(SERIAL_PORT_USBVIRTUAL)
    #define Serial SERIAL_PORT_USBVIRTUAL // Required for Serial on Zero based boards
  #endif
#endif

void setup()
{
  Serial.begin(115200);
  delay(5000);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(0, INPUT_PULLUP); //using internal pullup, makes pin 0 active low

  //Uses internal pullup eliminates the need for external resistor and makes interupt pin active low
  //If you need active high, then attach to HIGH and declare pin as INPUT without PULLUP, then use external resistor from GND to pin to keep it from floating
  attachInterrupt(pin, wakeupISR, LOW); //note: RISING and FALLING do not seem to work, use LOW or HIGH instead

  if (flash.initialize())
  {
    Serial.println("flash.init() OK, sleeping it...");
    flash.sleep();
  }
  else Serial.println("flash.init() FAIL");

#ifdef WITHRFM69
  if (!radio.initialize(FREQUENCY,NODEID,NETWORKID))
    Serial.println("radio.init() FAIL");
  else
    Serial.println("radio.init() SUCCESS");
 
  #ifdef IS_RFM69HW
    radio.setHighPower(); //uncomment only for RFM69HW!
  #endif
    radio.sleep();
#endif

  for (byte count=0; count < 3; count++)
  {
    Serial.print(".");
    blink(500);
  }
  Serial.println("Entering standby sleep mode...");
  delay(100);
}

void loop()
{
  standbySleep();

  //interrupt happened: WAKE UP and blink the LED!
  blink(50);
}

void blink(int ms) {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(ms);
  digitalWrite(LED_BUILTIN, LOW);
  delay(ms);
}

byte toggle=true;
void wakeupISR(void)
{
  //nothing here, just a placeholder
}

void standbySleep() {
  //Disable USB (optional)
  USBDevice.detach();

  //Standby - lowest power sleep mode
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  __DSB();
  __WFI(); // Wait For Interrupt call

  //Sleep until woken by interrupt...

  //Enable USB
  USBDevice.attach();
}

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Moteino M0 deep sleep too high
« Reply #1 on: October 13, 2020, 08:22:09 PM »
Could you try it with the voltage source connected at the battery port..

c@cwb.no

  • NewMember
  • *
  • Posts: 3
Re: Moteino M0 deep sleep too high
« Reply #2 on: October 14, 2020, 04:52:32 AM »
Thanks, that did the trick! Now it sleeps at 7.10uA. Awesome! :-)