22 Power Save Mode
33 By: Paul Clark (PaulZC)
44 Date: December 18th, 2019
5-
5+
66 Based extensively on Example3_GetPosition
77 By: Nathan Seidle
88 SparkFun Electronics
2121 Note: this will fail on the ZED (protocol version >= 27) as UBX-CFG-RXM is not supported
2222
2323 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
24+ to something google maps understands simply divide the numbers by 10,000,000. We
2525 do this so that we don't have to use floating point numbers.
2626
2727 Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
@@ -48,64 +48,76 @@ long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox m
4848void setup ()
4949{
5050 Serial.begin (115200 );
51- while (!Serial); // Wait for user to open terminal
51+ while (!Serial)
52+ ; // Wait for user to open terminal
5253 Serial.println (" SparkFun Ublox Example" );
5354
5455 Wire.begin ();
5556
5657 if (myGPS.begin () == false ) // Connect to the Ublox module using Wire port
5758 {
5859 Serial.println (F (" Ublox GPS not detected at default I2C address. Please check wiring. Freezing." ));
59- while (1 );
60+ while (1 )
61+ ;
6062 }
6163
6264 // myGPS.enableDebugging(); // Uncomment this line to enable debug messages
6365
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-
9666 myGPS.setI2COutput (COM_TYPE_UBX); // Set the I2C port to output UBX only (turn off NMEA noise)
9767 // myGPS.saveConfiguration(); //Uncomment this line to save the current settings to flash and BBR
68+
69+ Serial.println (" Power save example." );
70+ Serial.println (" 1) Enable power saving" );
71+ Serial.println (" 2) Disable power saving" );
9872}
9973
10074void loop ()
10175{
76+ if (Serial.available ())
77+ {
78+ byte incoming = Serial.read ();
79+
80+ if (incoming == ' 1' )
81+ {
82+ // Put the GNSS into power save mode
83+ // (If you want to disable power save mode, call myGPS.powerSaveMode(false) instead)
84+ // This will fail on the ZED (protocol version >= 27) as UBX-CFG-RXM is not supported
85+ if (myGPS.powerSaveMode ())
86+ Serial.println (F (" Power Save Mode enabled." ));
87+ else
88+ Serial.println (F (" ***!!! Power Save Mode FAILED !!!***" ));
89+ }
90+ else if (incoming == ' 2' )
91+ {
92+ // Go to normal power mode (not power saving mode)
93+ if (myGPS.powerSaveMode (false ))
94+ Serial.println (F (" Power Save Mode disabled." ));
95+ else
96+ Serial.println (F (" ***!!! Power Save Disable FAILED !!!***" ));
97+ }
98+ }
99+
102100 // Query module every 10 seconds so it is easier to monitor the current draw
103101 if (millis () - lastTime > 10000 )
104102 {
105103 lastTime = millis (); // Update the timer
106-
104+
105+ byte fixType = myGPS.getFixType (); // Get the fix type
106+ Serial.print (F (" Fix: " ));
107+ Serial.print (fixType);
108+ if (fixType == 0 )
109+ Serial.print (F (" (No fix)" ));
110+ else if (fixType == 1 )
111+ Serial.print (F (" (Dead reckoning)" ));
112+ else if (fixType == 2 )
113+ Serial.print (F (" (2D)" ));
114+ else if (fixType == 3 )
115+ Serial.print (F (" (3D)" ));
116+ else if (fixType == 4 )
117+ Serial.print (F (" (GNSS + Dead reckoning)" ));
118+
107119 long latitude = myGPS.getLatitude ();
108- Serial.print (F (" Lat: " ));
120+ Serial.print (F (" Lat: " ));
109121 Serial.print (latitude);
110122
111123 long longitude = myGPS.getLongitude ();
@@ -120,4 +132,4 @@ void loop()
120132
121133 Serial.println ();
122134 }
123- }
135+ }
0 commit comments