Basically I am doing project on GPS enabling. So in that I have to code such that GPOS signals are not there so you should jump into GLONASS. i have made code which is showing GPS is ok on LCD when gps is giving signals. And when GPS signals are not there it is showing GPS: invalid. This process is automatic and decide itself once signals route through module. Now inbetween part is that time when It shows GPS invalid, at that moment I want to send these bytes and it would enable other system to route signals. Once I insert this bytes in loop upon condition which is if (token==‘V’)
These bytes are sent and sent again and again because of which my GPS module wont work. Thts why I want to make this code reliable in way such that If It enables then it wont repeat this step again.
Kindly help me I have no other solution
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Choose two Arduino pins to use for software serial
int RXPin = 6;
int TXPin = 7;
//Default baud of NEO-6M is 9600
int GPSBaud = 9600;
// Create a software serial port called "gpsSerial"
SoftwareSerial gpsSerial(RXPin, TXPin);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define MAX_NMEA 200 // Max characters in NMEA Sentence to accumulate
float gpsSpeed;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void processGGA(char *nmea)
{
// TODO
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void processGLL(char *nmea)
{
// TODO
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// $GPRMC,144326.00,A,5107.0017737,N,11402.3291611,W,0.080,323.3,210307,0.0,E,A*20
// $GPRMC,
// 0 144326.00 Time
// 1 A Fix A=OK, V=INVALID
// 2 5107.0017737 Lat
// 3 N
// 4 11402.3291611 Lon
// 5 W
// 6 0.080 Speed
// 7 323.3 Course
// 8 210307 Date
// 9 0.0
// 10 E
// 11 A
// *20
void processRMC(char *nmea)
{
char *token = strtok(nmea, ","); // Split NMEA string with ',' delimiter
if (token) // Is Token NULL?
{
int i;
for(i=0; i<7; i++) // Process Fields, truncated
{
token = strtok(NULL, (i < 11) ? "," : "*"); // delimit based on expected termination
if (!token) break; // NULL Token
if (i == 1) // Field 1 Fix
{
if (token[0] == 'A')
{ lcd.clear();
lcd.setCursor(0,0);
lcd.print("GPS:OK");
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
else if (token[0] == 'V')
{
lcd.setCursor(0,0);
lcd.print("GPS:INVALID");
digitalWrite(8, HIGH);
delay(7000);
uint8_t ubx_cfg_gnss[] = {
0xB5,0x62,0x06,0x3E,0x2C,0x00, // UBX-CFG-GNSS
0x00,0x00,0x10,0x05, // 16-Channels, 5-Constellations in list
0x00,0x08,0x10,0x00,0x01,0x00,0x01,0x01, // GPS
0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x01, // SBAS
0x03,0x08,0x10,0x00,0x00,0x00,0x01,0x01, // GALILEO
0x05,0x00,0x03,0x00,0x00,0x00,0x01,0x01, // BEIDOU
0x06,0x08,0x0E,0x00,0x00,0x00,0x01,0x01, // GLONASS
0xE8,0xFE }; // compute checksum
Serial.write(ubx_cfg_gnss,sizeof(ubx_cfg_gnss));
digitalWrite(8, LOW);
lcd.setCursor(0,0);
lcd.print("GPS:gone");
delay(100000);
}
if (i == 6) // Field 6 Speed Knots (Basically a Nautical Mile, or One Arc Minute)
{ gpsSpeed = atof(token) / (3600.0 / 1852.0); // Pull as a floating point (in knots, convert to m/s)
}
}
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void readSerialGPS()
{
static char receivedGPSChars[MAX_NMEA]; // buffer for received GPS data
static int ndx = 0; // buffer index
static boolean newGPSData = false;
while((gpsSerial.available() > 0) && (newGPSData == false)) // Drop out at each complete line
{
char rc = gpsSerial.read();
Serial.write(rc); // Feed byte from GPS to the console
if (rc != '\r') { // Terminate line, CR,LF pair
if (rc == '
) // Resync on leading ’
ndx = 0;
if (rc != '\n') // Don't copy LF
receivedGPSChars[ndx++] = rc;
if (ndx >= MAX_NMEA) // Constrain length
ndx = MAX_NMEA - 1;
}
else { // '\r'
receivedGPSChars[ndx] = '\0'; // Terminate the string
ndx = 0;
newGPSData = true;
}
} // while
if (newGPSData) // One new line available
{
static boolean gpsAlert = false;
if (gpsAlert == false)
{
lcd.setCursor(0,0);
lcd.print("GPS:ENABLED");
gpsAlert = true;
}
if (strncmp(receivedGPSChars, "$GPGGA", 6) == 0)
processGGA(receivedGPSChars);
else if (strncmp(receivedGPSChars, "$GPGLL", 6) == 0)
processGLL(receivedGPSChars);
else if (strncmp(receivedGPSChars, "$GPRMC", 6) == 0)
processRMC(receivedGPSChars);
newGPSData = false;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
// Start the Arduino hardware serial port at 9600 baud
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(9, OUTPUT);
// Start the software serial port at the GPS's default baud
gpsSerial.begin(GPSBaud);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
readSerialGPS(); // Consume data, process sentences
}