Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 3dddb6e

Browse files
committed
Begining to add I2C lat/long harvesting
1 parent 163df86 commit 3dddb6e

File tree

3 files changed

+84
-30
lines changed

3 files changed

+84
-30
lines changed

examples/Example3_GetPosition/Example3_GetPosition.ino

+10-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ void setup()
3434
while (!Serial); //Wait for user to open terminal
3535
Serial.println("Ublox high precision accuracy example");
3636

37+
Wire.begin();
38+
3739
myGPS.begin(); //Connect to the Ublox module using Wire port
3840
if (myGPS.isConnected() == false)
3941
{
@@ -54,10 +56,14 @@ void loop()
5456
//Every other second print the current 3D position accuracy
5557
if(millis() - lastTime > 1000)
5658
{
57-
long accuracy = myGPS.getPositionAccuracy();
58-
Serial.print("3D Positional Accuracy: ");
59-
Serial.print(accuracy);
60-
Serial.println("mm");
59+
long lat = myGPS.getLatitude();
60+
Serial.print("Lat: ");
61+
Serial.print(lat);
62+
63+
long longitude = myGPS.getLongitude();
64+
Serial.print(" Long: ");
65+
Serial.print(longitude);
66+
Serial.println(" (degrees * 10^-7)");
6167
}
6268

6369
}

src/SparkFun_Ublox_Arduino_Library.cpp

+67-25
Original file line numberDiff line numberDiff line change
@@ -478,31 +478,6 @@ boolean SFE_UBLOX_GPS::waitForResponse(uint16_t maxTime)
478478
return (false);
479479
}
480480

481-
482-
//Get the current 3D high precision positional accuracy - a fun thing to watch
483-
//Returns a float representing the 3D accuracy in millimeters
484-
uint32_t SFE_UBLOX_GPS::getPositionAccuracy(uint16_t maxWait)
485-
{
486-
packetCfg.cls = UBX_CLASS_NAV;
487-
packetCfg.id = UBX_NAV_HPPOSECEF;
488-
packetCfg.len = 0;
489-
490-
if(sendCommand(packetCfg, maxWait) == false)
491-
return(0); //If command send fails then bail
492-
493-
//We got a response, now parse the bits into the float variable
494-
uint32_t tempAccuracy = 0;
495-
tempAccuracy |= payloadCfg[24] << 8*0;
496-
tempAccuracy |= payloadCfg[25] << 8*1;
497-
tempAccuracy |= payloadCfg[26] << 8*2;
498-
tempAccuracy |= payloadCfg[27] << 8*3;
499-
500-
if(tempAccuracy % 10) >= 5) tempAccuracy += 5; //Round fraction of mm up to next mm if .5 or above
501-
tempAccuracy /= 10; //Convert 0.1mm units to mm
502-
503-
return(tempAccuracy);
504-
}
505-
506481
//Get the current TimeMode3 settings - these contain survey in statuses
507482
boolean SFE_UBLOX_GPS::getSurveyMode(uint16_t maxWait)
508483
{
@@ -648,3 +623,70 @@ boolean SFE_UBLOX_GPS::getPortSettings(uint8_t portID, uint16_t maxWait)
648623

649624
return ( sendCommand(packetCfg, maxWait) );
650625
}
626+
627+
//Get the current 3D high precision positional accuracy - a fun thing to watch
628+
//Returns a float representing the 3D accuracy in millimeters
629+
uint32_t SFE_UBLOX_GPS::getPositionAccuracy(uint16_t maxWait)
630+
{
631+
packetCfg.cls = UBX_CLASS_NAV;
632+
packetCfg.id = UBX_NAV_HPPOSECEF;
633+
packetCfg.len = 0;
634+
635+
if(sendCommand(packetCfg, maxWait) == false)
636+
return(0); //If command send fails then bail
637+
638+
//We got a response, now parse the byte fields into our variable
639+
uint32_t tempAccuracy = 0;
640+
tempAccuracy |= payloadCfg[24] << 8*0;
641+
tempAccuracy |= payloadCfg[25] << 8*1;
642+
tempAccuracy |= payloadCfg[26] << 8*2;
643+
tempAccuracy |= payloadCfg[27] << 8*3;
644+
645+
if( (tempAccuracy % 10) >= 5) tempAccuracy += 5; //Round fraction of mm up to next mm if .5 or above
646+
tempAccuracy /= 10; //Convert 0.1mm units to mm
647+
648+
return(tempAccuracy);
649+
}
650+
//Get the current latitude in degrees
651+
//Returns a long representing the number of degrees *10^-7
652+
uint32_t SFE_UBLOX_GPS::getLatitude(uint16_t maxWait)
653+
{
654+
//Query the module for the latest lat/long
655+
packetCfg.cls = UBX_CLASS_NAV;
656+
packetCfg.id = UBX_NAV_POSLLH;
657+
packetCfg.len = 0;
658+
659+
if(sendCommand(packetCfg, maxWait) == false)
660+
return(0); //If command send fails then bail
661+
662+
//We got a response, now parse the byte fields
663+
uint32_t pos = 0;
664+
pos |= payloadCfg[8] << 8*0;
665+
pos |= payloadCfg[9] << 8*1;
666+
pos |= payloadCfg[10] << 8*2;
667+
pos |= payloadCfg[11] << 8*3;
668+
669+
return(pos);
670+
}
671+
672+
//Get the current longitude in degrees
673+
//Returns a long representing the number of degrees *10^-7
674+
uint32_t SFE_UBLOX_GPS::getLongitude(uint16_t maxWait)
675+
{
676+
//Query the module for the latest lat/long
677+
packetCfg.cls = UBX_CLASS_NAV;
678+
packetCfg.id = UBX_NAV_POSLLH;
679+
packetCfg.len = 0;
680+
681+
if(sendCommand(packetCfg, maxWait) == false)
682+
return(0); //If command send fails then bail
683+
684+
//We got a response, now parse the byte fields
685+
uint32_t pos = 0;
686+
pos |= payloadCfg[4] << 8*0;
687+
pos |= payloadCfg[5] << 8*1;
688+
pos |= payloadCfg[6] << 8*2;
689+
pos |= payloadCfg[7] << 8*3;
690+
691+
return(pos);
692+
}

