arduino-libraries / Arduino_MKRGPS

MKRGPS Library for Arduino
GNU Lesser General Public License v2.1
8 stars 14 forks source link

problems with combination Arduino_MKRGPS.h and MKRIMU.h #22

Open Nocentinia opened 2 years ago

Nocentinia commented 2 years ago

using together the two libraries with an arduino MKR WAN 1310 it happens that GPS.available () returns Always 0, how can this be solved?

facchinm commented 2 years ago

Hi @Nocentinia , are you connecting the GPS module using the (eslov) cable or as a shield?

Nocentinia commented 2 years ago

Occurs both when I use it as a shield and with the cable

Nocentinia commented 2 years ago

one of the codes I tried

#include <Arduino_MKRGPS.h>
#include <MKRIMU.h>
const long interval = 500;
unsigned long currentMillis;

float latitude;
float altitude;
float speed;
int satellites;
float heading, roll, pitch;

void setup() {
  Serial.begin(9600);

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

void loop() {
  currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {

    previousMillis = currentMillis;
    if (GPS.available()) {
      // read GPS values
      latitude = GPS.latitude();
      longitude = GPS.longitude();
      altitude = GPS.altitude();
      speed = GPS.speed();
      satellites = GPS.satellites();
    }

    if (IMU.eulerAnglesAvailable()) {
      IMU.readEulerAngles(heading, roll, pitch);
    }
    print_data();
  }
}

void print_data() {
  Serial.print("Location: ");
  Serial.print(latitude, 7);
  Serial.print(", ");
  Serial.println(longitude, 7);

  Serial.print("Altitude: ");
  Serial.print(altitude);
  Serial.println("m");

  Serial.print("Ground speed: ");
  Serial.print(speed);
  Serial.println(" km/h");

  Serial.print("Number of satellites: ");
  Serial.println(satellites);

  Serial.print(heading);
  Serial.print('\t');
  Serial.print(roll);
  Serial.print('\t');
  Serial.println(pitch);
}
brynlljones commented 2 years ago

I'm also experiencing the same problem, but have a workaround. If I book-end my IMU reads with IMU.begin() and IMU.end(), and book-end my GPS reads with GPS.begin() and GPS.end(), then I'm able to read successfully form both devices. I'm not entirely sure why this works but would guess it has something to do with freeing up the I2C bus (I'm using the eslov cable to connect the devices), but if you've had the same problem with the shield connection, which I don't think uses the I2C bus, then I'm not sure.

ku3i commented 7 months ago

maybe your time interval of 500 ms is too long. see https://github.com/arduino-libraries/Arduino_MKRGPS/issues/35

GPS.available() calls poll(), which is only reading 1 byte off the stream per call.