| 
 | 1 | +/*  | 
 | 2 | +  Powering off a ublox GNSS module  | 
 | 3 | +  By: bjorn  | 
 | 4 | +  unsurv.org  | 
 | 5 | +  Date: July 20th, 2020  | 
 | 6 | +  License: MIT. See license file for more information.  | 
 | 7 | +
  | 
 | 8 | +  This example shows you how to turn off the ublox module to lower the power consumption.  | 
 | 9 | +  There are two functions: one just specifies a duration in milliseconds the other also specifies a pin on the GNSS device to wake it up with.  | 
 | 10 | +  By driving a voltage from LOW to HIGH or HIGH to LOW on the chosen module pin you wake the device back up.  | 
 | 11 | +  Note: Doing so on the INT0 pin when using the regular powerOff(durationInMs) function will wake the device anyway. (tested on SAM-M8Q)  | 
 | 12 | +  Note: While powered off, you should not query the device for data or it might wake up. This can be used to wake the device but is not recommended.  | 
 | 13 | +        Works best when also putting your microcontroller to sleep.  | 
 | 14 | +
  | 
 | 15 | +  Feel like supporting open source hardware?  | 
 | 16 | +  Buy a board from SparkFun!  | 
 | 17 | +  SparkFun GPS-RTK2 - ZED-F9P (GPS-15136)    https://www.sparkfun.com/products/15136  | 
 | 18 | +  SparkFun GPS-RTK-SMA - ZED-F9P (GPS-16481) https://www.sparkfun.com/products/16481  | 
 | 19 | +  SparkFun ZED-F9K Breakout (GPS-18719)      https://www.sparkfun.com/products/18719  | 
 | 20 | +  SparkFun ZED-F9R Breakout (GPS-16344)      https://www.sparkfun.com/products/16344  | 
 | 21 | +
  | 
 | 22 | +  Hardware Connections:  | 
 | 23 | +  Plug a Qwiic cable into the GNSS and a BlackBoard.  | 
 | 24 | +  To force the device to wake up you need to connect to a pin (for example INT0) seperately on the module.  | 
 | 25 | +  If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)  | 
 | 26 | +  Open the serial monitor at 115200 baud to see the output  | 
 | 27 | +*/  | 
 | 28 | + | 
 | 29 | +#include <SparkFun_u-blox_GNSS_v3.h> //http://librarymanager/All#SparkFun_u-blox_GNSS_v3  | 
 | 30 | +SFE_UBLOX_GNSS myGNSS;  | 
 | 31 | + | 
 | 32 | +// define a digital pin capable of driving HIGH and LOW  | 
 | 33 | +#define WAKEUP_PIN 5  | 
 | 34 | + | 
 | 35 | +// Possible GNSS interrupt pins for powerOffWithInterrupt are:  | 
 | 36 | +// VAL_RXM_PMREQ_WAKEUPSOURCE_UARTRX  = uartrx  | 
 | 37 | +// VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0 = extint0 (default)  | 
 | 38 | +// VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT1 = extint1  | 
 | 39 | +// VAL_RXM_PMREQ_WAKEUPSOURCE_SPICS   = spics  | 
 | 40 | +// These values can be or'd (|) together to enable interrupts on multiple pins  | 
 | 41 | + | 
 | 42 | +void wakeUp() {  | 
 | 43 | + | 
 | 44 | +  Serial.print("-- waking up module via pin " + String(WAKEUP_PIN));  | 
 | 45 | +  Serial.println(" on your microcontroller --");  | 
 | 46 | + | 
 | 47 | +  digitalWrite(WAKEUP_PIN, LOW);  | 
 | 48 | +  delay(1000);  | 
 | 49 | +  digitalWrite(WAKEUP_PIN, HIGH);  | 
 | 50 | +  delay(1000);  | 
 | 51 | +  digitalWrite(WAKEUP_PIN, LOW);  | 
 | 52 | +}  | 
 | 53 | + | 
 | 54 | + | 
 | 55 | +void setup() {  | 
 | 56 | + | 
 | 57 | +  pinMode(WAKEUP_PIN, OUTPUT);  | 
 | 58 | +  digitalWrite(WAKEUP_PIN, LOW);  | 
 | 59 | + | 
 | 60 | +  Serial.begin(115200);  | 
 | 61 | +  while (!Serial); //Wait for user to open terminal  | 
 | 62 | +  Serial.println("SparkFun u-blox Example");  | 
 | 63 | + | 
 | 64 | +  Wire.begin();  | 
 | 65 | + | 
 | 66 | +  //myGNSS.enableDebugging(); // Enable debug messages  | 
 | 67 | + | 
 | 68 | +  if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port  | 
 | 69 | +  {  | 
 | 70 | +    Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));  | 
 | 71 | +    while (1);  | 
 | 72 | +  }  | 
 | 73 | + | 
 | 74 | +  // Powering off for 20s, you should see the power consumption drop.  | 
 | 75 | +  Serial.println("-- Powering off module for 20s --");  | 
 | 76 | + | 
 | 77 | +  myGNSS.powerOff(20000);  | 
 | 78 | +  //myGNSS.powerOffWithInterrupt(20000, VAL_RXM_PMREQ_WAKEUPSOURCE_EXTINT0);  | 
 | 79 | + | 
 | 80 | +  delay(10000);  | 
 | 81 | + | 
 | 82 | +  // After 10 seconds wake the device via the specified pin on your microcontroller and module.  | 
 | 83 | +  wakeUp();  | 
 | 84 | +}  | 
 | 85 | + | 
 | 86 | +void loop() {  | 
 | 87 | +  //Do nothing  | 
 | 88 | +}  | 
0 commit comments