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)
52
+ ; // Wait for user to open terminal
53
+ Serial.println (" SparkFun Ublox Example" );
54
+
55
+ Wire.begin ();
56
+
57
+ if (myGPS.begin () == false ) // Connect to the Ublox module using Wire port
58
+ {
59
+ Serial.println (F (" Ublox GPS not detected at default I2C address. Please check wiring. Freezing." ));
60
+ while (1 )
61
+ ;
62
+ }
63
+
64
+ // myGPS.enableDebugging(); // Uncomment this line to enable debug messages
65
+
66
+ myGPS.setI2COutput (COM_TYPE_UBX); // Set the I2C port to output UBX only (turn off NMEA noise)
67
+ // 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" );
72
+ }
73
+
74
+ void loop ()
75
+ {
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
+
100
+ // Query module every 10 seconds so it is easier to monitor the current draw
101
+ if (millis () - lastTime > 10000 )
102
+ {
103
+ lastTime = millis (); // Update the timer
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
+
119
+ long latitude = myGPS.getLatitude ();
120
+ Serial.print (F (" Lat: " ));
121
+ Serial.print (latitude);
122
+
123
+ long longitude = myGPS.getLongitude ();
124
+ Serial.print (F (" Long: " ));
125
+ Serial.print (longitude);
126
+ Serial.print (F (" (degrees * 10^-7)" ));
127
+
128
+ long altitude = myGPS.getAltitude ();
129
+ Serial.print (F (" Alt: " ));
130
+ Serial.print (altitude);
131
+ Serial.print (F (" (mm)" ));
132
+
133
+ Serial.println ();
134
+ }
135
+ }
0 commit comments