PBasic code help for GPS
Draetoxtheloon
Posts: 33
Hi, I have been in multiple forums which have helped me to get the Parallax 28146 GPS to work in Smart and Raw mode, the question I have now is in the GPS datasheet what does the variable "Word" mean....I don't know if that is similar to "String" in C.....The problem I have is that when I ask for Latitude I get this:
Lat=050(degree Symbol) then I get 54 (minutes) and finally my fractional minutes usually just come out with a random number like 156 or -2800....I'm assuming its due to the data coming out as a Word and I'm sending it to a Char array....anyone know how to help me get the proper data out on fractional minutes??? or can anyone help me figure out how to store a "Word" variable in C???
Lat=050(degree Symbol) then I get 54 (minutes) and finally my fractional minutes usually just come out with a random number like 156 or -2800....I'm assuming its due to the data coming out as a Word and I'm sending it to a Char array....anyone know how to help me get the proper data out on fractional minutes??? or can anyone help me figure out how to store a "Word" variable in C???
Comments
Best to use an integer because Word refers (in this case) to a 16-bit unsigned integer and a lot of C implementations will implement a short integer as a signed integer which won't work here. The values involved can range from 0 to 65535.
Okay, so I'm using an Array of unsigned int, and I can get the first byte (degrees) to show perfectly, I can then display the next byte (Minutes) perfectly....but when I try to get the Highbyte and Lowbyte from the fractional minutes I can't seem to get the correct data.....any idea why??? the Highbyte and Lowbyte come from this data sheet --> www.parallax.com/Portals/0/Downloads/docs/.../GPSManualV2.0.pdf
The FractMinWord value is the result of putting together the two bytes. You may want to format it for display to make it look pretty with the integer part of the minutes.
I had asked him if Word was like String in C language:
"I don't think so exactly. The "Word" is two-bytes -- the higher byte is full minutes, the lower byte is the fraction (256ths) if it's coming through as binary numbers (if it was "characters" like in a string, it would take at least 5 bytes -- 5 characters -- to get 3 digit whole numbers plus 2 digit decimal). "
In PBasic Byte is an unsigned byte in C
In PBasic Word is an unsigned int (16 bit) in C
Forget strings, except to format the byte data you're receiving onto the LCD. Absolutely, unequivically, make no mistake: the data this GPS module returns in Smart Mode is one or more unsigned bytes.
Now, why are you using [0] and [1] for the data returned by the GPS for the two bytes for fractional minutes? The docs show the order of the 5 bytes for latitude and longitude as:
degrees (one byte)
minutes (one byte)
fractional minutes (separated into 2 bytes, HIGH byte first)
direction (one byte, the value is either 0 or 1)
Read the five bytes, store in the array, and elements 2 and 3 will contain fractional minutes.
Your code suggests you expect to receive LOW byte first from the module. That's not correct.
There is no need to guess at the data. Look at each value on the LCD, starting with element 0. The data you see for each element should make sense, based on your latitude and longitude (use Google Maps to determine that). For example, for me, where I live near San Diego, the first byte for latitude is 32. Once I got that from the module I knew I was starting to see valid data.
Remember that the unit returns GPS coordinates, and you want decimal degrees for use in Google Maps. You can use the calculator here to make sense of the data with Google:
http://transition.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html
Refer to the bottom half of page 7 of the 28146 manual for a discussion of the different types of data formats.
-- Gordon
-- Gordon