Milliseconds from Arduino MKR GPS shield

Hello, I have an Arduino MKR WRAN 1310 with a GPS shield mounted, a BME680 and a SD breakout board card connected. The code which I am implementing is reading data coming form the GPS + BME, printing it on the SD card and sending it via LoRa to a receiver (the LoRa signal is sent once every 10 cycles in the loop).

I want to retrieve the GPS time including milliseconds, but at the moment I am only capable of having the epoch time in seconds. I managed to set the GPS acquisition rate to 3Hz and the code is executing at 2Hz-ish.
I'm using the native library <Arduino_MKRGPS.h>. In the library documents, I have seen a file called minimea which has some reference about milliseconds, but honestly I do not have the competence to figure out the meaning or see if it can be useful.

Do you have any suggestion?

#include <Arduino_MKRGPS.h>
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <LoRa.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME680 bme;

byte destination = 0x5D;
int i=0;

void setup() {
  Serial.begin(115200);
  Wire.begin();

  if (!GPS.begin(GPS_MODE_SHIELD)) {
    Serial.println("Failed to initialize GPS!");
    while(1);
  }

  if (!SD.begin(7)) {
    Serial.println("Card failed, or not present");
    while(1);
  }

  if (!bme.begin()) {
    Serial.println(F("Could not find a valid BME680 sensor"));
    while (1);
  }
  bme.setTemperatureOversampling(BME680_OS_16X);
  bme.setHumidityOversampling(BME680_OS_16X);
  bme.setPressureOversampling(BME680_OS_16X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);

  if (!LoRa.begin(868E6)) {
   Serial.println("Starting LoRa failed!");
   while(1);
  }
  LoRa.setTxPower(17);   //17 dB (defoult)(max power)
  LoRa.setSpreadingFactor(7);  //7 defoult (can be set from 6 to 12)
  LoRa.setSignalBandwidth(62.5E3); //125E3 defoult (7.8 10.4 15.6 20.8 31.25 41.7 62.5 125 250 500) 
  LoRa.setCodingRate4(8); //5 defoult (can be from 5 to 8 that correspond to 4/5 and 4/8)
}

void loop() {

  if (GPS.available()) {
    // lettura GPS
    bme.performReading();

    // read GPS values
    unsigned long time = GPS.getTime();
    float latitude   = GPS.latitude();
    float longitude  = GPS.longitude();
    float altitude   = GPS.altitude();
    float speed      = GPS.speed();
    int   satellites = GPS.satellites();
    float temperature = bme.temperature;
    float pressure   = bme.pressure/100;     
    float humidity   = bme.humidity;

    // print GPS values, IN ORDER AS ABOVE
    Serial.print(i);
    Serial.print(" £ , ");
    Serial.print(time);
    Serial.print(" , ");
    Serial.print(latitude, 7);
    Serial.print(" , ");
    Serial.print(longitude, 7);
    Serial.print(" , ");
    Serial.print(altitude);
    Serial.print(" , ");
    Serial.print(speed);
    Serial.print(" , ");
    Serial.print(satellites);
    Serial.print(" , ");
    Serial.print(temperature);
    Serial.print(" , ");
    Serial.print(pressure);
    Serial.print(" , ");
    Serial.print(humidity);
    Serial.println(" , $");


    // store in the SD card
    File log = SD.open("gps.txt", FILE_WRITE);

    log.print("£ , ");
    log.print(time);
    log.print(" , ");
    log.print(latitude, 7);
    log.print(" , ");
    log.print(longitude, 7);
    log.print(" , ");
    log.print(altitude);
    log.print(" , ");
    log.print(speed);
    log.print(" , ");
    log.print(satellites);
    log.print(" , ");
    log.print(temperature);
    log.print(" , ");
    log.print(pressure);
    log.print(" , ");
    log.print(humidity);
    log.println(" , $");

    log.close();

    // transmission of data with LORA
    if(i==10){
      LoRa.beginPacket();

      LoRa.write(destination);
      LoRa.print("£ , "); 
      LoRa.print(time);
      LoRa.print(" , "); 
      LoRa.print(latitude, 7);
      LoRa.print(" , ");
      LoRa.print(longitude, 7);
      LoRa.print(" , ");
      LoRa.print(altitude);
      LoRa.print(" , ");
      LoRa.print(speed);
      LoRa.print(" , ");
      LoRa.print(satellites);
      LoRa.print(" , ");
      LoRa.print(temperature);
      LoRa.print(" , ");
      LoRa.print(pressure);
      LoRa.print(" , ");
      LoRa.print(humidity);
      LoRa.print(" , $");

      LoRa.endPacket();
      i=0;
    }
    i=i+1;
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.