See below the output at Serial monitor from my code. Although I have setNavigationFrequency to 2 solutions/second it often takes over 2 seconds to respond, and even then it only updates the GPS coordinates every 5 - 10 seconds. (NB: the ms value in square brackets at end of each line is time spent in that loop)
Also it sometimes respond really quick, even < 100ms.
What am I doing wrong? (TIA)
My hardware:
Micromod Main Double board, fitted with:
Processor board : Micromod Teensy
Function board 0: Micromod ZED-F9P GNSS
Function board 1: Micromod ESP-32 WiFi/Bluetooth
My code, on Teensy:
#include <Streaming.h>
#include <TimeLib.h>
#include <SparkFun_u-blox_GNSS_v3.h>
#define ZED Serial1 // for TX of RTCM3 corrections + RX of GNS status data
SFE_UBLOX_GNSS_SERIAL gnss;
time_t timeU; // UTC
uint32_t t0,t1,t2; // timestamps
int32_t latitude, longitude, altitude; // GPS coords
void setup() {
Serial.begin(115200); // not needed teensy
while (!Serial && millis() < 1000);
delay(1000);
Serial << "\n\n======= GPS_basic.A =======\n";
initGNS();
processGPStime(); // UTC time
reportDateTime(timeU);
Serial << '\n' << '\n';
latitude = gnss.getLatitude(); // (10^7)°
longitude = gnss.getLongitude(); // (10^7)°
Serial << "Lat/Lon: " << latitude << " / " << longitude << " ° (*10^7)";
Serial << "\n\n------ setup() done -----\n";
t0 = millis();
}
uint loops = 0;
void loop() {
t1 = millis();
//if (t1 - t0 >= 1000) {
Serial << _WIDTHZ(++loops,3) << ": ";
processGPStime();
reportDateTime(timeU);
latitude = gnss.getLatitude();
longitude = gnss.getLongitude();
Serial << " Lat/Lon " << latitude << " / " << longitude; // << "° (*10^7) ";
t0 = millis();
Serial << " [" << (t0-t1) << " ms]\n";
//}
}
void initGNS(){
Serial << " * initialise GNSS : ";
ZED.begin(921600); // 8 x 115200 bps = 115.2 kB/s
while (!gnss.begin(ZED)) { // Connect to ZED-F9P over Serial
Serial << ".";
delay (1000);
}
gnss.setUART1Output(COM_TYPE_UBX); // same, for Serial/UART1 connections
gnss.setNavigationFrequency(2); // set for 2 solutions/second
Serial << "OK [2 sol/sec]\n";
Serial << " * Wait for GPS Fix : ";
while (!gnss.getGnssFixOk()) { // Connect to the u-blox module
Serial << ".";
delay (1000);
}
Serial << "OK\n";
Serial << " * Wait for GPS PVT : ";
while (!gnss.getPVT()) {
Serial << ".";
delay(500);
}
Serial << " OK\n\n";
}
void processGPStime(){
tmElements_t tm;
tm.Year = gnss.getYear(1) - 1970; // load UTC time elements
tm.Month = gnss.getMonth(1);
tm.Day = gnss.getDay(1);
tm.Hour = gnss.getHour(1);
tm.Minute = gnss.getMinute(1);
tm.Second = gnss.getSecond(1);
timeU = makeTime(tm); // UTC = GPS time (as unixtime)
}
void reportDateTime(time_t t){
if (t >= 946684800 && t < 2524608000){ // if in valid years (1/1/2000 to 31/12/2049)
Serial << "UTC ";
Serial << _WIDTHZ( hour(t),2) << ":"
<< _WIDTHZ(minute(t),2) << ":"
<< _WIDTHZ(second(t),2) << " ";
Serial << dayShortStr(weekday(t)) << " "
<< _WIDTHZ( day(t),2) << "/"
<< _WIDTHZ(month(t),2) << "/"
<< year(t);
}
else Serial << " *** time invalid (2) ***";
}