3D Robotics

Using the 5Hz Locosys GPS with Arduino/ArduPilot

Sparkfun is now selling the excellent 5Hz Locosys (Mediatek chipset) GPS that Dean Goedde uses in ArduPilot. We're developing a daughterboard that will allow this 3.3v module to be a plug-and-play replacement for the 5v, 1Hz EM406 GPS that we're currently using for ArduPilot. In the meantime, if you want to start playing with a 5Hz GPS with Arduino here's some code and instructions to get you started.
The code is Jordi's new NMEA parser for the Locosys GPS. It's checksum verified, rocksolid, continuous, no delays, loop rate is about 32000hz. It uses pointers, so it's efficient.

You have to configure the Locosys for the first time you use it. It's very easy, you just need an FTDI cable. Be sure to connect the GPS to a 3.3 volt source. (We'll do this setup for you in the commercial version)


Instructions (please use the picture above as reference):

1-Run Realterminal and open the port @4800bps, you should see all the NMEA stuff, is not check the connections..
2-Now make sure you have checked the options marked with the green arrow... +CR +LF
3-Copy and paste this code: $PMTK251,38400*27 to the box indicated with the red arrow.
4-Then click the "Send ASCII" button indicated with the blue arrow..
5-Then the NMEA should disappear, and starting showing strange values. Go back to the "Port tab" (yellow arrow),
close the port, and choose the Baud "38400", and open the port again. You should the NMEA data again... =)
6- Then go back to the "Send" tab, and copy&paste this code: $PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28 then click Send, this should turn Off all sentences except GGA and RMC
7-Copy&paste now this code: $PMTK220,200*2C This should increase the updates to 5hz... (WOW!!!)..
8- Now you are able to connect the GPS module to Arduino, (only connect the RX pin to the TX of the GPS)
9-Then upload the code above, and open the port monitor, you should see Lat, Lon, Course, Speed, Altitude, Fix Position... like this:
46024504 8050998 312 0 519 1 (and yes you now know the exact position of my Swiss Chalet =P)...

If you want other setup codes for this GPS, you can find them in this datasheet.

Code explanation

If you'd like to understand the NMEA parser code a bit better, here are some of the library functions that it calls (all from the standard C++ library):

  • First of all pointers, which are very easy. They just give you the memory address where a variable is allocated in the ram: info
  • Then the strncmp(), better know as String Comparator. We use it to compare the header of the NMEA string "$GPGGA": info
  • Then strtl(), which means String to Long Variable. It converts a string number into a long variable: info
  • Then the strtok(). This is the string tokens, which looks for tokens in a string, for example commas ",", the ones used to separate values in the NMEA sentence: info
  • The atoi() will convert strings to integers: info
  • If you want to know all the available functions, see the library called "strings.h", "stdlib.h": info and info
(All these libraries are already installed in the Arduino IDE.)
E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones

Comments

  • Still about the 5Hz Locosys (Mediatek chipset) GPS...
    Could anyone please explain to me how the checksum at the end of every NMEA sentense is calculated ?
    This point is not covered in the data sheet.
    Thanks,

    Yann
  • Thanks for your answer. I did a cable that works for 5v. I'll have to modify it for 3.3v. I soldered the small PCB at one end and sunk it in epoxy. No big deal.
  • 3D Robotics
    Realterm

    If you can build your own TTL-level serial cable that works, my hat's off to you.
  • Hi guys,
    I just bought a 5Hz Locosys (Mediatek chipset) GPS.
    Where do I get Realterminal to properly set the GPS module ?
    Do I really need an FTDI cable or can I use a regular serial cable with level shifter ?
    Thanks,

    Yann
  • @ Ben: yes, I think the meant FTDI is the one you mention.
  • Hi again. As I said before, I awaited information on MTK commands for the Locosys LS20031. I got them a few days ago but forgot to post them here for those interested. they issued only MTK commands for which there's an agreement for public release.
    MTK NMEA PROPRIETARY COMMAND.pdf
  • Hi there. Fairly new to GPS and microcontrollers. When you mention the FTDI cable to initially program this what actually is this? Is it http://www.sparkfun.com/commerce/product_info.php?products_id=8772 or something else?

    Thanks
  • I just mailed Locosystech to ask for complete MTK proprietary message references applied to the LS20031 unit. As soon As I get feedback, I'll post whatever they send me.
  • Update - I just got this info from Locosys. Now it would be nice to get the manual from which this was extracted ...

    ========================================

    Packet Type: 390 PMTK_API_SET_USER_OPTION

    Packet Meaning: API_Set_Flash_User_Option

    Write the user setting to the flash to override the default setting. Maximum 8 times without erase the chip.

    DataField: PMTK390, Lock, Update_Rate, Baud_Rate, GLL_Period, RMC_Period, VTG_Period, GSA_Period, GSV_Period, GGA_Period, ZDA_Period, MCHN_Period, Datum, DGPS_Mode, RTCM_Baud_Rate

    Lock: nonzero: freeze the setting; 0: allow further setting
    Update_Rate: 1~5 (Hz)
    Baud_Rate: 115200, 57600, 38400, 19200, 14400, 9600, 4800
    RTCM_Baud_Rate: 115200, 57600, 38400, 19200, 14400, 9600, 4800
    XXX_Period: NMEA sentence output period
    DGPS_Mode: 0 (disable), 1 (RTCM), 2 (SBAS)
    Datum: We support more than 200 datum. Please refer to Appendix A for the supported datum list. The typical value is: 0 (WGS84), 1 (Tokyo-M), 2 (Tokyo-A)

    Example:
    $PMTK390,0,5,57600,1,1,1,1,1,1,0,0,0,2,9600*04
  • Another question - I see the definition for $MPTK314 in the datasheet referenced above, but where did you find definitions for $PMTK220 and $PMTK251 ?
This reply was deleted.