Shop Learn
Ublox GPS to Propeller — Parallax Forums

Ublox GPS to Propeller

Hi All,

I am working on using a Ublox GPS module with the Propeller. With @JRoark 's help I have the module configured and outputting a simple NEMA sentence. All my project requires is the time and date. I can trap for the beginning of the sentence ($GNMC) but the time is coming across as nonsense. I suspect that the time is output as a long or something. I attach the code and will try to cut and paste inline although I don't see the "C" button that used to let you post inline code with the formatting intact.

CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

LF = 10
CR = 13

input = 0
output = 1

gpsBaud = 9600
gpsMode = 0
gpsOut = 3
gpsIn = 16

VAR

byte month, day, hours, minutes, second
byte gpsData[77]

OBJ
gps : "fullduplexserialplus"
pst : "Parallax Serial Terminal"
' nixies : "SPI Engine"
'rf : "Simple_Serial"

PUB init | i
dira[15] := output
gps.start(gpsIn,gpsOut,gpsMode,gpsBaud)
pst.Start(115_200)
pst.clear
pst.home
wait_ms(2000)
pst.str(string("GPS Timebase..."))
pst.newline
pst.str(string("Version 0.2"))
wait_ms(1000)
repeat
get_gps
pst.newline
repeat i from 0 to 10
pst.dec(gpsData[i])
pst.str(string(","))
' pst.dec(hours)
'wait_ms(1000)

pub get_gps | i, temp1
' gpsSynch := 0
longfill(@gpsData,0,77)
wait_for_char("$")
wait_for_char("G")
wait_for_char("N")
wait_for_char("M")
wait_for_char("C")
repeat i from 0 to 10
gpsData[i] := gps.rxtime(1000)
if gpsData[i] == -1
gps_error
return
hours := gpsData[2]
minutes := gpsData[3]
' pst.str(string("got GPS..."))
return

pub wait_for_char(b): temp | t
repeat until temp == b
temp := gps.rxtime(1300)
if temp == -1
gps_error
return

pub gps_error
pst.clear
pst.home
pst.str(string("GPS not responding..."))
wait_ms(2000)
'init
return

PUB wait_ms(ms) '
waitcnt(cnt+(clkfreq / 1_000) * ms)
RETURN

PUB wait_us(us)
waitcnt(cnt+(clkfreq / 1_000_000) * us)
RETURN

Comments

  • JRoarkJRoark Posts: 876
    edited 2021-08-01 23:24

    Easy fix: To delineate your code blocks, preface them with three consecutive backticks and a CR. At the end of the code block do the same.

    What is a $GNMC message? I’ve never seen that one and Google is silent about that too. There is nothing in the uBlox docs either. This appears to be a non-standard proprietary message. You might use the $GPZDA message instead. This is the format:

    $GPZDA - Date & Time
    Gives UTC, day, month, year, and local time zone.
    
    $GPZDA,hhmmss.ss,xx,xx,xxxx,xx,xx
    hhmmss.ss = UTC 
    xx = Day, 01 to 31 
    xx = Month, 01 to 12 
    xxxx = Year 
    xx = Local zone description, 00 to +/- 13 hours 
    xx = Local zone minutes description (same sign as hours)
    

    All the best…

    EDIT: ah! You are thinking of the $GPRMC message maybe? If so, look closely at your code. You are missing the “R”. :)

    EDIT2: All NMEA-183 messages are strings and not binary data. They appear just as if you had typed them on a keyboard. So you need to convert from string to int (or whatever). I’d be a lot more help if I knew Spin, but alas I’m a creature of FlexBASIC. If you want to use BASIC, I’ve got code I can share.

  • Are you sure 9600 baud is correct? NMEA sentences are typically at 4800 baud. But some modules allow you to change that.

    -Phil

  • @"Phil Pilgrim (PhiPi)" said:
    Are you sure 9600 baud is correct? NMEA sentences are typically at 4800 baud. But some modules allow you to change that.

    -Phil

    The people from Switzerland are known to speak very slowly but their GPS is speaking faster than usual. Their standard baudrate is really 9600.

  • JonathanJonathan Posts: 1,023

    I am at work for my 50 hour shift and so am away from the project.

    @JRoark , I will check that it is indeed a $GNMC message. I think so. It is passing the trap. I am so out of the loop that I am not familiar with flexbasic but I would love whatever sample code you have as I did do a lot of basic programming at one time. I could either use flexbasic or translate it to Spin.

    It is odd, the output does change with the seconds ticking away but just rolls through a short pattern. When I am home I will screen shot some of it.

    @"Phil Pilgrim (PhiPi)" Yes, the module is set to 9600 baud, which is its default. If I hook a propplug up with the Parallax Serial terminal set to 9600 baud I see the NEMA sentence as I should. It is something to do with my picking those bytesw up and displaying them that is going wrong.

    Thanks for the help. I know it is something simple.

  • When I've done GPS code, I used the "Binary" mode on a Skytraq GPS. It was much easier to parse in SPIN. It may be worth looking to see if Ublox has a documented binary comm mode.

  • JonathanJonathan Posts: 1,023

    Week has been blowing by and I have to back to work early this week for a 72 hour shift.

    @Circuitsoft , I will look and see if the ublox has a binary mode. That is what I used on the old GPS for this project. I'm also going to go take a look for flexbasic.

  • JonathanJonathan Posts: 1,023
    edited 2021-08-12 15:29

    Aha. Looking at the data stream this morning I realized that I am in fact getting the bytes. They are in ASCII, with each number seperated, as in if the hours are 14 I get 49,52. I thought this is how my old one did it and that my code should deal with it. Sadly, I wrote it a long time ago and haven't used fullduplexserialplus for ages so I am having trouble doing the conversion. What I want to do is take the ASCII char pairs and put them together in a dec. I have done that in the past but I am still befuddled now.

    EDIT: Man, have I forgotten a lot! Goes to show use it or lose it. Of course I can just subtract 48 to convert to dec! Now I just have to remember how to combine the two numbers, like 1 and 4 into 14.

    EDIT 2: Glad I got back here before anyone wasted their time. Multiply the first char by 10 then add the second char.

Sign In or Register to comment.