I am unable to get a connection to GPS satellites when I use the MKR IMU an MKR GPS code at the same time, even after waiting for a fix for 30 min. When I uncomment the IMU functions it works fine, after a minute or so I am able to connect to satellites.
Hardware setup: MKR GPS using I2C cable with clear sky access, MKR IMU shield on top of MKR WIFI 1010.
Working code:
#include <MKRIMU.h>
#include <Arduino_MKRGPS.h>
float x_acceleration = 0;
float y_acceleration = 0;
float z_acceleration = 0;
float x_gyroscope = 0;
float y_gyroscope = 0;
float z_gyroscope = 0;
float x_euler = 0;
float y_euler = 0;
float z_euler = 0;
float x_magneticfield = 0;
float y_magneticfield = 0;
float z_magneticfield = 0;
float latitude = 0;
float longitude = 0;
float altitude = 0;
float speed = 0;
int satellites = 0;
unsigned long start;
void setup() {
Serial.begin(9600);
while (!Serial);
// if (!IMU.begin()) {
// Serial.println("Failed to initialize IMU!");
// while (1);
// }
if (!GPS.begin()) {
Serial.println("Failed to initialize GPS!");
while (1);
}
}
void loop() {
start = micros();
// if (IMU.accelerationAvailable()) {
// IMU.readAcceleration(x_acceleration, y_acceleration, z_acceleration);
// }
// if (IMU.gyroscopeAvailable()) {
// IMU.readGyroscope(x_gyroscope, y_gyroscope, z_gyroscope);
// }
// if (IMU.eulerAnglesAvailable()) {
// IMU.readEulerAngles(x_euler, y_euler, z_euler);
// }
// if (IMU.magneticFieldAvailable()) {
// IMU.readMagneticField(x_magneticfield, y_magneticfield, z_magneticfield);
// }
if (GPS.available()) {
latitude = GPS.latitude();
longitude = GPS.longitude();
altitude = GPS.altitude();
speed = GPS.speed();
satellites = GPS.satellites();
}
Serial.print("freq:");Serial.print(1E6/(micros()-start));Serial.print(",");
// Serial.print("x_acc:");Serial.print(x_acceleration);Serial.print(",");
// Serial.print("y_acc:");Serial.print(y_acceleration);Serial.print(",");
// Serial.print("z_acc:");Serial.print(z_acceleration);Serial.print(",");
// Serial.print("x_gyro:");Serial.print(x_gyroscope);Serial.print(",");
// Serial.print("y_gyro:");Serial.print(y_gyroscope);Serial.print(",");
// Serial.print("z_gyro:");Serial.print(z_gyroscope);Serial.print(",");
// Serial.print("heading:");Serial.print(x_euler);Serial.print(",");
// Serial.print("roll:");Serial.print(y_euler);Serial.print(",");
// Serial.print("pitch:");Serial.print(z_euler);Serial.print(",");
// Serial.print("x_mag:");Serial.print(x_magneticfield);Serial.print(",");
// Serial.print("y_mag:");Serial.print(y_magneticfield);Serial.print(",");
// Serial.print("z_mag:");Serial.print(z_magneticfield);Serial.print(",");
Serial.print("lat:");Serial.print(latitude);Serial.print(",");
Serial.print("lon:");Serial.print(longitude);Serial.print(",");
Serial.print("alt:");Serial.print(altitude);Serial.print(",");
Serial.print("speed:");Serial.print(speed);Serial.print(",");
Serial.print("sats:");Serial.print(satellites);Serial.println(",");
delay(1000);
}
Not working code:
#include <MKRIMU.h>
#include <Arduino_MKRGPS.h>
float x_acceleration = 0;
float y_acceleration = 0;
float z_acceleration = 0;
float x_gyroscope = 0;
float y_gyroscope = 0;
float z_gyroscope = 0;
float x_euler = 0;
float y_euler = 0;
float z_euler = 0;
float x_magneticfield = 0;
float y_magneticfield = 0;
float z_magneticfield = 0;
float latitude = 0;
float longitude = 0;
float altitude = 0;
float speed = 0;
int satellites = 0;
unsigned long start;
void setup() {
Serial.begin(9600);
while (!Serial);
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
if (!GPS.begin()) {
Serial.println("Failed to initialize GPS!");
while (1);
}
}
void loop() {
start = micros();
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(x_acceleration, y_acceleration, z_acceleration);
}
if (IMU.gyroscopeAvailable()) {
IMU.readGyroscope(x_gyroscope, y_gyroscope, z_gyroscope);
}
if (IMU.eulerAnglesAvailable()) {
IMU.readEulerAngles(x_euler, y_euler, z_euler);
}
if (IMU.magneticFieldAvailable()) {
IMU.readMagneticField(x_magneticfield, y_magneticfield, z_magneticfield);
}
if (GPS.available()) {
latitude = GPS.latitude();
longitude = GPS.longitude();
altitude = GPS.altitude();
speed = GPS.speed();
satellites = GPS.satellites();
}
Serial.print("freq:");Serial.print(1E6/(micros()-start));Serial.print(",");
Serial.print("x_acc:");Serial.print(x_acceleration);Serial.print(",");
Serial.print("y_acc:");Serial.print(y_acceleration);Serial.print(",");
Serial.print("z_acc:");Serial.print(z_acceleration);Serial.print(",");
Serial.print("x_gyro:");Serial.print(x_gyroscope);Serial.print(",");
Serial.print("y_gyro:");Serial.print(y_gyroscope);Serial.print(",");
Serial.print("z_gyro:");Serial.print(z_gyroscope);Serial.print(",");
Serial.print("heading:");Serial.print(x_euler);Serial.print(",");
Serial.print("roll:");Serial.print(y_euler);Serial.print(",");
Serial.print("pitch:");Serial.print(z_euler);Serial.print(",");
Serial.print("x_mag:");Serial.print(x_magneticfield);Serial.print(",");
Serial.print("y_mag:");Serial.print(y_magneticfield);Serial.print(",");
Serial.print("z_mag:");Serial.print(z_magneticfield);Serial.print(",");
Serial.print("lat:");Serial.print(latitude);Serial.print(",");
Serial.print("lon:");Serial.print(longitude);Serial.print(",");
Serial.print("alt:");Serial.print(altitude);Serial.print(",");
Serial.print("speed:");Serial.print(speed);Serial.print(",");
Serial.print("sats:");Serial.print(satellites);Serial.println(",");
delay(1000);
}