Author Topic: M0 with Radio not low power  (Read 2065 times)

MAFlyfisher

  • NewMember
  • *
  • Posts: 1
M0 with Radio not low power
« on: September 15, 2020, 06:48:14 PM »
Hi I just purchased a Moteino M0 board with flash and radio (RFM95)... I have tried the deep sleep and RTC examples on the M0 Page. Unfortunately, I am still pulling 750 uA with the board. I understand that a bare bones board can pull under 10 uA, but I can't find what is nominal for this M0 configuration. A similar Moteino system I have pulls under 10 uA with just a radio attached. I saw only one other posting concerning this where the person ws at 450 uA but eventually got down to 15 uA however, the code listing is very sparse. Can some one please advise on how to reduce power?... Thank you in advance...

Here's the code that can achieve 750 uA

Code: [Select]
#include <RTCZero.h>
#include <SPIFlash.h>
#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!

#define SS_FLASHMEM 8
 
RFM69 radio;
SPIFlash flash(SS_FLASHMEM, 0xEF30); //EF30 for 4mbit  Windbond chip (W25X40CL)
RTCZero zerortc;

// Set how often alarm goes off here
const byte alarmSeconds = 8;
const byte alarmMinutes = 0;
const byte alarmHours = 0;

volatile bool alarmFlag = false; // Start awake

#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(1000); // Wait for console
 
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

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

  if (!radio.initialize(FREQUENCY,NODEID,NETWORKID)){
    Serial.println("radio.init() FAIL");
    delay(100);
  }else{
    Serial.println("radio.init() SUCCESS");
    delay(100);
  }
  radio.sleep();

  zerortc.begin(); // Set up clocks and such
 
  resetAlarm();  // Set alarm
  zerortc.attachInterrupt(alarmMatch); // Set up a handler for the alarm

}

void loop()
{
  if (alarmFlag == true) {
    alarmFlag = false;  // Clear flag
    digitalWrite(LED_BUILTIN, HIGH);
    Serial.println("Alarm went off - I'm awake!");
  }
  resetAlarm();  // Reset alarm before returning to sleep
  Serial.println("Alarm set, going to sleep now.");
  USBDevice.detach();
  digitalWrite(LED_BUILTIN, LOW);
  zerortc.standbyMode();    // Sleep until next alarm match

 
  USBDevice.attach();
}

void alarmMatch(void)
{
  alarmFlag = true; // Set flag
}

void resetAlarm(void) {
  byte seconds = 0;
  byte minutes = 0;
  byte hours = 0;
  byte day = 1;
  byte month = 1;
  byte year = 1;
 
  zerortc.setTime(hours, minutes, seconds);
  zerortc.setDate(day, month, year);

  zerortc.setAlarmTime(alarmHours, alarmMinutes, alarmSeconds);
  zerortc.enableAlarm(zerortc.MATCH_HHMMSS);
}
« Last Edit: October 29, 2020, 05:53:42 PM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: M0 with Radio not low power
« Reply #1 on: September 16, 2020, 10:19:30 AM »
You need to be using the library for RFM95 not for RFM69, use RadioHead instead.

GavinUk123

  • NewMember
  • *
  • Posts: 4
Re: M0 with Radio not low power
« Reply #2 on: October 29, 2020, 05:31:12 PM »
Hi, I recently purchased a Moteino M0 with flash and radio (RFM95) from the Welectron store. I too have had some trouble achieving 15uA but did manage to get down to 40uA so not too far off. I thought I would list the code for others who may be struggling and for any suggestions to achieve 15uA?

Thanks

Code: [Select]
//******* Code Notes *************************************************//
//
// Moteino M0 - RFM95W (868 MHz), 4MBit Flash
// Powered by 6V battery supply into VBat pin not Vin
// Sleep Flash, Lora and M0 - Current Consumption = 40uA
// Wake up by pulling pin SLEEP_WAKEUP_PIN to ground
// M0 will wake up for 12 seconds (LED turned ON) before returning to deep sleep (LED OFF)
//
//******* Libraries **************************************************//
#include <Arduino.h>
#include <RTCZero.h>
#include <SPI.h>
#include <RadioHead.h>
#include <RH_RF95.h>
#include <Wire.h>
#include <SPIFlash.h>
#include <ArduinoLowPower.h>

//******* Definitions ************************************************//
#define RFM95_LORA_FREQUENCY 868      // Frequency of Lora module
#define RFM95_CS_PIN A2               // Chip select pin, A2 on Moteino M0 Schematic
#define RFM95_INT_PIN 9               // Interrupt pin, D9 on Moteino M0 Schematic
#define RH_RF95_REG_01_OP_MODE 0x01   // Mode register address (see RH_RF95.h)
#define RH_RF95_MODE_SLEEP 0x00       // Sleep Mode (see RH_RF95.h)

#define FLASH_CS_PIN 8                // Chip select pin, D8 on Moteino M0 Schematic
#define FLASH_JedecID 0xEF30          // JedecID is optional but recommended, get this from the datasheet of your flash chip (see SPIFlash.h)

