I’ve connected a GPS antenna to my laptop. With several attempts to troubleshoot the code,
It appears the issue is within serialEvent(), and/or my parsing structure.
If I print(inString); to the console, I can see the entire message block. When the string is
split into the array, I’m only seeing 8 elements, and primarily $GPGLL header 95% of the time. Why is this?
Thank you in advance for pointing me in the right direction!
My code is below and here is the data read into processing, and the latter is parsed into
the array:
read into inStringGPS variable:
$GPRMC,030557.00,A,4355.94375,N,07859.68041,W,0.360,060320,A67
$GPVTG,T,M,0.360,N,0.666,K,A20
$GPGGA,030557.00,4355.94375,N,07859.68041,W,1,08,1.15,151.0,M,-35.9,M,63
$GPGSA,A,3,02,06,12,19,17,05,23,04,2.00,1.15,1.640F
$GPGSV,3,1,12,02,67,290,30,04,13,053,24,05,27,201,22,06,67,040,3375
$GPGSV,3,2,12,09,20,086,18,12,50,280,31,17,29,116,27,19,48,109,3179
$GPGSV,3,3,12,23,15,057,19,25,24,313,07,46,19,240,51,32,218,70
$GPGLL,4355.94375,N,07859.68041,W,030557.00,A,A7C
split into gpsData array:
[0] “$GPGLL”
[1] “4355.94696”
[2] “N”
[3] “07859.67775”
[4] “W”
[5] “024134.00”
[6] “A”
[7] "A*7F
import processing.serial.*;
Serial gpsPort, numsPort;int gpsHeading, gpsAltitude;
String gpsData = new String[215]; //65
String numsData = new String[15];
String inStringNums, inStringGPS;void setup() {
fullScreen(SPAN);
background(0);
// numsPort = new Serial(this, Serial.list()[1], 115200);
// numsPort.bufferUntil(‘\n’);gpsPort = new Serial(this, Serial.list()[0], 9600);
gpsPort.bufferUntil(10); //‘\n’delay(500);
}void draw() {
background(0);
// inStringGPS = gpsPort.readString();gpsData = split(inStringGPS, ‘,’);
String block = gpsData[0];
String str2 = “$GPVTG”, str3 = “$GPRMC”;if (str2.equals(block) == true){ // $GPVTG
float gpsData2 = float(split(inStringGPS, ‘,’));
gpsHeading = int(gpsData2[1]); //TRUE
}if (str3.equals(block) == true){ // $GPRMC
float gpsData2 = float(split(inStringGPS, ‘,’));
gpsHeading = int(gpsData2[8]); //TRUE
}text(gpsHeading, 40, 40);
print(inStringGPS); // for troubleshooting
printArray(gpsData);
}void serialEvent(Serial xCOM){
if(xCOM == gpsPort) inStringGPS = xCOM.readString(); //move to draw function?
// if(xCOM == numsPort) inString = xCOM.readString();
}