I'm having some trouble configuring my EM-406A to output. About half of the time, the output is just junk. I have 3+ satellites in view, have tried all sorts of different baud rates, and searched all over and can't seem to figure it out. Here's some example output:
Current GPS: 2911.3540,08102.7931
Current GPS: ,,*1.3540,08102.7931
Current GPS: 2911.3528,08102.7938
Current GPS: 179,14,09,,044,15,24
Current GPS: 179,14,09,,044,15,24
Current GPS: 22,30,27,,12,,,,,,,3
Current GPS: 2911.3511,08102.7968
As you can see, the first, third and last are the only correct outputs. Here's the code I'm using on the Mega:
byteGPS = 0;i = 0;while(byteGPS != 42) { // read the GGA sentencebyteGPS = mySerial.read();inBuffer[i]=byteGPS;i++;}k = 1;m1 = 0;m2 = 0;while(inBuffer[k] != 42) {k++;if(k > 17 && k < 27) {//Serial.print(inBuffer[k]); // write the GGA sentencecurrentGPSlat[m1] = inBuffer[k];m1++;}if(k > 29 && k < 40) {//Serial.print(inBuffer[k]); // write the GGA sentencecurrentGPSlong[m2] = inBuffer[k];m2++;}
Even when I'm just outputing the NMEA string, I get either a bunch of commas, or junk in general.
Any troubleshooting advice would be appriciated!
Replies
I think I have the same issue as John. My 406a was giving me the same garbage ( binary ) fresh out of the box.
John did you ever get this working with "putting-your-em406-gps-back-in" ?
NB: the delivery of my GPS took about 3 days... So unless they set it to binary at the suppliers before shipping I dont know what to say...
thanks!
mac
You don't check the checksum. You would not know if a character was dropped or inserted or flipped a bit.
You never check to see if the message is valid.
You never check to see if the message is in fact GGA. What if the GPS sends another message?
You set k=1, then loop until k>17. Why waste those cycles? Start k at 18.
You assume that the data will be exactly at position 18 to 26. What if the field size ever grew/shrank? What if a character was ever dropped or inserted? What if a field was invalid and empty?
You waste loops until k >29. Why waste those cycles? Bump k up to 30.
You assume that the data will be exactly at position 30 to 39. What if the field size ever grew/shrank? What if a character was ever dropped or inserted? What if a field was invalid and empty?
Read through your buffer to ensure you have GGA. Read until you get a comma. End of first field. Read until you get a comma. End of second field. Etc.
1. With 3 sats you can't get a GPS position unless you've entered a manual altitude.
2. The series of commas: ,,,,, is showing you that the values between those commas is invalid / null.
3. does mySerial.read(); check serial available? You realize that you should check that first, right? And watch for -1 inputs anyway?
I'm assuming that your parsing in mySerial.read is skipping (or trying to) everything except GGA? (I think you are letting other message data past.) And you are confirming the checksum? You might make sure that that routine is more fault tolerant. Never, ever, trust inputs coming from somewhere else.
The EM406 is not in binary mode. It is blinking red as soon as it locks.