-
Notifications
You must be signed in to change notification settings - Fork 35
Closed
Description
I am using F9P and esp32 board to get the data continuously. I have observed that while fetching the data from UART, I can receive the data within a second whereas when I trying to receive the data through I2C, there is a significant delay of 2-8 seconds. What could be the reason and how should I optimize so that I can get the data through I2C itself quickly?
#include <SparkFun_u-blox_GNSS_v3.h>
#include <Wire.h>
#include<HardwareSerial.h>
#include"ArduinoJson.h"
HardwareSerial gnssserial(2);
SFE_UBLOX_GNSS_SERIAL gnss;
void getDGPSdata(void* pvParameters) {
while (true) {
if (bluetooth.hasClient()) {
Serial.println("calculating the data value");
StaticJsonDocument<256> dgps;
dgps["latitude"] = gnss.getLatitude();
Serial.println("lat is calculated");
dgps["longitude"] = gnss.getLongitude();
Serial.println("long is calculated");
dgps["altitude"] = gnss.getAltitude();
Serial.println("alt..");
dgps["altitudeMSL"] = gnss.getAltitudeMSL();
Serial.println("altmsl..");
dgps["fixType"] = gnss.getFixType();
Serial.println("fix...");
dgps["solutionType"] = gnss.getCarrierSolutionType();
Serial.println("sol..");
dgps["accuracyHorizontal"] = gnss.getHorizontalAccuracy();
Serial.println("h...");
dgps["accuracyVertical"] = gnss.getVerticalAccuracy();
Serial.println("v...");
dgps["bluetStrengthValue"] =0;
Serial.println("bt...");
dgps["satelliteUsed"] =gnss.getSIV();
Serial.println("sat...");
dgps["PDOP"] = gnss.getPositionDOP();
Serial.println("pdop...");
dgps["HDOP"] = gnss.getHorizontalDOP();
Serial.println("hdop...");
dgps["VDOP"] = gnss.getVerticalDOP();
Serial.println("vdop...");
String output;
serializeJson(dgps,output);
Serial.println("paylaod..");
StaticJsonDocument<256> msg;
msg["topic"] = "dgpsData";
msg["payload"] = output;
String Data;
serializeJson(msg, Data);
Serial.println(Data);
vTaskDelay(pdMS_TO_TICKS(100));
}
}
}
void setup() {
Serial.begin(115200);
while(!Serial);
Serial.println("Starting GNSS...");
gnss.connectedToUART2();
gnssserial.begin(921600,SERIAL_8N1,16,17);
// Wire.begin(21,22);
// Wire.setClock(400000);
while (1){
if (gnss.begin(gnssserial) == false) {
Serial.println("GNSS init failed!");
delay(1000);
}
else{
Serial.println("GNSS connected over I2C");
break;
}
}
xTaskCreatePinnedToCore(getDGPSdata, "getDGPSdata", 4096, NULL, 1,NULL, 1);
}
void loop() {
}
Metadata
Metadata
Assignees
Labels
No labels