GPS Module Commands (Smart Mode)
For some reason for which I can't figure out, the demo program written for the GPS module works and the brief code that I wrote to just·find altitude does not.
I'm just using the SEROUT, SERIN commands and the data I get back is not accurate.
What's the trick?
I'm just using the SEROUT, SERIN commands and the data I get back is not accurate.
What's the trick?

Comments
You should post your code to get better help.
How inaccurate are the data? GPS altitude is notoriously inaccurate.
SEROUT Sio, Baud, [noparse][[/noparse]"!GPS", GetAlt]
SERIN Sio, Baud, 3000, noResponse, [noparse][[/noparse]token.HIGHBYTE, token.LOWBYTE]
PAUSE 500
DEBUG token
I've verified that the 'token' variable is a WORD.
The altitude is way off.· I'm at about 125 m and it gives me about 3000 m.··And again,·if I run the demo·program downloaded from the web, the reading is accurate.
Thanks!·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Duffer
·
Been there, done that.
Jim
It's definitely something quirky with my program or the Stamp BS2.· Get this, if I delete a PAUSE 500 line, the altitude and satellite numbers·become accurate!··Theoretically the line·should have nothing to do with this issue.
Any idea what's going on here?
' {$STAMP BS2} ' {$PBASIC 2.5} 'Test compass and GPS receiver test plate token VAR Word line VAR Byte alt VAR Word sats VAR Byte tPin PIN 0 fPin PIN 1 Sio PIN 12 T4800 CON 188 Open CON $8000 Baud CON Open | T4800 ' Open mode to allow daisy chaining ' GPS Module Commands GetInfo CON $00 GetValid CON $01 GetSats CON $02 GetTime CON $03 GetDate CON $04 GetLat CON $05 GetLong CON $06 GetAlt CON $07 GetSpeed CON $08 GetHead CON $09 DO GOSUB Get_Valid GOSUB Get_Alt GOSUB Get_Sats LOOP Get_Valid: line = 1 SEROUT Sio, 188, [noparse][[/noparse]"!GPS", GetValid] SERIN Sio, 188, 3000, noResponse, [noparse][[/noparse]token] SEROUT tPin\fPin, 16468, [noparse][[/noparse]"XYZ", DEC line, CR, DEC token, CR] [b] 'PAUSE 500 <--- if I omit this line, all readings are reasonably accurate. 'if I run this line, alt and sats values are way off![/b] RETURN Get_Alt: line = 2 SEROUT Sio, 188, [noparse][[/noparse]"!GPS", GetAlt] SERIN Sio, 188, 3000, noResponse, [noparse][[/noparse]alt.HIGHBYTE, alt.LOWBYTE] SEROUT tPin\fPin, 16468, [noparse][[/noparse]"XYZ", DEC line, CR, DEC alt, CR] PAUSE 500 RETURN Get_Sats: line = 3 SEROUT Sio, 188, [noparse][[/noparse]"!GPS", GetSats] SERIN Sio, 188, 3000, noResponse, [noparse][[/noparse]sats] SEROUT tPin\fPin, 16468, [noparse][[/noparse]"XYZ", DEC line, CR, DEC sats, CR] RETURN noResponse: RETURNUntil Valid is 1 (true), the number of Sats and altitude are zero and garbage respectively.
GPS Startup - Valid = False
$GPGGA,000056,,N,,E,0,00,,,M,,M,,*6E<CR><LF>
$GPRMC,000056,V,,N,,E,,,010303,,,N*5A<CR><LF>
Sats fixed - Valid = True
$GPGGA,013620,4034.8983,N,07439.6939,W,1,04,04.0,00039.2,M,-034.0,M,,*71<CR><LF>
$GPRMC,013620,A,4034.8983,N,07439.6939,W,000.0,000.0,271109,,,A*6D<CR><LF>
The NMEA sentences above represent what the SX processor is parsing from the GPS module in Smart mode(the GSA and GSV sentences are ignored by Smart mode).
Notice that while Valid is false (second field in RMC sentence is "V"), the number of sats (7th field in GGA sentence) is "00" and the Altitude (the 9th field in GGA sentence) is null, The parser counts commas to locate a field and then reads a number of bytes of what it thinks is valid data. In the case of·Altitude, before a valid fix, the parser would read garbage (",M,,M" instead of "00039.2 in the "valid" GGA sentence).
Contrast that to the GGA and RMC sentences when Valid (second field in RMC = "A").
You could try something like:
This would continue to test for a valid signal at 2 second intervals until a valid signal was acquired (the red LED on the GPS is on solid when the GPS unit has a fix). Untill Valid is true, all data from the GPS is suspect. That's why the demo program·for Smart mode checks for Valid and if it's not, it outputs "?" to all the fields and tries again.
Duffer
Post Edited (Duffer) : 1/2/2010 3:22:28 AM GMT
Duffer
' {$STAMP BS2p} ' {$PBASIC 2.5} 'Test compass and GPS receiver test plate token VAR Word line VAR Byte alt VAR Word sats VAR Byte tPin PIN 0 fPin PIN 1 Sio PIN 12 T4800 CON 188 Open CON $8000 Baud CON Open | T4800 ' Open mode to allow daisy chaining ' GPS Module Commands GetInfo CON $00 GetValid CON $01 GetSats CON $02 GetTime CON $03 GetDate CON $04 GetLat CON $05 GetLong CON $06 GetAlt CON $07 GetSpeed CON $08 GetHead CON $09 DO GOSUB Get_Valid IF(token) THEN 'token (Valid) = 1 or bolean true GOSUB Get_Alt GOSUB Get_Sats PAUSE 1000 'GPS data rate is 1Hz. No point in checking more often ELSE DEBUG CR PAUSE 2000 ENDIF LOOP Get_Valid: line = 1 SEROUT Sio, 500, [noparse][[/noparse]"!GPS", GetValid] SERIN Sio, 500, 3000, noResponse, [noparse][[/noparse]token] DEBUG "Valid=", DEC token, " " 'PAUSE 500 <--- if I omit this line, all readings are reasonably accurate. 'if I run this line, alt and sats values are way off! RETURN Get_Alt: line = 2 SEROUT Sio, 500, [noparse][[/noparse]"!GPS", GetAlt] SERIN Sio, 500, 3000, noResponse, [noparse][[/noparse]alt.HIGHBYTE, alt.LOWBYTE] DEBUG "Alt=",DEC alt," " 'PAUSE 500 RETURN Get_Sats: line = 3 SEROUT Sio, 500, [noparse][[/noparse]"!GPS", GetSats] SERIN Sio, 500, 3000, noResponse, [noparse][[/noparse]sats] DEBUG "Sats=",DEC sats, CR RETURN noResponse: RETURN