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

  • hello...this is a great tutorial, it helped me get my LS20031 gps up and running.
    The only thing i noticed though was that the link with the code for the arduino was broken...is this permanent?
  • Hi all,

    Ok got the loco sorted today, got it workign well with ardu, however...strange thing...now the AP dowloads telemtry at 38400 not 57600, is this normal?

    Is the gps speed teh dictator for downlink speed? can we run the LS20031 at 57.6k as its capable, but ardu has no code for it?

    Found the conversion easy, but cant tell what its running at hz wise though, use the codes above and it looked like it slowed down, but i cant be sure..

    any ideas?

    regards.

    Mike.
  • I'm just short of time describing all my setup here, but basically, I was happy with my LS20031. I am running it at 2Hz for now. I disabled the automatic setup of the GPS by ArduPilot in the code. I prefer to have my setting stored once in the GPS board. I use some Python code to program it with from my PC with my FTDI cable.
    I made a custom plug with 4 male pins on the board which then fit in a turret just above the FMA XY sensor atop of the wing on my high wing trainer. I can take off the turret easily, it is held by 4 small magnets. You may see details here.
    A few time ago, I got a chance to get an updated version from Locosys directly of the same LS20031 at 10Hz update rate. Had no chance to test it yet, though, but this could be something for you.
  • HI Reto,

    Hmmm, things change fast around here....just there is a deal on in teh UK for the locosys gps`s for low cost, and and cant work out if they are easy to employ or a pain, how was your experience?

    if they are easy i will grab a couple, but holding off, until i can glean which set it uses? NMEA or Sirf etc, wether i can run it through with normal connector (with adaption and 3.3v applied) or wethere we need to re write the code to read the gps...im using the 406 at the mo but its not fast enough for our UAV, as its quick and wanders as the update requires 4+ hz (IMHO) i hve ordered the ublox, but as as stop in and a bit of fun, use the locosys.

    Would you mind givin me the low down on your experience and processes?

    regards,

    Mike.
  • Basically, this post was started 1 year ago, when the Ardushield wasn't here. I power my LS GPS from a separate 3.3v regulator, but it's also because I need that voltage for other equipment. I don't know if the shield's 3.3v supply can handle enough intensity for the GPS board to run properly. It could be, but I can't certify it.
  • HI all, just a quick question....

    been reading through about the locosys.....have i missed somthing, but there is 3.3v on the ardushield, cant that be used to power the locosys? there would be a common GND, and teh logic is converted on the shield....

    or have got this back to front?

    regards,

    Mike.
  • I need help getting this to work. I am using a Spakfun shifter board - com1. The GPS is running off a 3.3 regulator and I verified it is getting 3.3 volts. RX on the shifter going to TX on the gps, and vice-versa. Both realterm and hyperterminal at 4800bps and com1, nothing at all. realterm indicates a "break" at startup and then nothing afterwards. Any ideas?
  • For the record: the $PMTK390, did work for me, no more nail bitting with the locosys status at boot. The command I used was: $PMTK390,0,5,9600,0,1,0,0,0,1,0,0,0,0,9600*3D'
  • is the code for this unavailable now? It says access denied when i click on the link.
  • By the way, Locosys informed me the 10Hz updated Locosys L20031 modules (code MT3329) are almost ready to ship!!! I ordered one from Taiwan for USD 19.60 + paypal fee (USD 2) and EMS shipping to Europe (USD 22), total USD 43.60. ETD is mid-July. ll report back when I get it.
This reply was deleted.