src/SparkFun_Ublox_Arduino_Library.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ const uint8_t UBX_CFG_TMODE3 = 0x71; //Used to enable Survey In Mode
9292
const uint8_t SVIN_MODE_DISABLE = 0x00;
9393
const uint8_t SVIN_MODE_ENABLE = 0x01;
9494

95+
const uint8_t UBX_NAV_POSLLH = 0x02; //Used for obtaining lat/long/alt in low precision
96+
const uint8_t UBX_NAV_HPPOSLLH = 0x14; //Used for obtaining lat/long/alt in high precision
97+
9598
const uint8_t UBX_NAV_SVIN = 0x3B; //Used for checking Survey In status
9699
const uint8_t UBX_NAV_HPPOSECEF = 0x13; //Find our positional accuracy (high precision)
97100

@@ -169,7 +172,10 @@ class SFE_UBLOX_GPS
169172

170173
boolean getPortSettings(uint8_t portID, uint16_t maxWait = 250); //Returns the current protocol bits in the UBX-CFG-PRT command for a given port
171174

172-
uint32_t getPositionAccuracy(uint16_t maxWait = 500); //Returns the 3D accuracy of the current high-precision fix
175+
uint32_t getPositionAccuracy(uint16_t maxWait = 500); //Returns the 3D accuracy of the current high-precision fix, in mm. Supported on NEO-M8P, ZED-F9P,
176+
177+
uint32_t getLatitude(uint16_t maxWait = 250); //Returns the current latitude in degrees * 10^-7. Auto selects between HighPrecision and Regular depending on ability of module.
178+
uint32_t getLongitude(uint16_t maxWait = 250); //Returns the current longitude in degrees * 10-7. Auto selects between HighPrecision and Regular depending on ability of module.
173179

174180
struct svinStructure {
175181
boolean active;

0 commit comments

Comments
 (0)