Skip to content

Instantly share code, notes, and snippets.

@dwblair
Created September 15, 2020 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwblair/b69a20dcf87314348bac970db574a723 to your computer and use it in GitHub Desktop.
Save dwblair/b69a20dcf87314348bac970db574a723 to your computer and use it in GitHub Desktop.
using moteino example + rfm95 sleep() to see how low we can get feather m0 lora to sleep ...
#include <RTCZero.h>
#include <SPI.h>
#include <RH_RF95.h>
// for feather m0
#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 3
RTCZero zerortc;
// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 915.0
// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);
// Set how often alarm goes off here
const byte alarmSeconds = 3;
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()
{
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
Serial.begin(115200);
delay(1000); // Wait for console
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
// manual reset
digitalWrite(RFM95_RST, LOW);
delay(10);
digitalWrite(RFM95_RST, HIGH);
delay(10);
while (!rf95.init()) {
Serial.println("LoRa radio init failed");
Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
while (1);
}
Serial.println("LoRa radio init OK!");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
if (!rf95.setFrequency(RF95_FREQ)) {
Serial.println("setFrequency failed");
while (1);
}
Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
// The default transmitter power is 13dBm, using PA_BOOST.
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
// you can set transmitter powers from 5 to 23 dBm:
rf95.setTxPower(23, false);
// put radio to sleep
rf95.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.");
digitalWrite(LED_BUILTIN, LOW);
zerortc.standbyMode(); // Sleep until next alarm match
}
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);
}
@dwblair
Copy link
Author

dwblair commented Sep 15, 2020

Was able to get .09 mA, without any additional sensors ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment