Go Down

Topic: MKR GPS .available() always 0. (Read 413 times) previous topic - next topic

indyvc

Mar 22, 2020, 12:54 pm Last Edit: Mar 22, 2020, 01:24 pm by indyvc
Hello everyone, I have a problem that I am struggling for some days.

I have an MKR GSM board with an MKR GPS Shield attachted to it with an I2C cable. When I run the code example, it NEVER gets passed the GPS.availbale. I have tried other cables, other USB slots and other computers. What can be the problem in this case...? There was once that the same script worked, but now I can't get it working.


Code: [Select]

/*
  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);
  }
}

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();

    // print GPS values
    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.println();
  }
}



mstepanek1976

Did you ever get anywhere with this? I think I'm facing effectively the same issue. Just wait longer (as I've read elsewhere)? I'm running the GPSLocationStandby example. It seems to initialize fine, but it is forever waiting for a location available. I haven't dug into it much more yet. I have tried it outside. Even waited about a half hour. Nothing. Any debug suggestions?

MKR WiFi 1010
MKR GPS shield - connected via I2C cable
USB power from laptop (no battery on 1010)
No battery on GPS shield
(Also have ENV shield attached simultaneously; runs with no issues)

mstepanek1976

FWIW, I had some success today (just to close out my query to this thread). With the ENV shield removed, I'm able to get location on the GPS (within a few minutes; fairly accurate). I will start a separate thread about the 2 shields.

philipdbrown

mstepanek1976,
I'm having an issue with just getting my MKR GPS shield working.  I have a similar setup as you with the MKR WiFi 1010 and the MKR GPS Shield connected via I2C cable.  I've tried the GPS Shield with and without a battery and am using GPS.begin(GPS_MODE_I2C), which returns 1.  However, GPS.available() always returns 0. (Using the Arduino_MKRGPS library.)  I'd love to see what you did to get yours working.

mstepanek1976

I'm trying to remember what my conclusions were there (I think I posted them in another thread). I think it was along the lines of "it just likes you to talk to it a lot". :) I think my solution was to not bother with using standby mode... and then call available() a lot. I think the examples call it in a tight loop (no delays). I think my solution just did a 1ms delay... and you get an answer back maybe once a second. If I added more delay, the answers just took longer.

Also, make sure you're trying it outside. :) If you get a prior lock (and you're using the battery on the board), you *might* have luck inside... but best to debug outside. (I eventually implemented a GPS-simulation mode for further development.)

philipdbrown

Thanks mstepanek1976,
I did read that some of the GPS modules take up to 30s to "heat up".  There was no definition for "heat up". To me, it means wait a while.  
Ok, cool, the onboard battery will keep a lock.  Perfect.  Yeah, I was going outside, but it started to rain.  I'll build out the code more and just let it sit outside for a while to see what happens.  I do appreciate the feedback.  Have a great week and hope you're killin' it.

mstepanek1976

I'm not a GPS guy, so pardon my butchering of terminology. The startup time is it "syncing up" with some number of minimal satellites before it can give a reliable location. Yeah, 30 seconds is about the right timeframe. On clear days with no buildings around, I've seen it go much faster. I've also seen people say a few minutes... so who knows... but something like that. Definitely want to do it outside though!

The battery, however that works in GPS technology, just lets it get a good location reading on the next bootup (after establishing a good location on the prior boot). I'm sure it has something to do with assuming you're at about the same location, and that probably just lets it calculate location with fewer satellites (initially)... or something to that effect.

philipdbrown

Yeah, I just let it sit, and it is now giving consistent reading.  Indoors!!  I do appreciate the feedback.  Patience is a virtue.   ;)  ;)

Go Up