I am new in Arduino ,
I want to take NMEA sentence from the GPS and parse them with the code below.
How can I print the parsed sentence argument in serial monitor? what I am doing wrong.
Please help.
#include <AltSoftSerial.h>
#include <Wire.h>
#include <NMEA0183.h>
#include <NMEAParser.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// matches Zihatec RS422/RS485 shield
AltSoftSerial gps;
NMEA0183 nmea;
NMEAParser<4> parser;
float gprmc;
float gprmb;
void handleGPRMC(void)
{
float test;
if (parser.getArg(4, test))
{
gprmc = test;
Serial.print(gprmc);
}
}
void handleGPRMB(void)
{
float test1;
if (parser.getArg(4, test1))
{
gprmb = test1;
Serial.print(gprmb);
}
}
void setup() {
Serial.begin(4800);
gps.begin(4800);
Serial.println("AltSoftSerial Test Begin");
// Start Serial
while (!Serial);
Serial.println("NMEA0183 parser test");
// Start LCD
lcd.begin();
lcd.backlight();
parser.addHandler("GPRMB", handleGPRMB);
parser.addHandler("GPRMC", handleGPRMC);
}
void loop()
// Reveive data from GPS
{
lcd.setCursor(0,0);
if (gps.available())
{
char c = gps.read();
if (nmea.update(c))
{
Serial.print("NMEA0183 sentence accepted (");
Serial.print(nmea.getFields());
Serial.print(" fields): ");
Serial.write(nmea.getSentence());
Serial.println();
// Display Data from GPS
lcd.clear();//Clean the screen
lcd.setCursor(0,0);
lcd.print(nmea.getFields());
lcd.setCursor(3,0);
lcd.print(" data received ");
lcd.setCursor(0,1);
lcd.print(nmea.getSentence());
// if (Serial.available()) {
parser << Serial.read();
// }
}
}
}
and the following input:
22:05:02.341 -> NMEA0183 sentence accepted (12 fields): $GPRMC,190502,A,3645.4300,N,03432.8414,E,0.0,101.6,051020,4.1,E,A1D
22:05:02.687 -> NMEA0183 sentence accepted (14 fields): $GPRMB,A,0.00,R,26. SK.,26 SK,3645.4357,N,03432.8447,E,0.007,23.8,,V,A5D
22:05:03.125 -> NMEA0183 sentence accepted (6 fields): $GPBOD,11.3,T,7.3,M,26. SK.,26. SK.70
22:05:03.261 -> NMEA0183 sentence accepted (6 fields): $PGRME,17.0,M,10.9,M,21.6,M15
22:05:03.404 -> NMEA0183 sentence accepted (3 fields): $PGRMZ,16,f,32C
22:05:03.540 -> NMEA0183 sentence accepted (1 fields): $PGRMM,WGS 8406
22:05:04.321 -> NMEA0183 sentence accepted (12 fields): $GPRMC,190504,A,3645.4303,N,03432.8412,E,0.0,101.6,051020,4.1,E,A*1E