SlashDevin / NeoGPS

NMEA and ublox GPS parser for Arduino, configurable to use as few as 10 bytes of RAM
GNU General Public License v3.0
702 stars 195 forks source link

Can't implement NMEA example in another class #132

Open MauriceChocoSwiss opened 4 years ago

MauriceChocoSwiss commented 4 years ago

Hi, i try to get a simple data location, the example NMEASimple work fine, i get position. But when i wan't to use in an another class than .ino file and call in in the main loop, it didn't work. I use AltSoftSerial to connect to my GPS.

Here is my code

GPS.h

#include <AltSoftSerial.h>

class GPS{
public:
    GPS();
    void GetGPSData();
    void gpsBegin();
private:
    AltSoftSerial gpsSerial;
};

GPS.cpp

GPS::GPS() : gpsSerial(52, 53)
{

}

void GPS::gpsBegin()
{
    gpsSerial.begin(9600);
}

void GPS::GetGPSData()
{
    while (gps.available(gpsSerial)) {

            fix = gps.read();

            Serial.print("Gps en vue : ");
            Serial.print(fix.satellites);
            Serial.print(F("Location: "));
            if (fix.valid.location) {
                Serial.print(fix.latitude(), 6);
                Serial.print(',');
                Serial.print(fix.longitude(), 6);
            }

            Serial.print(F(", Altitude: "));
            if (fix.valid.altitude)
                Serial.print(fix.altitude());

            Serial.println();
    }
}

Main file is to long but i'll simplify here

#include "GPS.h"
...

GPS gpsData;

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

}

void loop()
{
        gpsData.GetGPSData();
}

Like i say, the code in GPS.cpp work fine if i put it in the main loop... I try to check if gpsSerial is available before read, it work, but no gps informations...

Thank you for your help