|
| 1 | +/* |
| 2 | + Power Save Mode |
| 3 | + By: Paul Clark (PaulZC) |
| 4 | + Date: December 18th, 2019 |
| 5 | + |
| 6 | + Based extensively on Example3_GetPosition |
| 7 | + By: Nathan Seidle |
| 8 | + SparkFun Electronics |
| 9 | + Date: January 3rd, 2019 |
| 10 | + License: MIT. See license file for more information but you can |
| 11 | + basically do whatever you want with this code. |
| 12 | +
|
| 13 | + This example shows how to put the Ublox module into power save mode and then |
| 14 | + query its lat/long/altitude. We also turn off the NMEA output on the I2C port. |
| 15 | + This decreases the amount of I2C traffic dramatically. |
| 16 | +
|
| 17 | + ** When it is able to ** the module will reduce its current draw. |
| 18 | + For the ZOE-M8Q with a passive antenna, you should see the current drop |
| 19 | + from (approx.) 25-28mA to (approx.) 9mA when power save mode kicks in. |
| 20 | +
|
| 21 | + Note: this will fail on the ZED (protocol version >= 27) as UBX-CFG-RXM is not supported |
| 22 | +
|
| 23 | + Note: Long/lat are large numbers because they are * 10^7. To convert lat/long |
| 24 | + to something google maps understands simply divide the numbers by 10,000,000. We |
| 25 | + do this so that we don't have to use floating point numbers. |
| 26 | +
|
| 27 | + Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! |
| 28 | +
|
| 29 | + Feel like supporting open source hardware? |
| 30 | + Buy a board from SparkFun! |
| 31 | + ZED-F9P RTK2: https://www.sparkfun.com/products/15136 |
| 32 | + NEO-M8P RTK: https://www.sparkfun.com/products/15005 |
| 33 | + SAM-M8Q: https://www.sparkfun.com/products/15106 |
| 34 | +
|
| 35 | + Hardware Connections: |
| 36 | + Plug a Qwiic cable into the GPS and a BlackBoard |
| 37 | + If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) |
| 38 | + Open the serial monitor at 115200 baud to see the output |
| 39 | +*/ |
| 40 | + |
| 41 | +#include <Wire.h> //Needed for I2C to GPS |
| 42 | + |
| 43 | +#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS |
| 44 | +SFE_UBLOX_GPS myGPS; |
| 45 | + |
| 46 | +long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module. |
| 47 | + |
| 48 | +void setup() |
| 49 | +{ |
| 50 | + Serial.begin(115200); |
| 51 | + while (!Serial); //Wait for user to open terminal |
| 52 | + Serial.println("SparkFun Ublox Example"); |
| 53 | + |
| 54 | + Wire.begin(); |
| 55 | + |
| 56 | + if (myGPS.begin() == false) //Connect to the Ublox module using Wire port |
| 57 | + { |
| 58 | + Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing.")); |
| 59 | + while (1); |
| 60 | + } |
| 61 | + |
| 62 | + //myGPS.enableDebugging(); // Uncomment this line to enable debug messages |
| 63 | + |
| 64 | + Serial.println(F("Waiting for a 3D fix...")); |
| 65 | + |
| 66 | + byte fixType = 0; |
| 67 | + |
| 68 | + while (fixType != 3) // Wait for a 3D fix |
| 69 | + { |
| 70 | + fixType = myGPS.getFixType(); // Get the fix type |
| 71 | + Serial.print(F("Fix: ")); |
| 72 | + Serial.print(fixType); |
| 73 | + if(fixType == 0) Serial.print(F(" = No fix")); |
| 74 | + else if(fixType == 1) Serial.print(F(" = Dead reckoning")); |
| 75 | + else if(fixType == 2) Serial.print(F(" = 2D")); |
| 76 | + else if(fixType == 3) Serial.print(F(" = 3D")); |
| 77 | + else if(fixType == 4) Serial.print(F(" = GNSS + Dead reckoning")); |
| 78 | + Serial.println(); |
| 79 | + delay(1000); |
| 80 | + } |
| 81 | + |
| 82 | + Serial.println(F("3D fix found! Engaging power save mode...")); |
| 83 | + |
| 84 | + // Put the GNSS into power save mode |
| 85 | + // (If you want to disable power save mode, call myGPS.powerSaveMode(false) instead) |
| 86 | + // This will fail on the ZED (protocol version >= 27) as UBX-CFG-RXM is not supported |
| 87 | + if (myGPS.powerSaveMode()) |
| 88 | + { |
| 89 | + Serial.println(F("Power Save Mode enabled.")); |
| 90 | + } |
| 91 | + else |
| 92 | + { |
| 93 | + Serial.println(F("***!!! Power Save Mode FAILED !!!***")); |
| 94 | + } |
| 95 | + |
| 96 | + myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) |
| 97 | + //myGPS.saveConfiguration(); //Uncomment this line to save the current settings to flash and BBR |
| 98 | +} |
| 99 | + |
| 100 | +void loop() |
| 101 | +{ |
| 102 | + //Query module every 10 seconds so it is easier to monitor the current draw |
| 103 | + if (millis() - lastTime > 10000) |
| 104 | + { |
| 105 | + lastTime = millis(); //Update the timer |
| 106 | + |
| 107 | + long latitude = myGPS.getLatitude(); |
| 108 | + Serial.print(F("Lat: ")); |
| 109 | + Serial.print(latitude); |
| 110 | + |
| 111 | + long longitude = myGPS.getLongitude(); |
| 112 | + Serial.print(F(" Long: ")); |
| 113 | + Serial.print(longitude); |
| 114 | + Serial.print(F(" (degrees * 10^-7)")); |
| 115 | + |
| 116 | + long altitude = myGPS.getAltitude(); |
| 117 | + Serial.print(F(" Alt: ")); |
| 118 | + Serial.print(altitude); |
| 119 | + Serial.print(F(" (mm)")); |
| 120 | + |
| 121 | + Serial.println(); |
| 122 | + } |
| 123 | +} |
0 commit comments