tinyGPS - GPRMB

Hello,

How can we add to the tinyGPS library the $GPRMB sentence ?

$GPRMB,A,0.66,L,003,004,4917.24,N,12309.57,W,001.3,052.5,000.5,V*20

I would like to extract the L or R (after the third comma in the string) information to turn a pin (exemple : 9 if R and 8 if L) on HIGH or LOW state.

Or maybe just parse the information from the println to keep only the L or R info into a valriable, then turn on the LED

Thanks,

How can we add to the tinyGPS library the $GPRMB sentence ?

Typically, using a text editor. What have you tried?

Here is my code and comments where I think I need help :

#include <SoftwareSerial.h>

#include <TinyGPS.h>

/* This project is from the sample code demonstrates the normal use of a TinyGPS object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 3(rx) and 4(tx).
TLL Input, if you are using like me a Garmin RS232 you will have to use a MAX232 I.C to convert the signal.
*/

TinyGPS gps;
SoftwareSerial ss(3, 4);

int ledRIGHT = 8;
int ledLEFT = 9;

void setup()
{
Serial.begin(4800);

pinMode (ledRIGHT, OUTPUT);
pinMode (ledLEFT, OUTPUT);

ss.begin(4800);

Serial.print("GPS Rudder Control using TinyGPS library v. "); Serial.println(TinyGPS::library_version());
Serial.println("by Benoit Campeau - bencampeau@gmail.com");
Serial.println();
}

void loop()
{
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;

// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (ss.available())
{
char c = ss.read();
Serial.write(c); // uncomment this line if you want to see the GPS data flowing
//if (gps.encode(c)) // Did a new valid sentence come in?
//newData = true;
}
}

//if (newData) {

/* startsWith() checks to see if a String starts with a particular substring - DEBUG & TEST:
String stringOne = "$GPRMB";
Serial.println(stringOne);
if (stringOne.startsWith("$GPRMB")) {
Serial.println("GPRMB sentence has been detected");
digitalWrite(ledRIGHT, HIGH); // turn the LED HIGH WHEN GPRMB received
delay(1000); // wait for a second
digitalWrite(ledRIGHT, LOW); // turn the LED LOW until next GPRMB received
}
*/

// you can also look for startsWith() at an offset position in the string:

String stringOne = ss.read; //look to extract the GPRMB sentence, I think I need to set variable but don't know how
//String stringOne = "$GPRMB,V"; //this is my try, that's where I need help :

/* the NMEA sentence received by the GPS look like this :
$GPRMC,225326,V,4553.5498,N,07411.2165,W,20.0,291.1,280813,15.3326,V,S56
$GPBOD,246.1,T,261.4,M,063,062
46
$GPVTG,291.1,T,306.4,M,20.0,N,37.0,K42
$PGRME,15.0,M,22.5,M,27.0,M
1A
$PGRMZ,860,f,315
$PGRMM,NAD27 Canada
2F
$GPWPL,4640.6628,N,07503.5447,W,0586B
$GPRMC,225328,V,4553.5538,N,07411.2313,W,20.0,291.1,280813,15.3,W,S
10
$GPRMB,V,9.99,R,062,063,4637.3135,N,07503.9426,W,57.052,320.2,17.5,V,S55
$GPGGA,225328,4553.5538,N,07411.2313,W,8,10,2.0,262.1,M,-33.3,M,,73
$GPGSA,A,3,02,04,05,10,12,13,17,23,25,29,,,3.6,2.0,3.0
3E
$GPGSV,3,2,10,12,35,244,45,13,26,063,43,17,10,137,37,23,14,038,39
78
$GPGLL,4553.5538,N,07411.2313,W,225328,V,S50
$GPBOD,246.1,T,261.4,M,063,062
46
$GPVTG,291.1,T,306.4,M,20.0,N,37.0,K42
$PGRME,15.0,M,22.5,M,27.0,M
1A
$PGRMZ,860,f,315
$PGRMM,NAD27 Canada
2F
$GPWPL,4639.1135,N,07504.1523,W,059*68

I am trying to extract the $GPRMB line, maybe the startsWith is not the good fonction for this application, thanks for your help

*/

Serial.println();
Serial.println();
Serial.println(stringOne);
Serial.println();
Serial.println();

if (stringOne.startsWith("$GPRMB")) {
Serial.println("RUDDER TURN TO THE LEFT"); //extract the GPRMB car 14 L or R
digitalWrite(ledRIGHT, LOW); // turn the LED RIGHT LOW when boat turn to the left
digitalWrite(ledLEFT, HIGH); // turn the LED HIGH WHEN when boat turn to the left
}

else
(stringOne.startsWith("$GPRMB")); { //extract the GPRMB car 14 L or R
Serial.println("RUDDER TURN TO THE RIGHT");
digitalWrite(ledLEFT, LOW); // turn the LED LEFT LOW WHEN when boat need turn to the right
digitalWrite(ledRIGHT, HIGH); // turn the LED RIGHT HIGH when boat need turn to the right
}

delay(1000); // would like to wait for a second before the next correction

// } //end of if newdata

} //end of void

If I may make a suggestion - read the pinned header about how to use the forum.

If you place your code within code tags, it makes it easier to see what is code, and what is output.

I might be wrong, but I think the TinyGPS library doesn't parse the #GPRMB sentence.

Your best bet is to go to the TinyGPS site and ask Mikal himself how this needs to be extracted. It will probably involve changing the library itself... He is busy building a new library, More on that is at the bottom where you can leave questions...

String stringOne = ss.read;

Why are you trying to store a function pointer in a String? This is NOT calling the function, which does not return a String anyway.

Your best bet is to go to the TinyGPS site and ask Mikal himself how this needs to be extracted.

While that might work, you can also look at the source code for TinyGPS and add support for the GPRMB sentence yourself. It's not that difficult.

But, forget about the String class or any functions in the class. That is NOT how TinyGPS expects input or how it extracts data from the GPS sentence(s).

Thanks to all for your replies !

I'm newbee with Arduino and programation languange, so I have a lot to learn.

Any of you have a idea how I can add the GPRMB sentence to the tinyGPS library ?
As you told me, I have contacted Mikal about that, but maybe one of you can help too.

Thanks,