Shop OBEX P1 Docs P2 Docs Learn Events
PBasic code help for GPS — Parallax Forums

PBasic code help for GPS

DraetoxtheloonDraetoxtheloon Posts: 33
edited 2011-10-02 21:25 in General Discussion
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???

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-01 11:49
    Word generally refers to a 16-bit word in Parallax documentation. In most C implementations, this is a short integer, but you could use an integer as well.

    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.
  • DraetoxtheloonDraetoxtheloon Posts: 33
    edited 2011-10-01 14:29
    Mike Green wrote: »
    Word generally refers to a 16-bit word in Parallax documentation. In most C implementations, this is a short integer, but you could use an integer as well.

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-01 16:39
    The two bytes that make up the word may be coming in in a different order than you expect. The most significant byte comes first, then the least significant byte. How are you putting them together to get the whole word?
  • DraetoxtheloonDraetoxtheloon Posts: 33
    edited 2011-10-02 09:46
    so far all I have been doing, which I assume is incorrect, I have allocated an array temp[5], then I say temp[0] = SERIN (Read1USART for me), then temp[1] = SERIN...and so on....so temp[0] is my Degrees, temp[1] is my Minutes, and temp[2]/temp[3] would be the highbyte/lowbyte of the word, then I just say put temp 0-3 onto the LCD...I figured it would follow the format DD (0), MM (1), FracMinHighbyte (2), FracMinLowbyte (3), and finally DIR (4). Do I need to take the values of temp[2]/temp[3] highbyte/lowbyte and put them into a different variable combining the two pieces of information before sending it to the LCD???
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-02 10:04
    You'd typically use FractMinWord := FractMinHighbyte << 8 + FractMinLowbyte
  • DraetoxtheloonDraetoxtheloon Posts: 33
    edited 2011-10-02 10:21
    Okay so I would be putting the FractMinWord variable to the LCD correct? As another question I use C, so I'm trying to understand what it is your writing, I don't fully understand this operator ":=" but I think your saying shift the FractMinHighbyte left 8 times correct? then your adding the FractMinLowbyte to the end, correct? Finally do you know if I can do this operation of storing the shifted highbyte + lowbyte using an array???
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-02 11:39
    C uses "=". Both Pascal and Spin use ":=" for assignment. You're right about positioning the high byte then adding the low byte. Spin does not have array operators, so you'd have to use a loop to do the same thing to multiple values.

    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.
  • DraetoxtheloonDraetoxtheloon Posts: 33
    edited 2011-10-02 11:46
    Okay, because currently I have tried:
    {
          temp[i] = RCREG1;  //This is SERIN, Read1USART, ReadGPS data line
          Delay1KTCYx(100);
          i++;
    }
    FractMinHighbyte = temp[1];
    FractMinLowbyte = temp[0];
    FractMinWord = FractMinHighbyte << 8 + FractMinLowbyte;
    
    putrsXLCD("Alt="); //Print to LCD
    sprintf(idata, "%d", FractMinWord);  //print Alt Word
    putsXLCD(idata); //Print to LCD
    
    And I keep getting Alt=0 on my LCD....so I think I am looping at the top there and the storing the Highbyte/Lowbyte into temp[0]/temp[1]....does that seem correct? Because if it is I'm confused as to why I'm getting a 0 on the output, when I use an array and just say temp = SERIN (from GPS) and then just say output temp[0], temp[1] to the LCD I get a value of 40140, and 14040 if I reverse the bytes....someone mentioned to me that the output could be in binary, do you know anything about that?? I'll try to find the persons post and post it here
  • DraetoxtheloonDraetoxtheloon Posts: 33
    edited 2011-10-02 11:56
    Okay so this is the post from another gentleman:

    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). "
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2011-10-02 13:01
    Way too much guessing here. All the important points have been covered in these various threads. I think you need to review them, rather than try to open up new ground. In review:

    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
  • DraetoxtheloonDraetoxtheloon Posts: 33
    edited 2011-10-02 13:37
    Okay, yeah I was using [0] and [1] for Altitude to see if I could properly store the Highbyte and Lowbyte, although I end up getting a number like 40112 which is rather large. As for the Latitude the way that I have been troubleshooting is exactly that, display [0] I get degress correct, display [1] I get minutes correct, display [2] I get 11520, display [3] I get 2560....which clearly aren't correct...as when I don't use an array I get 50degrees, 54minutes, 35910, so I believe [2] should display 35, and [3] should display 910...correct?
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2011-10-02 21:25
    Byte variables can only hold values of 0-255, so anything 256 or above must be an error of another type. Maybe you're not clearing the LCD screen each time, or there's something else in your code.

    -- Gordon
Sign In or Register to comment.