sandeepmistry / arduino-LoRa

An Arduino library for sending and receiving data using LoRa radios.
MIT License
1.64k stars 627 forks source link

MKR1310 high consumption #311

Closed Tirititelu closed 4 years ago

Tirititelu commented 4 years ago

Hello, I am doing tests with the new mkr1310 and I am getting very bad consumption results (approx 9mA) when I use this library. On the other hand, when I use the MKRWAN I get a much lower consumption (0.5mA). After several tests I think the problem is that the sleep function does not work properly. Do you know what may be happening?.

One of the test codes (9mA):

#include <LoRa.h>
#include "ArduinoLowPower.h" 

float frequency = 868E6;
int power=17;
int spreading=7;
int coding=5;
long bandWidth=125000;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);

  if (!LoRa.begin(frequency)) {
          Serial.println("Starting LoRa failed!");
          while (1);
         }

      LoRa.setTxPower(power);
      LoRa.setSpreadingFactor(spreading);
      LoRa.setSignalBandwidth(bandWidth);
      LoRa.setCodingRate4(coding);

}

void loop() {

    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(2000);                       // wait for a second
    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
    delay(2000);

    LoRa.sleep();              
    delay(5000); 
    LowPower.deepSleep(15000); 
}

Other code (0,5mA):

  #include <MKRWAN.h>
  #include "ArduinoLowPower.h" 

  LoRaModem modem;

  void setup() {

  pinMode(LED_BUILTIN, OUTPUT);

  if (!modem.begin(EU868)) {
     Serial.println("Starting LoRa failed!");
     while (1);
    }
  }

void loop() {

    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(2000);                       // wait for a second
    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
    delay(2000);
    modem.sleep();              
    delay(5000); 
    LowPower.deepSleep(15000); 
}
facchinm commented 4 years ago

Hi @Tirititelu , the MKRWAN library communicates with the internal firmware that automatically handles low power modes (on the Murata chip). If you use arduino-LoRa, the internal firmware goes into a sort of "dumb mode" that forwards the SPI bus to the Semtech chip, without being aware of the ongoing communication. The only way to achieve a lower power consumption is to shutdown the Lora module completely and restore the context at resume (digitalWrite(LORA_RESET, LOW); after LoRa.sleep(); should be enough, but you'll need to call LoRa.begin() again at resume)