#define SLEEP_WAKEUP_PIN 0            // Interrupt pin used to wake the Moteino from a deep sleep

//******* Global Variables *******************************************//
SPIFlash flash(FLASH_CS_PIN, FLASH_JedecID);
RH_RF95 rf95(RFM95_CS_PIN, RFM95_INT_PIN);

//******* Setup ******************************************************//
void setup()
{
  Serial.begin(9600);
  delay(500);

  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN,LOW);

  pinMode(SLEEP_WAKEUP_PIN, INPUT_PULLUP);    // Using internal pullup, makes pin 0 active low
  attachInterrupt(0, wakeUpISR, LOW);         // Attach interrupt (named "wakeUpISR") to SLEEP_WAKEUP_PIN (Interrupt 0 is attached to SLEEP_WAKEUP_PIN)
  delay(500);

  pinMode(FLASH_CS_PIN,OUTPUT);
  digitalWrite(FLASH_CS_PIN,HIGH);

  pinMode(RFM95_CS_PIN,OUTPUT);
  digitalWrite(RFM95_CS_PIN,HIGH);

  delay(2000);

  // Flash Initilisation
  if (!flash.initialize())
  {
    Serial.println("flash.init() FAIL");
  }else{   
    Serial.println("flash.init() PASS");
  }
  delay(2000);
  flash.sleep();  // Sleep Flash
  delay(1000);

  // Lora Initialisation
  if (!rf95.init())
  {
    Serial.println("rf95.init() FAIL");
  }else{
    Serial.println("rf95.init() PASS");
  }
  delay(2000);
  rf95.setFrequency(RFM95_LORA_FREQUENCY);
  writeToLoraRegisterSPI(RH_RF95_REG_01_OP_MODE,RH_RF95_MODE_SLEEP);  // Sleep Lora Module
  delay(1000);

}

//******* Main Loop **************************************************//
void loop()
{
  digitalWrite(LED_BUILTIN,LOW);
  delay(2000);
  standbySleep();
  digitalWrite(LED_BUILTIN,HIGH);
  delay(10000);
}

//******* Functions **************************************************//
void writeToLoraRegisterSPI(byte destAddress, byte commandBuf)
{
  byte regAddress = destAddress | 0x80;
  digitalWrite(RFM95_CS_PIN, LOW);
  SPI.transfer(regAddress);
  SPI.transfer(commandBuf);
  digitalWrite(RFM95_CS_PIN, HIGH);
}

void wakeUpISR()
{
 
}

void standbySleep()
{
  delay(500);
  //USBDevice.detach();                 //Disable USB (optional)
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  __DSB();
  __WFI();                              // Wait For Interrupt call
  //USBDevice.attach();                 // Enable USB
  delay(500);
}

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: M0 with Radio not low power
« Reply #3 on: October 29, 2020, 05:55:25 PM »
GavinUk123,
What sleep current does the sample sleep sketch from this page yield?

GavinUk123

  • NewMember
  • *
  • Posts: 4
Re: M0 with Radio not low power
« Reply #4 on: October 29, 2020, 06:47:59 PM »
Hi Felix, the deep sleep example code uses the RFM69 library so it doesn't shut down my RFM95 module leaving 1.68mA sleep current when unmodified. Modifying the RFM69 part of the code in this example with RFM95 code (writing direct to the RH_RF95_REG_01_OP_MODE register) gives 40uA sleep current.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: M0 with Radio not low power
« Reply #5 on: November 02, 2020, 09:07:36 AM »
How do you power the MoteinoM0?
It should be powered through the Battery JST connector for the lowest power draw.

By the way, how come you are not using the library native sleep method and are doing raw writing to registers?
« Last Edit: November 02, 2020, 09:11:20 AM by Felix »

GavinUk123

  • NewMember
  • *
  • Posts: 4
Re: M0 with Radio not low power
« Reply #6 on: November 02, 2020, 05:20:21 PM »
Hi, I power the MoteinoM0 using the Vbat pin. I wrote directly to the register to sleep the RFM95 due to a post highlighting potential problems with using the native sleep function (https://lowpowerlab.com/forum/moteino-m0/moteino-m0-versus-standard-moteino-r6-current-draw/msg27367/#msg27367). However, I have just tried using the native sleep function and it acts exactly the same as writing to the register in terms of current consumption.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: M0 with Radio not low power
« Reply #7 on: November 03, 2020, 03:37:53 PM »
Ok let's try again: It should be powered through the Battery JST connector for the lowest power draw.

GavinUk123

  • NewMember
  • *
  • Posts: 4
Re: M0 with Radio not low power
« Reply #8 on: November 05, 2020, 05:11:45 AM »
My apologies Felix. I was under the impression the Vbat pin on the M0 R2 version was directly connected to the positive terminal of the battery JST connector so powering from either JST or Vbat would act in the same manner. I will give your suggestion a try. Thanks

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: M0 with Radio not low power
« Reply #9 on: November 05, 2020, 10:03:17 AM »
The schematic is actually published here.