ArduinoLoRa 休眠中断唤醒 1.4uA

提示1:锐米所有 LoRa 产品严格遵循国标标准的 LoRaWAN 协议
提示2:您可以免费复制,修改和商用本项目,请注明锐米原创
提示3:如果您有其他 LoRa 需求或建议,欢迎联系锐米 support@rimelink.com

运行效果

LoRa 模块入网后将自动休眠,Arduino Pro Mini 上电后休眠,将电流表串联在上述电路中测量值为 1.4uA。当 Arduino 响应按钮中断时闪烁 LED 电流增大,随后又进入休眠。

ArduinoLoRa 休眠中断唤醒 1.4uA 演示视频

低功耗是核心技术

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

ArduinoLoRa+ 是锐米推出的低成本快速开发 LoRa 终端方案,基于外部中断唤醒工作,它能达到行业第一的低功耗(1.4uA),最大延长电池续航能力。

下面,逐步解密 ArduinoLoRa+ 中断唤醒低功耗是如何实现的。

组件和材料

LoRa 开发板 x 1 采购链接


Arduino Pro Mini x 1 采购链接


按钮按钮 x 1 采购链接


电池盒电池盒 x 1 采购链接


南孚 7 号电池7 号电池 x 2 采购链接


鳄鱼夹鳄鱼夹 x 2 采购链接


杜邦线 x 10 采购链接

工具和软件

Arduino IDEArduino IDE 下载链接


下载烧录器下载器 采购链接


数字万用表数字万用表 采购链接


在这里插入图片描述USBasp烧录器 采购链接

技术细节

改制 Arduino Pro Mini

改制 Arduino Pro Mini
如上图所示,新购的 Arduino Pro Mini 需要卸掉 2 个器件:LDO(低压差稳压器)和电源指示灯处的 1k 电阻

关闭低电压检测

安装 USBasp 驱动程序

  • 将 USBasp 插入 PC 的 USB 端口
  • 双击打开“zadig-2.3.exe”
  • 选择“WinUSB”,点击“Install Driver”
    WinUSB
    USBasp驱动程序 下载链接

Arduino Pro Mini 连接 USBasp

Arduino Pro Mini杜邦线USBasp
GNDGND
RSTRST
VCCVCC
13绿SCK
12MISO
11MOSI
  • USBasp 的跳线 JP21(正视丝印,从左至右) 连接 1 和 2 引脚时 VCC=3.3V,用于连接 Arduino Pro Mini;连接 2 和 3 引脚时 VCC=5V,用于连接 Arduino UNO
    在这里插入图片描述
    Arduino Pro Mini 基于 ISP 下载的 6 引脚 参考链接

设置熔丝位,关闭低电压检测

  • 徽标+R键运行,输入“cmd”,回车,进入命令行终端
  • 切换到 avrdude 路径:cd C:\Program Files (x86)\Arduino\hardware\tools\avr\bin
  • 关闭低电压检测:avrdude -c usbasp -p m328p -U efuse:w:0xFF:m -C ../etc/avrdude.conf
    在这里插入图片描述

烧录 Arduino 休眠唤醒代码

按下表连接 Arduino Pro Mini 和 下载烧录器

Arduino杜邦线下载烧录器
VCC3.3
GNDGND
RXD绿TXD
TXDRXD
DTRDTR

接线图
小窍门:如果不接 DTR 也可以上传程序,点击 Upload 后按下 Arduino 的复位键。

设置 Arduino IDE

设置 Arduino IDE

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

#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();
}

硬件接线

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