Shop OBEX P1 Docs P2 Docs Learn Events
Parallax Gps giving weird Long Lat Points — Parallax Forums

Parallax Gps giving weird Long Lat Points

TylerSkylerTylerSkyler Posts: 72
edited 2012-03-14 09:48 in Propeller 1
Hello All! I'm using a Parallax Gps for reading gps data(This One). Using this code I'm continually printing Longitude and Latitude:
Pub Main
repeat
  Debug.str(string("Longitude : "))
  lon2 := GPS.GetLongitude
  Debug.str(FS.FloatToString(lon2))
  Debug.str(string(" degrees",13))
  Debug.str(string("Latitude : "))
  lat2 := GPS.GetLatitude
  Debug.str(FS.FloatToString(lat2))
  Debug.str(string(" degrees",13))
  waitcnt(clkfreq + cnt)

All of the variables are declared in VAr. This prints values to the terminal. But the values are completely erratic jumping from .1degree to degrees in one debug. The light on the module is solid and it is reading in smart mode with the GPS_SmartMode object in the obex. some said it needed to be moving to get good values so I drove it around my block then plotted the points and they were skattered all over europe(im in California:smile:). Why would this be? How can I fix it?

As Always...Thanks,

Tyler

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-11 10:52
    Are you sure that GetLongitude and its mate return floating-point values? Perhaps they're integer with an assumed decimal point location. What happens if you use Debug.dec to print them out?

    -Phil
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-03-11 11:16
    Thanks for the reply. I changed it to Debug.dec() and ran the program again and I got this:
    Longitude : 1113523308 degrees
    Latitude : 1110657089 degrees
    
    
    Longitude : 1108090073 degrees
    Latitude : 1100105870 degrees
    
    
    Longitude : 1110653863 degrees
    Latitude : -1035524249 degrees
    
    
    Longitude : 1095952913 degrees
    Latitude : 1111984838 degrees
    
    
    Longitude : 1112500388 degrees
    Latitude : 1112270057 degrees
    
    
    Longitude : 1111697261 degrees
    Latitude : 1084938900 degrees
    
    
    Longitude : 1112212481 degrees
    Latitude : 1112246983 degrees
    
    
    Longitude : 1108664015 degrees
    Latitude : 1112505874 degrees
    
    
    Longitude : 1120935621 degrees
    Latitude : 1099208876 degrees
    
    
    Longitude : 1117023207 degrees
    Latitude : 1092237621 degrees
    
    
    Longitude : 1113783530 degrees
    Latitude : 1112517303 degrees
    
    
    Longitude : 1111959963 degrees
    Latitude : 1110730917 degrees
    
    
    Longitude : 1113042376 degrees
    Latitude : 1084309418 degrees
    
    
    Longitude : 1115971052 degrees
    Latitude : 1075141855 degrees
    
    
    Longitude : 1118326528 degrees
    Latitude : 1117222776 degrees
    
    
    Longitude : 1112859211 degrees
    Latitude : 1117963620 degrees
    
    
    Longitude : 1117941103 degrees
    Latitude : 1117618742 degrees
    
    
    Longitude : 1111697037 degrees
    Latitude : 1111181377 degrees
    
    
    Longitude : 1110787714 degrees
    Latitude : 1110730924 degrees
    
    
    Longitude : 1112238244 degrees
    Latitude : 1111207144 degrees
    
    
    Longitude : 1118667429 degrees
    Latitude : 1113299927 degrees
    
    
    Longitude : 1112999131 degrees
    Latitude : 1070051228 degrees
    
    
    Longitude : 1111194048 degrees
    Latitude : 1089507385 degrees
    
    
    Longitude : 1110135134 degrees
    Latitude : 1107877588 degrees
    
    
    Longitude : 1115831462 degrees
    Latitude : 1115691179 degrees
    
    
    Longitude : 1084683893 degrees
    Latitude : 1092392576 degrees
    
    
    Longitude : 1108496028 degrees
    Latitude : 1094892462 degrees
    
    
    Longitude : 1112887997 degrees
    Latitude : 1113805489 degrees
    
    
    Longitude : -1035783366 degrees
    Latitude : 1117618742 degrees
    
    
    Longitude : 1110147794 degrees
    Latitude : 1113025570 degrees
    
    
    Longitude : 1111692549 degrees
    Latitude : 1116303990 degrees
    
    
    Longitude : 1110670530 degrees
    Latitude : 1112474957 degrees
    
    
    Longitude : 1113554218 degrees
    Latitude : 1112255733 degrees
    



    Even If I assumed a decimal place it isn't close to my location(i have found it on my gps). Any other ideas?

    Thanks,


    Tyler
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-11 11:58
    Are you sure that the GPS_SmartMode object that you're using was written for your GPS and not an earlier model? The only one I can find online was written in 2007. Please post the GPS_SmartMode object that you're using.

    -Phil
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-03-11 13:39
    The one I'm using was written in 2007, but the BS2 demo for the new and old GPS module are the same. It seems therefore that the Propeller demo written for the other should be acceptable. Correct me if i'm wrong please.

    Thanks,

    Tyler
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-11 13:56
    The 2007 version I'm looking at uses 4800 baud and sends commands to the GPS in the form "!GPS". That's both the wrong baudrate and wrong command for the GPS unit that you have. So, again, please post the object that you're using.

    -Phil
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-11 14:19
    Use this to test. It was written for and tested with the VPN1513 unit. Note it uses 9600 bps to communicate with the GPS unit rather than 4800 of the older model. As Phil surmises, this is very likely your problem. No additional objects are required other than those that come with the Propeller tool. The output is Google Maps friendly.

    !GPS is still the command word to use with this unit. Not sure what Phil was looking at there.

    Please also note the unit requires 5V to 12V (won't run reliably at 3.3V as it has its own 3.3V voltage regulator) but its I/O pin is 3.3V friendly, having already a suitable 1K series resistor.
    OBJ
    
      PST    :  "FullDuplexSerial"
      GPS    :  "FullDuplexSerial"
    
    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      GetLat   = $05
      GetLong  = $06
    
    PUB main 
    
      PST.start(31, 30, 0, 115200)
      GPS.start(0, 0, 00, 9600)                ' GPS connected to pin0
       
      repeat
        GPS.str(string("!GPS"))                   ' GPS command header
        GPS.tx(GetLat)                            '  for latitude  
        WriteVal
       
        PST.str(string(",")) 
        GPS.str(string("!GPS"))                   ' GPS command header
        GPS.tx(GetLong)                           '  for longitude 
        WriteVal
        PST.str(string(13))
        WaitCnt(ClkFreq + Cnt)                    ' Wait 1 second
      
    PRI  WriteVal | Degrees, Minutes, MinutesD, Dir, workVal
    
      WaitCnt(ClkFreq / 10 + Cnt)                 ' 1/10 second wait
    
      Degrees := GPS.rx                           ' Retrieve bytes from GPS
      Minutes := GPS.rx
      MinutesD := (GPS.rx << 8) | GPS.rx
      Dir := GPS.rx==1
      
      if dir == -1                                ' If Dir = -1, prepend - sign
        PST.str(string("-"))
      PST.dec(Degrees)
      PST.str(string("."))
    
      workVal := (Minutes * 1000 / 6) + (MinutesD / 60)
      PST.dec(workVal) 
    
    

    -- Gordon
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-03-11 14:37
    @Phil- sorry i don't have access to my computer right now that is why I wasn't able to post the object, but it is the one written in 2007 that you mentioned.

    @Gordon- thanks I'll look at that code when I get a chance(I'm responding on my iPod touch right now). I'll post the results of your code. Wish me luck!

    As always Thanks,


    Tyler
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-11 15:26
    !GPS is still the command word to use with this unit. Not sure what Phil was looking at there.
    Odd that "!GPS" is not mentioned in the 28506 PDF anywhere. All that's listed there are command codes ranging from 0x00 to 0x0A.

    -Phil
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-03-11 21:04
    @Gordon I tested out your code and it just gave me 33.12175 for the longitude and latitude over and over again. It's very strange. Do you know why this is? and how could it be fixed??

    Thanks,

    Tyler
  • Ken GraceyKen Gracey Posts: 7,400
    edited 2012-03-11 21:44
    Hey Tyler, it's really odd that the GPS reports data and that the data is incorrect. As you guys continue to debug this system, feel free to drop me a line if you think you need a replacement to this unit. It seems like a code situation but we don't make these chips [just source them] so I really couldn't definitively say that it's entirely functional. However, that particular unit would have passed our internal tests to properly identify its location after it was manufactured.

    Ken Gracey
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-11 22:50
    @Gordon I tested out your code and it just gave me 33.12175 for the longitude and latitude over and over again. It's very strange. Do you know why this is? and how could it be fixed?

    It could be in the formatting of the code. Compare the indenting shown in the code here with yours. As you didn't provide the actual output (you can copy and paste, as you did before) it's hard to know from just your short description. It helps if you're as specific and complete as possible.

    Apart from that, is 33.12175 correct for your latitude? That would be helpful info. (Or is it your longitude, and you're in eastern Europe or some such?)

    You can also switch to /RAW mode, and just read the sentences as they stream into the Propeller. This is a great way to verify proper operation of any GPS module.

    Phil, The docs on this one are a little scant. The BS2 code was updated (the main change was the baud rate), but for whatever reason the additional detail that was in the 28146 docs were omitted for the replacement unit.

    -- Gordon
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-03-11 23:17
    @Gordon- Thanks here's the output:
    33.12175, 33.12175
    
    33.12175, 33.12175
    
    33.12175, 33.12175
    
    33.12175, 33.12175
    
    33.12175, 33.12175
    
    33.12175, 33.12175
    
    33.12175, 33.12175
    


    No my position isn't 33.12175 lat or long(I'm in California). The you provided code seems to reports data even when the gps isn't connected. The wire to the antenna is very loose and I'm worried that the gps antenna isn't send data to the module or being grounded properly. Would the gps light go solid even if the gps antenna isn't enjoying a good connection?

    @Ken- Thanks for the info. If it is deemed to be a bad module I'll have it replaced, but I how it is user error on my part :)

    Thanks,


    Tyler
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-12 09:34
    No my position isn't 33.12175 lat or long(I'm in California).

    That latitude is valid for California (north San Diego county, parts of Imperial county), so without knowing what it's supposed to be anything I suggest is just guessing.

    The only thing I can say is to check the usual things:

    1. Don't connect /RAW (let it float high, so it's in Smart Mode).
    2. Be sure you're powering it from an *adequate* 5V supply (not 3.3V)
    3. Recheck the wiring to the GPS (the example I provided assumes the GPS is on pin 0.)

    etc.

    You may also want to simply try receiving the GPS in raw mode at 4800. Pull /RAW low, reset power to the GPS, and see if you get what looks like valid sentences. You'll see sentences that should include your location (but it's not Google Maps ready).

    The antenna on this is a bit loose (I wouldn't classify it as "very loose"). It just snaps on. If you get satellite lock within a minute or so then it should be fine.

    -- Gordon
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-03-12 09:53
    @Gordon- Thanks i'll check all that when I get a chance. My Location is 35,-118(Approximately) so neither Lat or Long was right. I'll check those things and try again.

    Thanks,

    Tyler
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-12 10:10
    You may also want to simply try receiving the GPS in raw mode at 9600.
    I assume you meant to say "4800." According to the doc:
    "RAW: Selected by pulling the /RAW pin LOW. When low, the module outputs raw NMEA0183 strings @ 4800 baud."

    -Phil
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-12 11:26
    I assume you meant to say "4800."

    Yes, that's correct. Should be 4800 baud. I edited original post as well.

    -- Gordon
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-12 11:51
    @Gordon- Thanks i'll check all that when I get a chance.

    I looked at the posted code and I see the forum software lobbed off some characters. The line should read:

    GPS.start(0, 0, (percent sign)1100, 9600)

    where the (percent sign) is %.

    In case there's anything else missing I'm posting it, as well.

    For a more robust test, you might want to go back to the smart mode object you started out with, changing it to 9600 baud (edit GPS_SmartMode.spin), and trying that again. That demo provides more data. The one I posted just gives latitude and longitude only.

    -- Gordon
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-12 12:05
    I don't know why the got chopped off. In case there's anything else missing I'm posting it, as well.
    That's really weird. I was all ready to send Bump an email about it. But, when I tried it myself, I couldn't get it to screw up:
    OBJ
    
      PST    :  "FullDuplexSerial"
      GPS    :  "FullDuplexSerial"
    
    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      GetLat   = $05
      GetLong  = $06
    
    PUB main 
    
      PST.start(31, 30, 0, 115200)
      GPS.start(0, 0, %1100, 9600)                ' GPS connected to pin0
       
      repeat
        GPS.str(string("!GPS"))                   ' GPS command header
        GPS.tx(GetLat)                            '  for latitude  
        WriteVal
       
        PST.str(string(",")) 
        GPS.str(string("!GPS"))                   ' GPS command header
        GPS.tx(GetLong)                           '  for longitude 
        WriteVal
        PST.str(string(13))
        WaitCnt(ClkFreq + Cnt)                    ' Wait 1 second
      
    PRI  WriteVal | Degrees, Minutes, MinutesD, Dir, workVal
    
      WaitCnt(ClkFreq / 10 + Cnt)                 ' 1/10 second wait
    
      Degrees := GPS.rx                           ' Retrieve bytes from GPS
      Minutes := GPS.rx
      MinutesD := (GPS.rx << 8) | GPS.rx
      Dir := GPS.rx==1
      
      if dir == -1                                ' If Dir = -1, prepend - sign
        PST.str(string("-"))
      PST.dec(Degrees)
      PST.str(string("."))
    
      workVal := (Minutes * 1000 / 6) + (MinutesD / 60)
      PST.dec(workVal)
    

    Which browser and OS are you using?

    -Phil
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-12 12:32
    Which browser and OS are you using?

    Try editing your post, and see what happens.

    Anyway, I'm using WinXP/SP3 and Firefox (latest whatever). Funnily enough, I get a Unicode symbol box when I view your quote of my post in Firefox, and nothing (a blank space) when I view in Chrome. (Same characters appear in View Source). However, your post of the code shows the percent character.

    Same thing happens when I view the page on a Mac with Firefox.

    Maybe you have extra posting privileges, being a VIP and all.

    Just to test, I'm going to post the line again with the percent sign, and leave it to see what happens now (I won't edit this post either way):

    GPS.start(0, 0, $1100, 9600)

    -- Gordon
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-12 13:12
    Gordon,

    I edited my post, and nothing changed. I, too, am using WinXP/SP3 and latest Firefox. I use the plain-text editor, though, not the fancy one. Maybe that's the difference. BTW, your percent sign got changed to a dollar sign in your previous post.

    -Phil
  • cavelambcavelamb Posts: 720
    edited 2012-03-12 13:44
    Really dumb obvious question to the O.P.?

    You ARE outside when you run this?
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-12 16:08
    On this unit the satellite lock LED is (I think) under the control of the Prop chip on the board. If the satellites are in lock, the data should be good. However, this could be an issue with the firmware. I had only one unit to test, and it seemed to lock quickly, and indoors. My location indoors is typically within 4-5 feet of a window, and my house uses wood construction and older paper-backed fiberglass insulation. Offices and homes with aluminum construction, and/or aluminum-backed insulation, may not fare as well.

    In my tests, accuracy with this unit was always within six feet of my actual location inside my house, as displayed in Google Maps. In fact, it was always more accurate than the GPS in my iPhone. With my iPhone I apparently live two houses down the street.

    Try the revised code with the proper mask for the serial port setup. That might do it. Download the spin file itself to avoid any possible errors in formatting of the posted code.

    -- Gordon
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-12 16:11
    Phil, I posted some tests in the Test forum. I got the problem again when I edited the post. This might be an issue related to posting privileges.

    -- Gordon
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-03-12 16:29
    @Gordon- Thanks the updated code works perfectly! I think that it was the lack of the percent as you said in your post. Hopefully soon i'll be give back to the propeller community(Im a noob:smile:).

    Thanks Again,

    Tyler
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-12 16:30
    Gordon,

    I don't have any special or unique posting privileges. Are you using the fancy editor, or the plain text editor? If the former, try the latter to see if there's any difference.

    Tyler,

    'Glad you got it working!

    -Phil
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-12 18:32
    Looks like it was the enhanced editor. I'll make a new test in the Test forum, again with editing the post afterward, and we'll see what we'll see.

    Tyler, Glad it's working now. This GPS is a nice unit, especially as you can tweak the firmware. The existing code is on the shopping page for the GPS. It's not commented much (if at all) though. It's not terribly complicated, fortunately.

    -- Gordon
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-03-14 09:29
    Hello All! Sorry to reawaken this thread, but i'm trying to get the heading now. What do I have to do to recieve this as it isn't a number it is a "Word"(according to the documentation). What would be the procudure to recieve a word from the module?

    Thanks,

    Tyler
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-14 09:48
    The module sends one byte at a time, so you send the command request for heading, then receive two bytes. The two bytes together make a word. You need to shift the first (high) byte into the variable, then add (or OR) the low byte. The code I posted earlier demonstrates this for the decimal minutes value:
    MinutesD := (GPS.rx << 8) | GPS.rx
    

    Note that heading is usually not accurate unless you're moving, and even then, it's still often off by several degrees. So if you get incorrect or inconsistent results that's probably the reason. You need a magnetometer to get accurate compass headings.

    For other values returned and how to handle them look at the smart gps object you originally started with.

    -- Gordon
Sign In or Register to comment.