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,06246
$GPVTG,291.1,T,306.4,M,20.0,N,37.0,K42
$PGRME,15.0,M,22.5,M,27.0,M1A
$PGRMZ,860,f,315
$PGRMM,NAD27 Canada2F
$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,S10
$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.03E
$GPGSV,3,2,10,12,35,244,45,13,26,063,43,17,10,137,37,23,14,038,3978
$GPGLL,4553.5538,N,07411.2313,W,225328,V,S50
$GPBOD,246.1,T,261.4,M,063,06246
$GPVTG,291.1,T,306.4,M,20.0,N,37.0,K42
$PGRME,15.0,M,22.5,M,27.0,M1A
$PGRMZ,860,f,315
$PGRMM,NAD27 Canada2F
$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