BS2 to Garmin GPS - Newbie
Justin
Posts: 6
Ello folks...
Ok, so my deal is that I'm rather new to the basic stamp 2 and to electronics period.· What I'm trying to do is that I have a Garmin GPS 20SL (old, but still works) that I'm trying to interface with the basic stamp 2.· I'm using a programming board to do this.· I have two programs that I've been trying - one to just cycle through repeatedly and look for serial input from the GPS, and one to send a command to the GPS and listen for a response that should be echoed back.· Neither are working.· I've included the code for each below - any help/suggestions/links would be awesome.· I can try to give more info if needed as well.
Thanks!!
·- Justin
Code: Simple loop to get incoming data
'{$STAMP BS2}
'{$PBASIC 2.5}
DataOut VAR Word
DEBUG "Testing", CR
OUTPUT 7
INPUT 16
HIGH 7
Main:
·· SERIN 16, 16572, 1000, Timeout, [noparse][[/noparse]DataOut]· ' 4800 baud rate
·· DEBUG "DataOut: ", DataOut, CR
·· GOTO Main
Timeout:
·· DEBUG "timeout ", CR
GOTO Main
END
Code:· Trying to send command and listen for echo back
'{$STAMP BS2}
'{$PBASIC 2.5}
OUTPUT 7
INPUT 4
DataOut VAR Word
DEBUG "Testing", CR
HIGH 7
Main:
·· SEROUT 16,16572,200,[noparse][[/noparse]"$PGRMC"]
·· 'DEBUG "Data Sent: ", CR
repeat:
·· SERIN 17, 16572, 1000, Timeout, [noparse][[/noparse]DataOut]
·· DEBUG "DataOut: ", DataOut, CR
··· GOTO repeat
Timeout:
·· DEBUG "timeout ", CR
GOTO repeat
EndX:
END
·
Ok, so my deal is that I'm rather new to the basic stamp 2 and to electronics period.· What I'm trying to do is that I have a Garmin GPS 20SL (old, but still works) that I'm trying to interface with the basic stamp 2.· I'm using a programming board to do this.· I have two programs that I've been trying - one to just cycle through repeatedly and look for serial input from the GPS, and one to send a command to the GPS and listen for a response that should be echoed back.· Neither are working.· I've included the code for each below - any help/suggestions/links would be awesome.· I can try to give more info if needed as well.
Thanks!!
·- Justin
Code: Simple loop to get incoming data
'{$STAMP BS2}
'{$PBASIC 2.5}
DataOut VAR Word
DEBUG "Testing", CR
OUTPUT 7
INPUT 16
HIGH 7
Main:
·· SERIN 16, 16572, 1000, Timeout, [noparse][[/noparse]DataOut]· ' 4800 baud rate
·· DEBUG "DataOut: ", DataOut, CR
·· GOTO Main
Timeout:
·· DEBUG "timeout ", CR
GOTO Main
END
Code:· Trying to send command and listen for echo back
'{$STAMP BS2}
'{$PBASIC 2.5}
OUTPUT 7
INPUT 4
DataOut VAR Word
DEBUG "Testing", CR
HIGH 7
Main:
·· SEROUT 16,16572,200,[noparse][[/noparse]"$PGRMC"]
·· 'DEBUG "Data Sent: ", CR
repeat:
·· SERIN 17, 16572, 1000, Timeout, [noparse][[/noparse]DataOut]
·· DEBUG "DataOut: ", DataOut, CR
··· GOTO repeat
Timeout:
·· DEBUG "timeout ", CR
GOTO repeat
EndX:
END
·
Comments
Change your SERIN and SEROUT statements to use some pin port other than pin port 16. You also have a typo in the last SERIN as there is no pin port 17. Among other things, by default, ECHO is ON for data sent on pin port 16 (the DEBUG pin port) and that will certainly confuse the issue for the GPS and the Stamp.
I'm not sure that it actually matters here, but just as a matter of information, as soon as DEBUG is used, the BAUD RATE is reset to 9600 baud. The DEBUG BAUD RATE is fixed at 9600 BAUD for all of the BS-2 products.
Regards,
Bruce Bates
Each SEROUT can have a different baud rate -- no problem for the BS2.
I assume the Garmin wants a real RS232 voltage -- so you'll probably need to add a MAX232 chip to the pins you use for the Garmin, to get the voltage shift.
Question for y'all though. Probably a really simple thing, but I was under the impression that only the serial in/out pins could handle serial data coming into the BS2? By changing it to a regular pin, say 5, the data will still come in and be stored as data type word for example?
Cheers,
- Justin
Post Edited (Justin) : 2/17/2005 10:06:27 PM GMT
For your program, any pin port can be used with SERIN/SEROUT. On the BS-2 (plain) any pin port can be used for any purpose, as the only predefined use is DEBUG on pin port 16. On the BS-2p series this is not the case. Some pin ports or sets of pin ports are dedicated there for specific uses.
Regards,
Bruce Bates
I have interfaced my garmin emap gps to a BS2 directly without a MAX232 driver..·Read ·Jon William's article in Nuts and Volts on interfacing with GPS.
Mike S.
I found the article I think you're talking about in the Nov 2003 edition of Nuts and Volts, and was able to download the code that went with it, but couldn't find a copy of the actual article online. Any chance that someone would have a link to it online or will I need to go order a back issue? (Gonna scout out the libraries tomorrow too...)
Thanks guys... Y'all are great!
- Justin
All of the Nuts & Volts articles written by Jon Williams can be found here on the Parallax web site:
http://www.parallax.com/html_pages/downloads/nvcolumns/Nuts_Volts_Downloads.asp
Regards,
Bruce Bates
I'm back in the saddle again, and what y'all have given thus far has been great. I'm now at the point where I'm pretty sure I've got all the wires on right and I'm getting data from the GPS. My next issue, however, is how to get that data into usable form. Everything I've found thus far, from you guys and the Nuts and Volts article, is using the BS2p, which has the scratchpad memory. I've got the green chip, the plain old BS2, which I'm thinking does not have that memory.
Any hints on how I can bring out that text string into a memory spot so I can parse it?
Cheers,
- Justin
You can use WAIT and SKIP commands to get your data to individual variables.· If you just want them to display, then you debug them or serout them in the format you like.
you certainly don't need the entire string....if you do...then yes, get the BS2P...otherwise you do a bit of 'on the fly' filtering.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
I stole this off of the Yahoo groups back when they were going!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
·· Sure!· Just go to the main Forums window.· Toward the bottom is "Archives."· And under that is the BASIC Stamps Archive, which is all the archived messages from the Yahoo Group.· Enjoy!· Lots of stuff in there!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--==<{Chris}>==--
The woes continue... I've gotten to the point now where I'm using a basic program to grab what I believe are the first 3 bytes of data coming out of the gps, then post then to the debug window (code below). The problem, however, is that all I get out are binary numbers, and even those are not consistent or understandable. I've tried doing a WAIT("$GPGGA") statement, but then it hangs up, never finding it. I'm using a plain old BS2, so I haven't been able to pull out the full string of data (if I'm even getting good data). Arg! Oh the joys of jumping into a project with little experience and randomly donated hardware. [noparse]:)[/noparse]
Any ideas?
- Justin
Code:
'{$STAMP BS2}
'{$PBASIC 2.5}
OUTPUT 7
INPUT 8 'Set pin to receive input
HIGH 7 'Turn power on - 5V to pin 7
DataOut VAR Word
Main:
SERIN 8, 16572, 1000, Timeout, [noparse][[/noparse] DataOut(0), DataOut(1), DataOut(2)]
DEBUG "DataOut: ", BIN DataOut(0), "-",BIN DataOut(1),"-",BIN DataOut(2), CR', BIN DataOut(1), CR 'Outputting in other formats - STR, HEX, etc also doesn't give useful data... still shows the binary in most cases
GOTO Main
Timeout:
DEBUG "timeout ", CR
GOTO Main
END
Sample of code output:
DataOut: 11111111-1-0
DataOut: 0-0-0
DataOut: 0-11111111-0
DataOut: 0-0-0
DataOut: 0-0-0
DataOut: 0-11111111-0
DataOut: 0-0-11111111
DataOut: 0-0-1
DataOut: 0-0-0
DataOut: 0-0-11111111
DataOut: 0-0-0
DataOut: 0-0-0
DataOut: 0-0-0
DataOut: 11111111-0-0
DataOut: 0-0-0
DataOut: 0-0-0
DataOut: 0-11111111-0
DataOut: 0-0-11111111
DataOut: 0-0-0
DataOut: 0-0-0
DataOut: 0-0-0
DataOut: 11111-0-0
Code that will stall the program:
SERIN 8,16572,2000,GPSReadDataFailed,[noparse][[/noparse]WAIT("$GPGGA"), SKIP 1, DEC2 TimeData(0), DEC2 TimeData(1), DEC2 TimeData(2), SKIP 1, DEC2 TimeData(3), SKIP 2, DEC2 LatitudeData(0), DEC2 LatitudeData(1), SKIP 1, DEC2 LatitudeData(2), SKIP 3, LatitudeData(3), SKIP 1, DEC3 LongitudeData(0), DEC2 LongitudeData(1), SKIP 1, DEC2 LongitudeData(2), SKIP 3, LongitudeData(3), SKIP 1, DEC1 GPSQuality, SKIP 8, DEC AltitudeData]
(with appropriate variable definitions, etc)
I honestly don't know what the $GPGGA string is...but there is a $GPRMC string that is NMEA183 which is fairly common.
So, in ·that stamp code that stalls...change the wait string to the $GPRMC.·
Have you tried a serstring...it should give you an idea what the first wad of characters are...
so, declare the string:
···· serstring VAR Byte(20)·
then bring in your data:
···· SERIN commin, n19k2, [noparse][[/noparse]STR serstring\20]··
---I've stolen this from a program...so the baud is different and you may want to shorten/lengthen the number of bytes)
then display the string:
DO
····· temp = temp + 1
····· DEBUG DEC2 temp+1," :",HEX serstring(temp),CR
····· IF (temp = 20) THEN
······ENDIF
LOOP
I use a temp variable to number out the digits...but it isn't really necessary...just looks somewhat organized.
This may not catch the beginning of the string as the serin line will wait until all 20 characters are received....so you might end up with the middle 20 characters of the string...but just reset until you see the beginning of the string.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
Jim