Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.
Prev Previous commit
Add menu to control power
  • Loading branch information
Nathan Seidle committed Dec 23, 2019
commit 9024f2e378792bbad0cd9d4b8e71d537f9c201c5
90 changes: 51 additions & 39 deletions examples/Example19_PowerSaveMode/Example19_PowerSaveMode.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Power Save Mode
By: Paul Clark (PaulZC)
Date: December 18th, 2019

Based extensively on Example3_GetPosition
By: Nathan Seidle
SparkFun Electronics
Expand All @@ -21,7 +21,7 @@
Note: this will fail on the ZED (protocol version >= 27) as UBX-CFG-RXM is not supported

Note: Long/lat are large numbers because they are * 10^7. To convert lat/long
to something google maps understands simply divide the numbers by 10,000,000. We
to something google maps understands simply divide the numbers by 10,000,000. We
do this so that we don't have to use floating point numbers.

Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
Expand All @@ -48,64 +48,76 @@ long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox m
void setup()
{
Serial.begin(115200);
while (!Serial); //Wait for user to open terminal
while (!Serial)
; //Wait for user to open terminal
Serial.println("SparkFun Ublox Example");

Wire.begin();

if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
{
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
while (1);
while (1)
;
}

//myGPS.enableDebugging(); // Uncomment this line to enable debug messages

Serial.println(F("Waiting for a 3D fix..."));

byte fixType = 0;

while (fixType != 3) // Wait for a 3D fix
{
fixType = myGPS.getFixType(); // Get the fix type
Serial.print(F("Fix: "));
Serial.print(fixType);
if(fixType == 0) Serial.print(F(" = No fix"));
else if(fixType == 1) Serial.print(F(" = Dead reckoning"));
else if(fixType == 2) Serial.print(F(" = 2D"));
else if(fixType == 3) Serial.print(F(" = 3D"));
else if(fixType == 4) Serial.print(F(" = GNSS + Dead reckoning"));
Serial.println();
delay(1000);
}

Serial.println(F("3D fix found! Engaging power save mode..."));

// Put the GNSS into power save mode
// (If you want to disable power save mode, call myGPS.powerSaveMode(false) instead)
// This will fail on the ZED (protocol version >= 27) as UBX-CFG-RXM is not supported
if (myGPS.powerSaveMode())
{
Serial.println(F("Power Save Mode enabled."));
}
else
{
Serial.println(F("***!!! Power Save Mode FAILED !!!***"));
}

myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
//myGPS.saveConfiguration(); //Uncomment this line to save the current settings to flash and BBR

Serial.println("Power save example.");
Serial.println("1) Enable power saving");
Serial.println("2) Disable power saving");
}

void loop()
{
if (Serial.available())
{
byte incoming = Serial.read();

if (incoming == '1')
{
// Put the GNSS into power save mode
// (If you want to disable power save mode, call myGPS.powerSaveMode(false) instead)
// This will fail on the ZED (protocol version >= 27) as UBX-CFG-RXM is not supported
if (myGPS.powerSaveMode())
Serial.println(F("Power Save Mode enabled."));
else
Serial.println(F("***!!! Power Save Mode FAILED !!!***"));
}
else if (incoming == '2')
{
//Go to normal power mode (not power saving mode)
if (myGPS.powerSaveMode(false))
Serial.println(F("Power Save Mode disabled."));
else
Serial.println(F("***!!! Power Save Disable FAILED !!!***"));
}
}

//Query module every 10 seconds so it is easier to monitor the current draw
if (millis() - lastTime > 10000)
{
lastTime = millis(); //Update the timer


byte fixType = myGPS.getFixType(); // Get the fix type
Serial.print(F("Fix: "));
Serial.print(fixType);
if (fixType == 0)
Serial.print(F("(No fix)"));
else if (fixType == 1)
Serial.print(F("(Dead reckoning)"));
else if (fixType == 2)
Serial.print(F("(2D)"));
else if (fixType == 3)
Serial.print(F("(3D)"));
else if (fixType == 4)
Serial.print(F("(GNSS + Dead reckoning)"));

long latitude = myGPS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(F(" Lat: "));
Serial.print(latitude);

long longitude = myGPS.getLongitude();
Expand All @@ -120,4 +132,4 @@ void loop()

Serial.println();
}
}
}