arkieguy

UBLOX Example

May 7th, 2021
574
143 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Arduino.h>
  2.  
  3. /**
  4.    @file RAK12500_GPS_ZOE-M8Q_IIC.ino
  5.    @author rakwireless.com
  6.    @brief use I2C get and parse gps data
  7.    @version 0.1
  8.    @date 2021-1-28
  9.    @copyright Copyright (c) 2021
  10. **/
  11.  
  12. #include <Wire.h> //Needed for I2C to GNSS
  13.  
  14. #include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
  15.  
  16. #define WB_IO2 34
  17.  
  18. SFE_UBLOX_GNSS g_myGNSS;
  19.  
  20. long g_lastTime = 0; //Simple local timer. Limits amount if I2C traffic to u-blox module.
  21.  
  22. void setup()
  23. {
  24.   pinMode(WB_IO2, OUTPUT);
  25.   digitalWrite(WB_IO2, 0);
  26.   delay(1000);
  27.   digitalWrite(WB_IO2, 1);
  28.   delay(1000);
  29.  
  30.   Wire.begin();
  31.   // Initialize Serial for debug output
  32.   time_t timeout = millis();
  33.   Serial.begin(115200);
  34.   while (!Serial)
  35.   {
  36.     if ((millis() - timeout) < 5000)
  37.     {
  38.       delay(100);
  39.     }
  40.     else
  41.     {
  42.       break;
  43.     }
  44.   }
  45.   Serial.println("GPS ZOE-M8Q Example(I2C)");
  46.   if (g_myGNSS.begin() == false) //Connect to the u-blox module using Wire port
  47.   {
  48.     Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
  49.     delay(1000);
  50.     while (1);
  51.   }
  52.  
  53.   g_myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
  54.   g_myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
  55. }
  56.  
  57. void loop()
  58. {
  59.   if (millis() - g_lastTime > 1000)
  60.   {
  61.     g_lastTime = millis(); //Update the timer
  62.    
  63.     long latitude = g_myGNSS.getLatitude();
  64.     Serial.print(F("Lat: "));
  65.     Serial.print(latitude);
  66.  
  67.     long longitude = g_myGNSS.getLongitude();
  68.     Serial.print(F(" Long: "));
  69.     Serial.print(longitude);
  70.     Serial.print(F(" (degrees * 10^-7)"));
  71.  
  72.     long altitude = g_myGNSS.getAltitude();
  73.     Serial.print(F(" Alt: "));
  74.     Serial.print(altitude);
  75.     Serial.print(F(" (mm)"));
  76.    
  77.     long speed = g_myGNSS.getGroundSpeed();
  78.     Serial.print(F(" Speed: "));
  79.     Serial.print(speed);
  80.     Serial.print(F(" (mm/s)"));
  81.  
  82.     long heading = g_myGNSS.getHeading();
  83.     Serial.print(F(" Heading: "));
  84.     Serial.print(heading);
  85.     Serial.print(F(" (degrees * 10^-5)"));
  86.  
  87.     byte SIV = g_myGNSS.getSIV();
  88.     Serial.print(F(" SIV: "));
  89.     Serial.println(SIV);
  90.   }
  91. }
RAW Paste Data