28146 GPS module
Draetoxtheloon
Posts: 33
Hi, so I have a Parallax 28146 SIO GPS module...I was looking at the datasheet and I was wondering if anyone could clear me up on a few things.. first off I'm using MCC18 C language, I want to know how to initialize the GPS and I want to know how to send commands to the GPS so that I can display the result on an LCD module. Can anyone help me???
Comments
You might want to consider configuring it to output only a specific sentence of interest.
PE - If you're looking for a "C" program done up, then ask for that.
There's about 10 or 12 different commands you can send over the serial I/O line. They're in the data sheet. You just send an ascii string (!GPS) followed by the hex code for the command you want to issue and the result comes back immediately over the same I/O line. It's just basic serial communication at 4800 bps (8n1). I've never used it with anything but a Basic Stamp2, but it shouldn't be too hard.
So, you can poll for possibly slightly stale data, or wait for the latest 1/sec. Either way.
Draetox,
Are you looking for help with serial comms in re. "C" (or what)?
PJ, MCC18 is a popular C variant for the PIC. So my guess is he's interfacing the module to a PIC, and using an LCD to display whatever values he's looking for. Draetoxtheloon, is that about right?
-- Gordon
First you need to prepend all command bytes with the string !GPS (with the "bang" character). Second, you to review the electrical connection between your MCU and the GPS. The GPS uses half-duplex serial, and your MCU will need to either have open collector I/O so you can use just one pin for both input and output, or you'll need to cheat by separating the SIO line from the GPS into Rx and Tx lines on your MCU. You can do this by pulling the Rx line high with a 10K resistor, and placing a diode between the SIO line and the Tx line. The cathode faces the Tx line. (Do a search in the forums and you should be able to find some examples of this).
Commands like GetLat return five bytes, which you must then combine to get the actual GPS coordinates. The coordinate data is in several separate bytes. Review the Basic Stamp 2 code in the data sheet for the conversion on how to convert the byte values to standard GPS dd.mmmm display.
As for what programming functions you can use, hopefully someone familiar with MCC18 can help. You might have better luck with that aspect in a PIC-C forum, where you'll happen on more people familiar with the libraries.
-- Gordon
edit: ah, reading comprehension 101
valid signal, number of sats, time, lat, long = 5
So, for a 1 second accurate clock, you would have to request only the time.
-- Gordon
SEROUT Sio, Baud, ["GPS", GetLat]
SERIN Sio, Baud, 3000, No_Response, [degrees, minutes, minutesD.HIGHBYTE, minutesD.LOWBYTE, dir]
I kind of understand the SEROUT line but tell me if I'm wrong, First you are calling the SEROUT function and telling it that it is on the Sio line, then you are giving it a Baud rate (mine is 4800), then it looks like it is writing strings using RX and TX....is this correct?
I don't understand the SERIN line....mainly the 3000, No_Response, [degrees, minutes, minutesD.HIGHBYTE, minutesD.LOWBYTE, dir] part
SERIN <Pin>, <Baud Rate>, <Timeout> (3 seconds in this example), <where to go if there is a timeout>, [ BYTE <degrees>, BYTE <minutes>, HIGH BYTE of <minutesD> LOW BYTE of <minutesD> (to be combined into a word varable <minuteD>), BYTE dir]
DEBUG MoveTo, FieldLen, 12, DEC3 degrees, DegSym, " ", DEC2 minutes, MinSym, " "
DEBUG DEC2 (workVal / 10), ".", DEC1 (workVal // 10), SecSym, " "
DEBUG "N" + (dir * 5)
You don't "need" to implement a Timeout equivalent if you're happy to have your program hang till it gets GPS data. The Timeout is an option whereby the program can move on if there's no data within some given time.
DEC3 is a formatter, indicating that 'degrees' is 3 decimal numbers. DEC2 stipulates that 'minutes' is 2 decimal numbers.
The data from the GPS is all ASCII.
OK, back in #14, you stated, "I don't understand the SERIN line....mainly the 3000, No_Response... part."
So, in that line of code, the program is going to SERIN (ReadUART), but if it doesn't get any data in 3000msec then it's going to go to a subroutine called No_Response. If those parameters (optional) aren't specified then the program will stay there, waiting for data.
Typically, "we" SERIN the data to a data array and then transmit that out to an LCD with some formatting (starting on a particular line or place.)
[If you are using a serial LCD (has that been specified yet?) you could run the GPS data_out right into the LCD input (it won't be formatted) - assuming they have a common baudrate.]
PE - I don't know how you guys send characters, but as a hex/data proposition, if you send the GPS the following string: 21 47 50 53 05
(representing "! G P S" 05)
then it should send out Latitude data (once)
There's a member, his handle is Zoot, who probably knows your "C"-deal well enough to connect with you there.
Assuming the GPS gets the latitude query then it'll shoot back the latitude data, 9 bytes of ASCII code: 4 numeric characters, a period, and 4 numeric characters -- the degrees MSD, the degrees LSD, the minutes MSD, the minutes LSD, a period, the 1/10min digit, the 1/100min digit, the 1/1000 min digit, the 1/10000 minute digit.
Are you using a microcontroller or a PC or what?
Any progress yet?
It's easy to get confused if you try to do too many things at once. You should first try by manually setting byte variables to display as characters on your LCD. Forget the GPS for now. Once you're sure that a byte with the value "205" is displayed correctly on the LCD you're ready to move on. Be sure to also try values under 32. If you get weird characters instead, you're sending actual bytes for those values, and not strings.
Then test the connection with your GPS and your conversion by putting the unit in RAW mode. Simply echo the strings you get back from the GPS. If you have a debug window send the serial output from the GPS there. It'll be easier to see what's happening, because LCD displays have limited space for characters.
When all of this is working you can put the GPS back into Smart Mode. Try a simpler one-byte return type. Number of satellites is a good one, as it returns just one byte. The value will always be under 20, as that's the limit of the receiver itself. (BE SURE you're back into Smart Mode, or else it'll appear you're getting data, when it's actually just random values being picked up from the receive pin in RAW mode.)
Okay, *now* you're ready to query the GPS for the five bytes for reading latitude or longitude.
-- Gordon
That means, for example, if the degrees value is 33, it's not ASCII 3 and 3, but a byte value of 33.
From these bytes you must construct the actual degrees/minutes display. The receiver provides GPS coordinates in the format DDmm.mmmm, but you probably want degrees in minutes and seconds in the more readable dd.mmmm format, or decimal degrees.
-- Gordon
OMG...
Now I have to go set myself on fire (again.)
A. Prefix with !GPS, and you get the individual bytes, which you can then use for numeric calculations. (If they were strings you'd have to then parse them down if you wanted, for example, to calculate the distance between two points.)
B. Prefix with !GPX, and you get the value as a single ASCII null terminated string. You can use that kind of data to directly display on an LCD without any further processing except basic formatting.
Variations on the theme, or an additional control byte sent in, might provide the latitude and longitude in various coordinate types. DD.mmmm in min/sec could be directly plugged into Google Maps API (it won't take decimal or DDmm.mmmm GPS coordinates, it seems).
-- Gordon