gps – hardware

Programming

gps – hardware

where am i?

Just after latitude and longitude? Check out my earlier post for refresher on how to extract latitude and longitude from a file containing the $GPGGA nmea sentence using awk.

Lets connect up the ublox gps module to the arduino. There are four pins, Vcc, RX, TX and GND. My module accepts 5v on Vcc, and 5v logic on TX and RX.

ublox gps connected to arduino
void setup(){}
void loop(){}

That’s it

The arduino is doing very little here; we are leveraging its built-in USB-TTL serial convertor to get the gps information to our laptop. A nice alternative to the “arduino-in-the-middle” approach would be to use a usb to TTL cable, like this one by adafruit.

Plug the arduino into the computer in the usual way and upload the code. We can check what the gps module has to say by either using the arduino IDE serial monitor window, or straight from the command line. My gps communicates at a baud rate of 9600.

$ stty -F /dev/ttyACM0 raw 9600 -hupcl

$ head -2 /dev/ttyACM0
7,2930,57,154,25*7A
$GPGLL,3200.25950,S,11553.63112,E,005321.00,A,A*7F

$ ./latlon.awk /dev/ttyACM0
-32.0043,115.894

I’ve added -hupcl to the stty command to prevent the arduino from resetting whenever we send a command to it (there are other ways of managing this which we might explore later). After setting the correct baud rate with stty, we can use head to see what the gps is saying. Try running that command a few times, note that sometimes the first line is incomplete.

Finally, we call the latlon.awk script we made earlier with the arduino device name as the input and get our latitude and longitude returned. That worked nicely!

Note, if you are getting 0,0 for your latitude and longitude it is likely that your gps hasn’t yet got a satellite fix. Try positioning your gps antenna closer to a window, or go outside.

Now that we have a piece of functioning hardware, we can improve on the software implementation. Next time.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.