sidwarkd / gp20u7_arduino

A simple Arduino library for the GP20U7 GPS unit
4 stars 5 forks source link

Cannot read data from GPS-module #4

Closed FinnAlberts closed 3 years ago

FinnAlberts commented 3 years ago

Hi there,

I'm currently trying to read the GPS-coordinates using the GP20U7, but I don't get any results even after a few minutes. I'm using an Adafruit M0 LoRa. According to https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/pinouts, I should use Serial1 when using RX/0. I also tried Serial and Serial5, but with no luck whatsoever.

The code I'm using:

/*
  GP20U7 GPS Library - Basic
 Demonstrates the use of the GP20U7 GPS unit by retrieving the latitude
 and longitude of your current position.

 The circuit:
 * GP20U7 TX pin to digital pin 0/RX
 * GP20U7 VCC pin to 3.3V
 * GP20U7 GND pin to ground

 NOTE: The GPS unit can take up to a minute or more to acquire a position
 lock and start outputting data. That means you may not see the serial
 output right away which is normal.

 */

// include the library code:
#include <gp20u7.h>

// initialize the library with the serial port to which the device is
// connected
GP20U7 gps = GP20U7(Serial1);

// Set up a Geolocation variable to track your current Location
Geolocation currentLocation;

void setup() {
  // Start the GPS module
  gps.begin();
}

void loop() {
  // The call to read() checks for new location information and returns 1
  // if new data is available and 0 if it isn't. It should be called
  // repeatedly.
  if(gps.read()){
    currentLocation = gps.getGeolocation();
    Serial.println("Your current location is:");
    Serial.print("    Latitude: ");
    Serial.println(currentLocation.latitude,5);
    Serial.print("    Longitude: ");
    Serial.println(currentLocation.longitude,5);
  }
}

What am I doing wrong?

sidwarkd commented 3 years ago

Based on the docs I definitely agree that Serial1 should be used. Looking at the docs I think the issue might be that you aren't writing to the USB port to get serial output displayed in the terminal. Serial.println goes to Serial5 on the M0. I think you need to change those to SerialUSB.println. See https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/adapting-sketches-to-m0#serial-vs-serialusb-2677093-4 for more info. You may also have to do a SerialUSB.begin() but I can't remember if that is necessary or not. Let me know if that works.

FinnAlberts commented 3 years ago

Thank you for the quick response. I tried completely reinstalling both Arduino, the boards and the library and for some reason that did the trick. Maybe I was accidentally using an outdated version of the library or something. I'll close this issue as the code is working as expected now.

sidwarkd commented 3 years ago

Glad you got it working @FinnAlberts Happy making!