Changing GPS co-ordinates into Degrees-Minutes-Seconds


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1

    Question Changing GPS co-ordinates into Degrees-Minutes-Seconds

    Hi
    I am able to get GPS NMEA data and display it onto my PC. Has anyone done any project to change the GPS co-ordinates into Degrees Minutes and Seconds they would like to share here. Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    I have some ugly code that I could share ... (if you really want it...)

    But the basic conversion is *5/300 for minutes and *5/18000 for seconds

    For instance 30 minutes *5/300 = .50 degrees


    if latitude = 47 deg 32 min 14 sec
    47 32' 14"

    then we can use:
    32 *500/3 = 5333 (really .5333 degrees)

    for seconds:
    14*50/18 = 38 (really .0038 degrees)

    Then add 5333 + 38 = 5371 or .5371 degrees

    So, 47.5371 degrees is the answer.
    http://www.scalerobotics.com

  3. #3


    Did you find this post helpful? Yes | No

    Question

    I am confused as well.
    Last edited by financecatalyst; - 26th October 2009 at 18:12.
    ___________________
    WHY things get boring when they work just fine?

  4. #4


    Did you find this post helpful? Yes | No

    Question

    Quote Originally Posted by scalerobotics View Post
    I have some ugly code that I could share ... (if you really want it...)

    But the basic conversion is *5/300 for minutes and *5/18000 for seconds

    For instance 30 minutes *5/300 = .50 degrees


    if latitude = 47 deg 32 min 14 sec
    47 32' 14"

    then we can use:
    32 *500/3 = 5333 (really .5333 degrees)

    for seconds:
    14*50/18 = 38 (really .0038 degrees)

    Then add 5333 + 38 = 5371 or .5371 degrees

    So, 47.5371 degrees is the answer.
    I would like to see the code if you dont mind. Currently the coordinates are in a string format. Being new to this field your code will help me to have a starting point and will help me understand and decide the way forward

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Sorry, let me explain a little more. I will try to explain this better tonight when I get home from work.

    The basic conversion is:
    Code:
    Converting Between Decimal Degrees, Degrees, Minutes and Seconds, and Radians
    (dd + mm/60 +ss/3600) to Decimal degrees (dd.ff)
    
    dd = whole degrees, mm = minutes, ss = seconds
    
    dd.ff = dd + mm/60 + ss/3600
    
    Example: 30 degrees 15 minutes 22 seconds = 30 + 15/60 + 22/3600 = 30.2561
    
    Decimal degrees (dd.ff) to (dd + mm/60 +ss/3600)
    But division by 3600 does not work so well for PICs, so .......

    Here are a couple ways of converting 15 minutes:
    15minutes/60 = .25 degrees. Unfortunately PicBasicPro will round it off to 0, which we do not like.

    So, if we change it to 15minutes*500/3=2500 (you'll notice this is the same as the first equation, only multiplied by 10000). We want whole numbers here, and we will need to add seconds to it in whole numbers too.


    Here is one part of my minutes to degrees conversion, but I will try to make this a lot clearer tonight. char_A is the validity character in a gps string called gpsdata.
    Code:
    lathome_min = ((((gpsdata[char_A+9]-48)*10) + (gpsdata[char_A+10]-48))*5)/3    'lathome_min
    http://www.scalerobotics.com

  6. #6
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by FromTheCockpit View Post
    Hi
    I am able to get GPS NMEA data and display it onto my PC. Has anyone done any project to change the GPS co-ordinates into Degrees Minutes and Seconds they would like to share here. Thanks
    OOPS. My bad.

    Did you really mean that you only want Degrees Minutes and Seconds? Or do need to convert to deg.deg ?

    If you just need the digits, its the ASCII -48 = digits.
    http://www.scalerobotics.com

  7. #7


    Did you find this post helpful? Yes | No

    Question

    Quote Originally Posted by scalerobotics View Post
    OOPS. My bad.

    Did you really mean that you only want Degrees Minutes and Seconds? Or do need to convert to deg.deg ?

    If you just need the digits, its the ASCII -48 = digits.
    Yes thats correct. I only need to convert the lat & long to degrees minutes and seconds and display it on my pc screen.

  8. #8
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Well, then...........

    There are a couple different ways to do it. I'm going to show you the Serin2 example, because that is the gps example that MeLabs gives.
    Another good way to do it is to read the entire NMEA sentence into an array like this, then worry about parsing it later:
    Code:
    HSerin 200, Main, [WAIT("$GPRM"), STR gpsdata\MAXDATA\13]
    but we will stick with serin2 for now.

    Here is MeLabs gps example for reading speed.
    http://melabs.com/resources/samples/...d/read_gps.bas

    You would have to adjust to get degrees minutes and then do a conversion for seconds
    For instance, their ...
    Code:
    SerIn2 GPSin,baudGPS,Timeout,Nogps,[wait("$GPRMC"),skip 34,DEC1 tens,DEC1 digits,skip 1,DEC1 tenth]
    means wait till it sees $GPRMC that begins the NMEA sentence, skip 34 characters to the speed tens digit, put it in variable "tens", then read next speed digit and put in variable called "digits", then skip the "." and read the last decimal into a variable called "tenth".

    You would have to adjust the skips to match the digits you want to get.
    Code:
    $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
    
    Where:
         RMC          Recommended Minimum sentence C
         123519       Fix taken at 12:35:19 UTC
         A            Status A=active or V=Void.
         4807.038,N   Latitude 48 deg 07.038' N
         01131.000,E  Longitude 11 deg 31.000' E
         022.4        Speed over the ground in knots
         084.4        Track angle in degrees True
         230394       Date - 23rd of March 1994
         003.1,W      Magnetic Variation
         *6A          The checksum data, always begins with *
    If your NMEA sentence was similar to above (some add more resolution and are of slightly different format), then you could use:
    Code:
    SerIn2 GPSin,baudGPS,Timeout,Nogps,[wait("$GPRMC"),skip 11,DEC2 lat_deg,DEC2 lat_min,skip 1,DEC3 lat_min_dec ... then same for longitude]
    Now, you need to convert decimal minutes to seconds .... am I right this time? Because the GPS will output in decimal minutes, not seconds.

    So, to convert decimal minutes into seconds:
    lat_seconds = lat_min_dec * 6
    so, using the NMEA sample above: 038 * 6 = 228

    When you print this out to your computer, you print a "." in between the twos
    and get 2.28 seconds. This part just prints the seconds out through the serial port.
    The dig specifies which digit you want to print of the variable called seconds. Rightmost digit is 0
    Code:
    DEBUG DEC lat_seconds dig 2,".",DEC lat_seconds dig 1, DEC lat_seconds dig 0,13,10
    Last edited by ScaleRobotics; - 27th October 2009 at 07:05.
    http://www.scalerobotics.com

  9. #9


    Did you find this post helpful? Yes | No

    Question

    Ok, thanks for your time in writing a detailed explanation, BUT little bit of confusion still left. I have the following string :

    $GPRMC,123339.000,A,5134.2770,N,00007.8480,E,1.14, 254.38,271009,,*09

    Can you please show me as to how to convert "5134.2770" & "00007.8480" into degrees - minutes - seconds in PBP + speed to Km/H.
    I have done this online and the answer is
    Degrees, Minutes & Seconds
    Latitude - Longitude
    N51 34 16 - W0 07 50 and 2.111 Km/Hr (Though it should be 0 Km/Hr as Module is stationary)

    Also what is checksum? and what it is used for?

    Your effort will be much appreciated. Many Thanks

  10. #10
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    You are using one of the newer GPS's with a little higher resolution. With any handheld gps, there will be a little wandering of the output. You will see slight position changes, even though you are standing still. This will result in a display of speed, although it will be very low speed.

    The checksum is used to ensure the device reading the gps doesn't receive faulty input. If it is important for your application, the Pic chip can be made to perform a checksum on the sentence, and compare it to the one the gps calculated. If it differs, the data read from the gps is corrupt, and must be read again.

    To convert Knotts to km/h, multiply by 1.852. Since PICs don't do decimal, we will have to make our own. A close enough approximation of knotts x 1.852 is (knotts x 2048)/11, but remind yourselft that your result will have two digits past the decimal point. If you want whole numbers for km/h then divide by 100, or do (knotts x 2048)/1100. A handy tool to figure these fractions out is a download at the very bottom of this page: http://www.miscel.dk/MiscEl/miscel.html

    To convert, you follow my earlier example, but insert skips to match the format of your NMEA sentence.

    For your:
    Code:
    $GPRMC,123339.000,A,5134.2770,N,00007.8480,E,1.14, 254.38,271009,,*09
    it would be something like:
    Code:
    SerIn2 GPSin,baudGPS,Timeout,Nogps,[wait("$GPRMC"),skip 14,DEC2 lat_deg,DEC2 lat_min,skip 1,DEC3 lat_min_dec ....]
    you should be able to enter the rest for longitude now....

    The degrees and whole minutes are already in the format you want. We just need to convert decimal minutes into seconds. To do this, we use the same conversion I showed you in the previous example (except you will see that I forgot to add another digit for the seconds result). Here you have .2770 minutes. We only care about the first three digits. In fact, we might care about even fewer digits, but since we used three of the digits in the last example, lets just use three again.

    The following will multiply your 277 by 6. This will give you a result of 1662, which really is 16.62, but again, the PIC can't do decimal, so we will use the whole number, and just format it for output.
    Code:
    lat_seconds = lat_min_dec * 6
    DEBUG DEC lat_deg," deg ",DEC lat_min," min ",DEC lat_seconds dig 3,DEC lat_seconds dig 2,".",DEC lat_seconds dig 1, DEC lat_seconds dig 0," sec",13,10
    That would print out:
    "51 deg 34 min 16.62 sec", which matches pretty well with the 51 34 16 that you converted on line.
    Last edited by ScaleRobotics; - 27th October 2009 at 15:08.
    http://www.scalerobotics.com

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 09:47
  2. Virtual LED Clock For Windows By Trent Jackson
    By T.Jackson in forum Code Examples
    Replies: 8
    Last Post: - 10th November 2009, 08:20
  3. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  4. GPS clock timing !
    By bethr in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 3rd July 2008, 20:11
  5. DS1994 Memory/Time iButton
    By NavMicroSystems in forum mel PIC BASIC Pro
    Replies: 47
    Last Post: - 22nd October 2006, 11:55

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts