|
6 | 6 | License: MIT. See license file for more information but you can
|
7 | 7 | basically do whatever you want with this code.
|
8 | 8 |
|
9 |
| - This example shows how to query a Ublox module for its lat/long/altitude. Leave NMEA |
10 |
| - parsing behind. Now you can simply ask the module for the datums you want! |
| 9 | + This example shows how to query a Ublox module for its lat/long/altitude. |
| 10 | +
|
| 11 | + Note: Long/lat are large numbers because they are * 10^7. To convert lat/long |
| 12 | + to something google maps understands simply divide the numbers by 1,000,000. We |
| 13 | + do this so that we don't have to use floating point numbers. |
| 14 | +
|
| 15 | + Leave NMEA parsing behind. Now you can simply ask the module for the datums you want! |
11 | 16 |
|
12 | 17 | Feel like supporting open source hardware?
|
13 | 18 | Buy a board from SparkFun!
|
@@ -36,120 +41,39 @@ void setup()
|
36 | 41 |
|
37 | 42 | Wire.begin();
|
38 | 43 |
|
39 |
| - myGPS.begin(); //Connect to the Ublox module using Wire port |
40 |
| - if (myGPS.isConnected() == false) |
| 44 | + if (myGPS.begin() == false) //Connect to the Ublox module using Wire port |
41 | 45 | {
|
42 | 46 | Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
|
43 | 47 | while (1);
|
44 | 48 | }
|
45 |
| - |
46 |
| - //Wire.setClock(400000); //Increase I2C clock speed to 400kHz |
47 |
| - |
48 |
| - /*byte response; |
49 |
| - response = myGPS.getVal(VAL_GROUP_I2C, VAL_ID_I2C_ADDRESS, VAL_GROUP_I2C_SIZE, VAL_LAYER_RAM); |
50 |
| - Serial.print("res: 0x"); |
51 |
| - Serial.println(response, HEX); |
52 |
| -
|
53 |
| - delay(100); |
54 |
| -
|
55 |
| - response = myGPS.getVal(VAL_GROUP_I2COUTPROT, VAL_ID_I2COUTPROT_NMEA, VAL_GROUP_I2COUTPROT_SIZE, VAL_LAYER_RAM); |
56 |
| - Serial.print("res: 0x"); |
57 |
| - Serial.print(response, HEX); |
58 |
| - while(1);*/ |
59 |
| - |
60 |
| - |
61 |
| - myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) |
62 |
| - myGPS.setNavigationFrequency(4); //Set output to 4 times a second |
63 |
| - |
64 |
| - byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module |
65 |
| - Serial.print("Update rate:"); |
66 |
| - Serial.println(rate); |
67 |
| - |
68 |
| - while(1); |
69 |
| - |
70 |
| - /*long pos = myGPS.getPositionAccuracy(); |
71 |
| - Serial.print("pos: "); |
72 |
| - Serial.println(pos); |
73 |
| -
|
74 |
| - byte version = myGPS.getProtocolVersionHigh(); |
75 |
| - Serial.print("version: "); |
76 |
| - Serial.println(version);*/ |
77 |
| - |
78 |
| - long latitude = myGPS.getLatitude(1000); |
79 |
| - Serial.print("Lat: "); |
80 |
| - Serial.print(latitude); |
81 |
| - |
82 |
| - |
83 |
| - long longitude = myGPS.getLongitude(2000); |
84 |
| - Serial.print(" Long: "); |
85 |
| - Serial.print(longitude); |
86 |
| - Serial.print(" (degrees * 10^-7)"); |
87 |
| - |
88 |
| - long altitude = myGPS.getAltitude(); |
89 |
| - Serial.print(" Alt (above mean sea level): "); |
90 |
| - Serial.print(altitude); |
91 |
| - Serial.print(" (mm)"); |
92 |
| - |
93 |
| - byte SIV = myGPS.getSIV(); |
94 |
| - Serial.print(" SIV: "); |
95 |
| - Serial.print(SIV); |
96 |
| - |
97 |
| - byte fixType = myGPS.getFixType(); |
98 |
| - Serial.print(" Fix: "); |
99 |
| - Serial.print(fixType); |
100 |
| - |
101 |
| - byte RTK = myGPS.getCarrierSolutionType(); |
102 |
| - Serial.print(" RTK: "); |
103 |
| - Serial.print(RTK); |
104 |
| - if (RTK == 1) Serial.println("High precision float fix!"); |
105 |
| - if (RTK == 2) Serial.println("High precision fix!"); |
106 |
| - |
107 |
| - long speed = myGPS.getGroundSpeed(); |
108 |
| - Serial.print(" Speed: "); |
109 |
| - Serial.print(speed); |
110 |
| - Serial.print(" (mm/s)"); |
111 |
| - |
112 |
| - long heading = myGPS.getHeading(); |
113 |
| - Serial.print(" Heading: "); |
114 |
| - Serial.print(heading); |
115 |
| - Serial.print(" (degrees * 10^-5)"); |
116 |
| - |
117 |
| - int pDOP = myGPS.getPDOP(); |
118 |
| - Serial.print(" pDOP: "); |
119 |
| - Serial.print(pDOP / 100.0, 2); |
120 |
| - |
121 |
| - while (1); |
122 | 49 | }
|
123 | 50 |
|
124 | 51 | void loop()
|
125 | 52 | {
|
126 |
| - /* myGPS.checkUblox(); //See if new data is available. Process bytes as they come in. |
127 |
| -
|
128 |
| - delay(250); //Don't pound too hard on the I2C bus |
129 |
| -
|
130 |
| - //Every other second print the current 3D position accuracy |
131 |
| - if (millis() - lastTime > 1000) |
132 |
| - { |
133 |
| - long latitude = myGPS.getLatitude(); |
134 |
| - Serial.print("Lat: "); |
135 |
| - Serial.print(latitude); |
136 |
| -
|
137 |
| - while (1); |
138 |
| -
|
139 |
| - long longitude = myGPS.getLongitude(); |
140 |
| - Serial.print(" Long: "); |
141 |
| - Serial.print(longitude); |
142 |
| - Serial.print(" (degrees * 10^-7)"); |
143 |
| -
|
144 |
| - long altitude = myGPS.getAltitude(); |
145 |
| - Serial.print(" Alt (above mean sea level): "); |
146 |
| - Serial.print(altitude); |
147 |
| - Serial.print(" (mm)"); |
148 |
| -
|
149 |
| - long altitudeEllipsoid = myGPS.getAltitudeEllipsoid(); |
150 |
| - Serial.print(" AltMSL (above Ellipsoid model surface of earth): "); |
151 |
| - Serial.print(altitudeEllipsoid); |
152 |
| - Serial.println(" (mm)"); |
153 |
| - }*/ |
154 |
| - |
| 53 | + //Query module only every second. Doing it more often will just cause I2C traffic. |
| 54 | + //The module only responds when a new position is available |
| 55 | + if (millis() - lastTime > 1000) |
| 56 | + { |
| 57 | + lastTime = millis(); //Update the timer |
| 58 | + |
| 59 | + long latitude = myGPS.getLatitude(); |
| 60 | + Serial.print(F("Lat: ")); |
| 61 | + Serial.print(latitude); |
| 62 | + |
| 63 | + long longitude = myGPS.getLongitude(); |
| 64 | + Serial.print(F(" Long: ")); |
| 65 | + Serial.print(longitude); |
| 66 | + Serial.print(F(" (degrees * 10^-7)")); |
| 67 | + |
| 68 | + long altitude = myGPS.getAltitude(); |
| 69 | + Serial.print(F(" Alt (above mean sea level): ")); |
| 70 | + Serial.print(altitude); |
| 71 | + Serial.print(F(" (mm)")); |
| 72 | + |
| 73 | + byte SIV = myGPS.getSIV(); |
| 74 | + Serial.print(F(" SIV: ")); |
| 75 | + Serial.print(SIV); |
| 76 | + |
| 77 | + Serial.println(); |
| 78 | + } |
155 | 79 | }
|
0 commit comments