Hello!
I recently got a MKR GPS shield and have been playing around with it. When I upload code, I get the correct output, (lat, long, speed, altitude, satellites,) but I cannot get heading/variation working.
The shield is connected via the I2C cable
Code:
/*
GPS Location
This sketch uses the GPS to determine the location of the board
and prints it to the Serial monitor.
Circuit:
- MKR board
- MKR GPS attached via I2C cable
This example code is in the public domain.
*/
#include <Arduino_MKRGPS.h>
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// If you are using the MKR GPS as shield, change the next line to pass
// the GPS_MODE_SHIELD parameter to the GPS.begin(...)
if (!GPS.begin()) {
Serial.println("Failed to initialize GPS!");
while (1);
}
Serial.println("Aquiring satellites...");
}
void loop() {
// check if there is new GPS data available
if (GPS.available()) {
// read GPS values
float latitude = GPS.latitude();
float longitude = GPS.longitude();
float altitude = GPS.altitude();
float speed = GPS.speed();
int satellites = GPS.satellites();
float crs = GPS.course();
float var = GPS.variation();
// print GPS values
Serial.print("course: ");
Serial.println(crs, 20);
Serial.print("Variation: ");
Serial.println(var, 20);
Serial.print("Location: ");
Serial.print(latitude, 20);
Serial.print(", ");
Serial.println(longitude, 20);
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.println();
}
}
Output:
course: nan
Variation: nan
Location: *my location*
Altitude: 124.90m
Ground speed: 0.08 km/h
Number of satellites: 9
course: nan
Variation: nan
Location: *my location*
Altitude: 124.60m
Ground speed: 0.14 km/h
Number of satellites: 9
Does anyone know why this is happening?
Thanks!