您现在的位置是:网站首页> 硬件

ArduinoLoRa 休眠极限 1.4uA

  • 硬件
  • 2021-09-23
  • 757人已阅读
摘要

提示1:锐米所有 LoRa 产品严格遵循国际标准的 LoRaWAN 协议。

提示2:您可以免费复制,修改和商用本项目,请注明锐米原创。

提示3:如果您有其他 LoRa 需求或建议,欢迎联系锐米 support@rimelink.com


把低功耗做到极致

超过 80% 的 LoRa 终端将由电池供电,这样一来,低功耗将是一个核心的技术挑战,一旦电能耗尽设备将“罢工”,在某些场合电能意味着 LoRa 终端的寿命。


ArduinoLoRa+ 是锐米推出的低成本快速开发 LoRa 终端方案,它能达到行业第一的低功耗(1.4uA),最大限度地延长电池续航能力。


下面,逐步解密 ArduinoLoRa+ 极限低功耗是如何实现的。

上传休眠代码


#include <avr/sleep.h>


void setup () 

{

  pinMode(LED_BUILTIN, OUTPUT);


  int  count;

  for (count = 0; count < 5; ++count)

  {

    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)

    delay(200);                       // wait for 200ms

    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW

    delay(200);                       // wait for 200ms    

  }

  

  // disable ADC

  ADCSRA = 0;  

  

  set_sleep_mode (SLEEP_MODE_PWR_DOWN);  

  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 ();              // sleep within 3 clock cycles of above


}  // end of setup


void loop () { }


LoRa 自动休眠

LoRa 开发板上电后闪烁 LED 共 5 次(表示正常工作),LoRa 模块入网后将自动休眠。将电流表串联在上述电路中,测量休眠电流为 1.4uA

1.png

唤醒技术

很明显,一个永久休眠的 ArduinoLoRa 平台是没有意义的,它需要被唤醒以从事某些工作,这可以通过“定时器”和“外部中断”来完成。请参考:

  • ArduinoLoRa 休眠中断唤醒 1.4uA
  • ArduinoLoRa 休眠定时器唤醒 5.5uA

  • 编译和烧录下述休眠中断唤醒代码

  • #include <avr/sleep.h>

  •  

  • /* 

  •  * Example code to demonstrate the sleep functions in a Arduino.

  •  *

  •  * use a pull up resistor on pin 2 to 5V.

  •  * and ground pin 2 momentary to wake it up again.

  •  *

  •  * When awake, the arduino will run the ledPin_blink code

  •  */

  •  

  • const int ledPin = 13;  // ledPin connected to digital pin 13

  • const int wakePin = 2;  // active LOW, ground this pin momentary to wake up

  •  

  • /* here we put the arduino to sleep */

  • void sleepNow()

  • {

  • /* Now is the time to set the sleep mode. In the Atmega8 datasheet

  •  * https://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35

  •  * there is a list of sleep modes which explains which clocks and

  •  * wake up sources are available in which sleep modus.

  •  *

  •  * In the avr/sleep.h file, the call names of these sleep modus are to be found:

  •  *

  •  * The 5 different modes are:

  •  *     SLEEP_MODE_IDLE         -the least power savings

  •  *     SLEEP_MODE_ADC

  •  *     SLEEP_MODE_PWR_SAVE

  •  *     SLEEP_MODE_STANDBY

  •  *     SLEEP_MODE_PWR_DOWN     -the most power savings

  •  *

  •  * For now, we want as much power savings as possible,

  •  * so we choose the according sleep modus: SLEEP_MODE_PWR_DOWN

  •  *

  • */  

  •   set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // sleep mode is set here

  •  

  •   sleep_enable();  // enables the sleep bit in the mcucr register so sleep is possible. just a safety pin

  •  

  • /* Now is time to enable a interrupt. we do it here so an

  •  * accidentally pushed interrupt button doesn't interrupt

  •  * our running program. if you want to be able to run

  •  * interrupt code besides the sleep function, place it in

  •  * setup() for example.

  •  *

  •  * In the function call attachInterrupt(A, B, C)

  •  * A   can be either 0 or 1 for interrupts on pin 2 or 3.  

  •  *

  •  * B   Name of a function you want to execute at interrupt for A.

  •  *

  •  * C   Trigger mode of the interrupt pin. can be:

  •  *             LOW        a low level triggers

  •  *             CHANGE     a change in level triggers

  •  *             RISING     a rising edge of a level triggers

  •  *             FALLING    a falling edge of a level triggers

  •  *

  •  * In all but the IDLE sleep modes only LOW can be used.

  • */

  •   attachInterrupt(0, wakeUpNow, FALLING);  // use interrupt 0 (pin 2) and run function wakeUpNow when pin 2 gets LOW

  •  

  •   sleep_mode();  // here the device is actually put to sleep!!


  •   /* THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP */

  •   sleep_disable();  // first thing after waking from sleep: disable sleep...

  •     

  •   detachInterrupt(0);  // disables interrupt 0 on pin 2 so the wakeUpNow code will not be executed during normal running time.

  • }


  • /* here the interrupt is handledPin after wakeup */

  • void wakeUpNow()

  • {

  •   // execute code here after wake-up before returning to the loop() function

  •   // timers and code using timers (serial.print and more...) will not work here.

  • }


  • void flash()

  • {

  •   pinMode(ledPin, OUTPUT);

  •   digitalWrite(ledPin, HIGH);

  •   delay(50);

  •   digitalWrite(ledPin, LOW);

  •   delay(50);

  •   pinMode(ledPin, INPUT);

  • }


  • void setup()

  • {

  •   ADCSRA = 0;  // disable ADC

  •   pinMode(wakePin, INPUT);

  •   digitalWrite (wakePin, HIGH);  // enable pull-up

  • }

  •  

  • void loop()

  • {

  •   flash();

  •   sleepNow();

  • }

  • 硬件接线

  • 如下图所示,使用杜邦线连接 LoRa 开发板和按钮,并使用电池供电。

  • 1.png

  • 添加 Narcoleptic 低功耗定时器库

  • 使用 Arduino IDE 打开工程,点击"Sketch -> Include Library -> Add .ZIP Library…"

  • Narcoleptic 软件库 下载链接


  • 编译和烧录下述休眠定时器唤醒代码

  • #include <Narcoleptic.h>


  • void setup () 

  • {  

  •   // disable ADC

  •   ADCSRA = 0;  

  • }  // end of setup


  • void loop () 

  •   flash();

  •   lowpwrDelay(4000); // During this time power consumption is minimised

  • }


  • void flash()

  • {

  •   pinMode(LED_BUILTIN, OUTPUT);

  •   

  •   for (byte count = 0; count < 10; ++count)

  •   {

  •     digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)

  •     delay(50);                       // wait for 50ms

  •     digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW

  •     delay(50);                       // wait for 50ms    

  •   }

  •   

  •   pinMode(LED_BUILTIN, INPUT);

  • }


  • void lowpwrDelay(long milliseconds)

  • {

  •   while(milliseconds > 0)

  •   {

  •     if(milliseconds > 8000)

  •     {

  •       milliseconds -= 8000;

  •       Narcoleptic.delay(8000);

  •     }

  •     else

  •     {

  •       Narcoleptic.delay(milliseconds);

  •       break;

  •     }//if

  •   }//while

  • }

  • 硬件接线

  • 如下图所示,连接 LoRa 开发板和电池即可。

  • 1.png


Top