NeoGPS icon indicating copy to clipboard operation
NeoGPS copied to clipboard

Can't implement NMEA example in another class

Open MauriceChocoSwiss opened this issue 6 years ago • 0 comments

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

MauriceChocoSwiss avatar Dec 28 '19 07:12 MauriceChocoSwiss