-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmkr1310-lora-lowpower.ino
75 lines (59 loc) · 1.48 KB
/
mkr1310-lora-lowpower.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <RTCZero.h>
#include <ArduinoLowPower.h>
#include <LoRa.h>
#define RTC_MATCH_SECOND 10
RTCZero rtc;
int counter = 0;
void setup()
{
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
rtc.begin();
// detach USB so the chip is asleep
USBDevice.detach();
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
// wake up the LoRa chip
if (!LoRa.begin(868E6)) {
while (1);
}
// transmit packet
LoRa.beginPacket();
LoRa.print(counter);
LoRa.endPacket();
// put LoRa module to sleep
LoRa.end();
// put LoRa SPI pins to LOW
// otherwise the LoRa module still pulls 8mA
// even after the LoRa.end()
digitalWrite(LORA_IRQ_DUMB, LOW);
digitalWrite(LORA_BOOT0, LOW);
digitalWrite(LORA_RESET, LOW);
// also set those pins as INPUT
// they were set as OUTPUT by LoRa.begin()
// but they can be set back
// to INPUT to reduce consumption by ~0.30mA
pinMode(LORA_IRQ_DUMB, INPUT);
pinMode(LORA_BOOT0, INPUT);
pinMode(LORA_RESET, INPUT);
digitalWrite(LED_BUILTIN, LOW);
rtc.setAlarmSeconds(RTC_MATCH_SECOND);
// match only seconds. In other words
// a periodic alarm every minute,
// at second RTC_MATCH_SECOND)
rtc.enableAlarm(RTCZero::MATCH_SS);
rtc.attachInterrupt(alarmMatch);
LowPower.deepSleep();
// waking up again here
// and carrying on with the loop()
counter++;
}
void alarmMatch()
{
// this function is be called on
// device wakeup and executed
// in the interrupt context
}