I have ZEDF9P AND ARDUINO and connected them Via UART. I have programmed it such that GNSS receiver won't see GPS it give GPS: INVALID on LCD and switch to some other system. But my problem is that I am unable to write code for the time once GLONASS is enabled. I want that once I switch on another system The system name should come on LCD automatically but I don't know where the code is wrong. Kindly help me with the code. (I am doing it with NEO6M as well so kindly ignore baudrate)
#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 GPSENABLE 2
byte GPSBuffer[82];
byte GPSIndex=0;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#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
{
lcd.clear();
lcd.setCursor(0,0);
if (token[0] == 'A')
{ lcd.print("GPS:OK");
digitalWrite(9, HIGH);
digitalWrite(8, LOW);}
else if (token[0] == 'V')
{delay(100);
lcd.print("GPS:INVALID");
for (int i = 0; i <= 100; i++) {
digitalWrite(8, HIGH);
delay(100);
digitalWrite(8, LOW);
delay(100);
};
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));
}
else
lcd.print("GPS:UNKNOWN");
}
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 loop1()
{
CheckGPS();
}
void CheckGPS()
{
int inByte;
while (gpsSerial.available() > 0)
{
inByte = gpsSerial.read();
if ((inByte =='
) || (GPSIndex >= 80))
{
GPSIndex = 0;
}
if (inByte != '\r')
{
GPSBuffer[GPSIndex++] = inByte;
}
if (inByte == '\n')
{
ProcessGPSLine();
GPSIndex = 0;
}
}
}
void ProcessGPSLine()
{
if ((GPSBuffer[1] == 'G') && (GPSBuffer[2] == 'L') && (GPSBuffer[3] == 'G') && (GPSBuffer[4] == 'G') && (GPSBuffer[5] == 'A'))
{
lcd.print("GLGGA Detected!");
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////