|
| 1 | +/* |
| 2 | + Powering off a ublox GPS module |
| 3 | + By: bjorn |
| 4 | + unsurv.org |
| 5 | + Date: July 20th, 2020 |
| 6 | + License: MIT. See license file for more information but you can |
| 7 | + basically do whatever you want with this code. |
| 8 | +
|
| 9 | + This example shows you how to turn off the ublox module to lower the power consumption. |
| 10 | + There are two functions: one just specifies a duration in milliseconds the other also specifies a pin on the GPS device to wake it up with. |
| 11 | + By driving a voltage from LOW to HIGH or HIGH to LOW on the chosen module pin you wake the device back up. |
| 12 | + Note: Doing so on the INT0 pin when using the regular powerOff(durationInMs) function will wake the device anyway. (tested on SAM-M8Q) |
| 13 | + 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. |
| 14 | + Works best when also putting your microcontroller to sleep. |
| 15 | +
|
| 16 | + Feel like supporting open source hardware? |
| 17 | + Buy a board from SparkFun! |
| 18 | + ZED-F9P RTK2: https://www.sparkfun.com/products/15136 |
| 19 | + NEO-M8P RTK: https://www.sparkfun.com/products/15005 |
| 20 | + SAM-M8Q: https://www.sparkfun.com/products/15106 |
| 21 | +
|
| 22 | + Hardware Connections: |
| 23 | + Plug a Qwiic cable into the GPS 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_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS |
| 30 | +SFE_UBLOX_GPS myGPS; |
| 31 | + |
| 32 | +// define a digital pin capable of driving HIGH and LOW |
| 33 | +#define WAKEUP_PIN 5 |
| 34 | + |
| 35 | +// interrupt pin mapping |
| 36 | +#define GPS_RX 0 |
| 37 | +#define GPS_INT0 1 |
| 38 | +#define GPS_INT1 2 |
| 39 | +#define GPS_SPI_CS 3 |
| 40 | + |
| 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 | + |
| 59 | + Serial.begin(115200); |
| 60 | + while (!Serial); //Wait for user to open terminal |
| 61 | + Serial.println("SparkFun Ublox Example"); |
| 62 | + |
| 63 | + Wire.begin(); |
| 64 | + |
| 65 | + if (myGPS.begin() == false) //Connect to the Ublox module using Wire port |
| 66 | + { |
| 67 | + Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); |
| 68 | + while (1); |
| 69 | + } |
| 70 | + |
| 71 | + // Powering off for 20s, you should see the power consumption drop. |
| 72 | + Serial.println("-- Powering off module for 20s --"); |
| 73 | + |
| 74 | + myGPS.powerOff(20000); |
| 75 | + // myGPS.powerOffWithInterrupt(20000, GPS_INT0); |
| 76 | + |
| 77 | + delay(10000); |
| 78 | + |
| 79 | + // After 10 seconds wake the device via the specified pin on your microcontroller and module. |
| 80 | + wakeUp(); |
| 81 | +} |
| 82 | + |
| 83 | +void loop() { |
| 84 | + //Do nothing |
| 85 | +} |
0 commit comments