STAMP Project -Parsing NMEA data string
Archiver
Posts: 46,084
First, I am new to not only the STAMP but to PBASIC and any other
code. The idea of this project is to use NMEA sentences parsed into
the stamp, extract the altitude, and set some flags to trigger a
couple pins to turn on a light and alarm. For the purposes of the
project I am simulating the GPS feed using Hyperterminal from a
laptop and using the serial port. I am trying to set the first flag
at 4k m to signal the peak ascent and then having the light come on
at 3k m and the sound at 1k m. I checked the syntax and everything
seems o.k. For the time being I'm just testing with two LEDs but am
not getting the lights to come on or toggle. Below is the code I
wrote along with a sample NMEA sentence. I have the Hperterminal set
up for 4800 bps,7 data bits, even parity, 1 stop bit, and none for
flow control. Line delay is set for 1000 ms.
NMEA sentence:
$GPGGA,22708,333.601,N,8157.192,W,1,8,1.5,165.2,M,-31.7,M,,*7D
The tenth position is the altitude (165.2)
'{$STAMP BS2}
'{$PBASIC 2.5}
'
[noparse][[/noparse]constants]
gpspin con 16
lightpin con 6
soundpin con 15
peakalt con 4000
lightalt con 3000
soundalt con 1000
gpsbaud con 8380
'
[noparse][[/noparse]Variables]
peakflag VAR bit ' if altitude >4000m = 1
lightflag VAR bit ' if altitude <3000m = 1
soundflag VAR bit ' if altitude <1000m = 1
curalt VAR word ' altitude parsed from gps string
'
Initialize
out lightpin = 0
out soundpin = 0
' Main Program
peakalt = 0
lightalt = 0
soundalt=0
curalt=0
DO
SERIN gpspin, gpsbaud,[noparse][[/noparse]Wait("GPGGA,") ,wait (","), wait (","),
wait (","), wait (","), wait (","), wait (","), wait (","), wait
(","), dec curalt] 'parse gps string for alt
IF peakflag = 0 AND curalt > peakalt THEN peakflag = 1
IF peakflag = 1 AND curalt < lightalt THEN TOGGLE lightpin
IF peakflag = 1 AND curalt < soundalt THEN TOGGLE soundpin
IF ENDIF
LOOP
Thanks for any help!
code. The idea of this project is to use NMEA sentences parsed into
the stamp, extract the altitude, and set some flags to trigger a
couple pins to turn on a light and alarm. For the purposes of the
project I am simulating the GPS feed using Hyperterminal from a
laptop and using the serial port. I am trying to set the first flag
at 4k m to signal the peak ascent and then having the light come on
at 3k m and the sound at 1k m. I checked the syntax and everything
seems o.k. For the time being I'm just testing with two LEDs but am
not getting the lights to come on or toggle. Below is the code I
wrote along with a sample NMEA sentence. I have the Hperterminal set
up for 4800 bps,7 data bits, even parity, 1 stop bit, and none for
flow control. Line delay is set for 1000 ms.
NMEA sentence:
$GPGGA,22708,333.601,N,8157.192,W,1,8,1.5,165.2,M,-31.7,M,,*7D
The tenth position is the altitude (165.2)
'{$STAMP BS2}
'{$PBASIC 2.5}
'
[noparse][[/noparse]constants]
gpspin con 16
lightpin con 6
soundpin con 15
peakalt con 4000
lightalt con 3000
soundalt con 1000
gpsbaud con 8380
'
[noparse][[/noparse]Variables]
peakflag VAR bit ' if altitude >4000m = 1
lightflag VAR bit ' if altitude <3000m = 1
soundflag VAR bit ' if altitude <1000m = 1
curalt VAR word ' altitude parsed from gps string
'
Initialize
out lightpin = 0
out soundpin = 0
' Main Program
peakalt = 0
lightalt = 0
soundalt=0
curalt=0
DO
SERIN gpspin, gpsbaud,[noparse][[/noparse]Wait("GPGGA,") ,wait (","), wait (","),
wait (","), wait (","), wait (","), wait (","), wait (","), wait
(","), dec curalt] 'parse gps string for alt
IF peakflag = 0 AND curalt > peakalt THEN peakflag = 1
IF peakflag = 1 AND curalt < lightalt THEN TOGGLE lightpin
IF peakflag = 1 AND curalt < soundalt THEN TOGGLE soundpin
IF ENDIF
LOOP
Thanks for any help!
Comments
modifiers and I think that's going to be problematic. You might
consider a WAIT, then SKIP, then take in enough characters so you catch
the altitude and can parse it out of that.
One of the problems you will have with your HyperTerminal simulation is
that you can only type one character at a time, and the GPS receiver is
going to be sending them at a much steadier clip (hence the problem with
all the WAIT modifiers).
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: freqman1 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=TgT_3W5PtWClVrmvbnon7DOX_-gqJihT4FMlurQ2XYvE3yJiSHJACwa_O_tNBGi3dwNPhI-Z0lYDKeIIei8axXta]shawnsweeney@h...[/url
Sent: Thursday, December 04, 2003 12:37 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] STAMP Project -Parsing NMEA data string
First, I am new to not only the STAMP but to PBASIC and any other
code. The idea of this project is to use NMEA sentences parsed into
the stamp, extract the altitude, and set some flags to trigger a
couple pins to turn on a light and alarm. For the purposes of the
project I am simulating the GPS feed using Hyperterminal from a
laptop and using the serial port. I am trying to set the first flag
at 4k m to signal the peak ascent and then having the light come on
at 3k m and the sound at 1k m. I checked the syntax and everything
seems o.k. For the time being I'm just testing with two LEDs but am
not getting the lights to come on or toggle. Below is the code I
wrote along with a sample NMEA sentence. I have the Hperterminal set
up for 4800 bps,7 data bits, even parity, 1 stop bit, and none for
flow control. Line delay is set for 1000 ms.
NMEA sentence:
$GPGGA,22708,333.601,N,8157.192,W,1,8,1.5,165.2,M,-31.7,M,,*7D
The tenth position is the altitude (165.2)
'{$STAMP BS2}
'{$PBASIC 2.5}
'
[noparse][[/noparse]constants]
gpspin con 16
lightpin con 6
soundpin con 15
peakalt con 4000
lightalt con 3000
soundalt con 1000
gpsbaud con 8380
'
[noparse][[/noparse]Variables]
peakflag VAR bit ' if altitude >4000m = 1
lightflag VAR bit ' if altitude <3000m = 1
soundflag VAR bit ' if altitude <1000m = 1
curalt VAR word ' altitude parsed from gps string
'
Initialize
out lightpin = 0
out soundpin = 0
' Main Program
peakalt = 0
lightalt = 0
soundalt=0
curalt=0
DO
SERIN gpspin, gpsbaud,[noparse][[/noparse]Wait("GPGGA,") ,wait (","), wait (","),
wait (","), wait (","), wait (","), wait (","), wait (","), wait
(","), dec curalt] 'parse gps string for alt
IF peakflag = 0 AND curalt > peakalt THEN peakflag = 1
IF peakflag = 1 AND curalt < lightalt THEN TOGGLE lightpin
IF peakflag = 1 AND curalt < soundalt THEN TOGGLE soundpin
IF ENDIF
LOOP
Thanks for any help!
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
This message has been scanned by WebShield. Please report SPAM to
abuse@p....
string. I actually connected to my Garmin eTrex and tested it. You'll
see that the program does SERIN like this:
SERIN GpsIn, Baud, [noparse][[/noparse]WAIT("GPGGA,"), SKIP 40, WAIT(","), STR
gpsData\6\","]
I used an array to capture the altitude data so that the tenths can be
extracted (there's a subroutine that handles this) -- this is based on
previous experiments with GPS. The \"," at the end of the input causes
the SERIN to terminate when the trailing comma is encountered, and the
rest of the array gets filled with zeroes (the subroutine knows this and
handles it).
You can, of course, simplify by using DEC as in your example. I tested
and it works just as well, you just lose the tenths digit.
SERIN GpsIn, Baud, [noparse][[/noparse]WAIT("GPGGA,"), SKIP 40, WAIT(","), DEC altM]
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: freqman1 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=q9kkXOxLJ6EPXrlN4uLwXKvd4KNAYArzUjrxZreJE7bTtJl-f0ZAC7_IpXZMtgf6mlGn8IIIts-ZE1IOTx_wwmoL]shawnsweeney@h...[/url
Sent: Thursday, December 04, 2003 12:37 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] STAMP Project -Parsing NMEA data string
First, I am new to not only the STAMP but to PBASIC and any other
code. The idea of this project is to use NMEA sentences parsed into
the stamp, extract the altitude, and set some flags to trigger a
couple pins to turn on a light and alarm. For the purposes of the
project I am simulating the GPS feed using Hyperterminal from a
laptop and using the serial port. I am trying to set the first flag
at 4k m to signal the peak ascent and then having the light come on
at 3k m and the sound at 1k m. I checked the syntax and everything
seems o.k. For the time being I'm just testing with two LEDs but am
not getting the lights to come on or toggle. Below is the code I
wrote along with a sample NMEA sentence. I have the Hperterminal set
up for 4800 bps,7 data bits, even parity, 1 stop bit, and none for
flow control. Line delay is set for 1000 ms.
NMEA sentence:
$GPGGA,22708,333.601,N,8157.192,W,1,8,1.5,165.2,M,-31.7,M,,*7D
The tenth position is the altitude (165.2)
'{$STAMP BS2}
'{$PBASIC 2.5}
'
[noparse][[/noparse]constants]
gpspin con 16
lightpin con 6
soundpin con 15
peakalt con 4000
lightalt con 3000
soundalt con 1000
gpsbaud con 8380
'
[noparse][[/noparse]Variables]
peakflag VAR bit ' if altitude >4000m = 1
lightflag VAR bit ' if altitude <3000m = 1
soundflag VAR bit ' if altitude <1000m = 1
curalt VAR word ' altitude parsed from gps string
'
Initialize
out lightpin = 0
out soundpin = 0
' Main Program
peakalt = 0
lightalt = 0
soundalt=0
curalt=0
DO
SERIN gpspin, gpsbaud,[noparse][[/noparse]Wait("GPGGA,") ,wait (","), wait (","),
wait (","), wait (","), wait (","), wait (","), wait (","), wait
(","), dec curalt] 'parse gps string for alt
IF peakflag = 0 AND curalt > peakalt THEN peakflag = 1
IF peakflag = 1 AND curalt < lightalt THEN TOGGLE lightpin
IF peakflag = 1 AND curalt < soundalt THEN TOGGLE soundpin
IF ENDIF
LOOP
Thanks for any help!
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
This message has been scanned by WebShield. Please report SPAM to
abuse@p....