Moving Forward with Arduino – Chapter 17 – GPS
This is part of a series originally titled “Getting Started with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.
Updated 23/01/2013
In this instalment we will introduce and examine the use of the Global Positioning System receivers with Arduino systems. What is the GPS? In very simple terms, a fleet of satellites orbit the earth, transmitting signals from space. Your GPS receiver uses signals from these satellites to triangulate position, altitude, compass headings, etc.; and also receives a time and date signal from these satellites. The most popular GPS belongs to the USA, and was originally for military use – however it is now available for users in the free world.
Interestingly, the US can switch off or reduce accuracy of their GPS in various regions if necessary, however many people tell me this is not an issue unless you’re in a combat zone against the US forces. For more information, have a look at Wikipedia or the USAF Space Command GPS Ops Centre site. As expected, other countries have their own GPS as well – such as Russia, China, and the EU is working on one as well.
So – how can us mere mortals take advantage of a multi-billion dollar space navigation system just with our simple Arduino? Easy – with an inexpensive GPS receiver and shield. When searching for some hardware to use, I took the easy way out and ordered this retail GPS pack which includes the required Arduino shield and header sockets, short connecting cable and an EM-406A 20-channel GPS receiver with in-built antenna:
For reference now and in the future, here is the data book for the GPS receiver: EM-406 manual.pdf. All you will need is an Arduino Uno or 100% compatible board, and the usual odds and ends. When it comes time to solder up your shield, if possible try and sit it into another shield or board – this keeps the pins in line and saves a lot of trouble later on:
And we’re done:
Please notice in the photo above the cable is a lot longer between the shield and the GPS receiver. This was an extra cable, which makes things a lot more convenient, and it never hurts to have a spare. Finally, on the shield please take note of the following two switches – the shield/GPS power switch:
and the UART/DLINE switch:
For now, leave this set to UART while a sketch is running. When uploading a sketch to the board, this needs to be on DLINE. Always turn off your GPS shield board before changing this switch to avoid damage. Example 17.1 – Is anyone out there? Now, let’s get some of that juicy GPS data from outer space. You will need:
- Arduino Uno or compatible board
- a suitable GPS setup – for example the GPS shield bundle
Once you have your hardware assembled, upload the following sketch. Now for desk jockeys such as myself, there is a catch – as a GPS receives signals from satellites the receiver will need to be in line of sight with the open sky. If you have your desk next to a window, or a portable computer you’re in luck. Look at the LED on your GPS receiver – if it is blinking, it has a lock (this is what you want); on - it is searching for satellites; off - it is off (!). The first time you power up your receiver, it may take a minute or so to lock onto the available satellites, this period of time is the cold start time.
This will be in ideal conditions – i.e. with a clear line of sight from the unit to the sky (clouds excepted!). Once this has been done, the next time you power it up, the searching time is reduced somewhat as our receiver stores some energy in a supercap (very high-value capacitor) to remember the satellite data, which it will use the next time to reduce the search time (as it already has a “fair idea” where the satellites are). Now open the serial monitor box, sit back and wait a moment or two, and you should be presented with something very similar to this:
What a mess. What on earth does all that mean? For one thing the hardware is working correctly. Excellent! Now how do we decode these space-signals… They are called NMEA codes. Let’s break down one and see what it means. For example, the line: $GPRMC,165307.000,A,2728.9620,S,15259.5159,E,0.20,48.84,140910,,*27 Each field represents:
- $GPRMC tells us the following data is essential point-velocity-time data;
- 165307.000 is the universal time constant (Greenwich Mean Time) – 16:53:07 (hours, minutes, seconds). So you now have a clock as well.
- A is status – A for active and data is valid, V for void and data is not valid.
- 2728.9620 is degrees latitude position data = 27 degrees, 28.962′
- S for south (south is negative, north is positive)
- 15259.5159 is degrees longitude position data = 152 degrees, 59.5159′
- E for east (east is positive, west is negative)
- 0.20 is my speed in knots over ground. This shows the inaccuracy that can be caused by not having a clear view of the sky
- 48.84 – course over ground (0 is north, 180 is south, 270 is west, 90 is east)
- 140910 is the date – 14th September, 2010
- the next is magnetic variation for which we don’t have a value
- checksum number
Thankfully the data is separated by commas. This will be useful if you are logging the data to a text file using a microSD shield, you will then be able to use the data in a spreadsheet very easily. Later on we will work with data from other codes, but if you can’t wait, here is the NMEA Reference Manual that explains them all. In the meanwhile, how can we convert the location data (longitude and latitude) received into a position on a map?
- Visit this website
- In the box that says “paste your data here”, enter (for example, using my data above)
name,desc,latitude,longitude home,home,-2728.9660,15259.5143
For example:
Then click “Draw the Map”, and you will be presented with a Google map in a new window that you can zoom around in, change views and so on. Interestingly enough the coordinates returned in the test above were accurate down to around three meters. Later on that website will be of great use, as you can import text files of coordinates, and it will plot them out for you. If you use this mapping site a lot, please consider making a donation to help them out. Now as always, there is an easier way. The purpose of the previous demonstrations were to see the raw data that comes from a receiver, and understand how to work with it.
Moving on… now we can receive GPS signals – and in the past we have used LCD modules – so we can make our own variations of portable (!) GPS modules and other devices. At this point you will need to install another Arduino library - TinyGPS. So download and install that before moving forward.
Example 17.2 – My First GPS
Using various pieces of hardware from the past, we will build a simple, portable unit to display our data.
You will need:
- Arduino Uno or compatible board
- a suitable GPS setup – for example the GPS shield bundle;
- An LCD with HD44780 interface that has the ability to connect to your Arduino system. The size is up to you, we’re using a 20 x 4 character unit. If you have dropped in or are a bit rusty on LCDs, please read chapter twenty-four;
- An external power supply for your setup (if you want to walk up and down the street at midnight like I did) – for example, a 9V battery snap soldered to a DC plug is a quick and dirty solution!
Luckily I have made an LCD shield in the past which works nicely, and doesn’t use digital pins D0 and D1 – these are used by the GPS shield to get the data back to the Arduino. Therefore the whole lot just plugged in together as shields do. Here is the sketch for your consideration. Before uploading the sketch, turn off the GPS shield, set the DLINE/UART switch on the GPS shield to DLINE, upload the sketch, then set it back again, then back on with the GPS shield.
So here it is all thrown together in my lunch box:
And a close-up view of the LCD. There was not room for the course data, but you can modify the sketch accordingly. The data will be a little off due to the photo being taken indoors:
Now for some outdoor fun. In the video clip below, we take a ride on the bus and see our GPS in action…
I had to take an old bus that wasn’t full of security cameras, so the ride is bumpy:
As we have a lot of electronics in this setup, it would be interesting to know the current draw – to help plan for an appropriate power supply. The trusty meter gives us:
Wow – a maximum of 122 milliamps even with that LCD backlight blazing away. So when we make some GPS logging devices without such a monstrous LCD, we should be able to get the current draw down a lot more.
The purpose of this example was to show how you can manipulate the data from the GPS receiver. We continue with GPS part II here.
September 17, 2010 - Posted by John Boxall | arduino, beginnner, education, GPS, GPS-09123, learning electronics, microcontrollers, RTL-10709 | 0183, 406, 406A, acceleration, altitude, arduino, compass, data, DIY, EM, EM-406, EM-406A, global, GPS, GPS-09123, guide, guides, heading, III, lesson, lessons, libraries, library, logging, microSD, microSD shield, navigation, newsoftserial, NMEA, pack, positioning, receiver, RTL-10709, shield, Sirf, SirfStarIII, sparkfun, speed, star, system, tinygps, tracker, tracking, tronixstuff, tutorial, tutorials
13 Comments »
Leave a Reply Cancel reply
YouTube
Visit tronixstuff on YouTube for our range of videosClock Projects
Zero - blinky the clock
One - DMD clock
Two - Single digit clock
Three - Pillow clock
Four - Scrolling text clockArduino Tutorials
Click for Detailed Chapter Index
Chapters 0 1 2 3 4
Chapters 5 6 6a 7 8
Chapters 9 10 11 12 13
Ch. 14 - XBee
Ch. 15 - RFID - RDM-630
Ch. 15a - RFID - ID-20
Ch. 16 - Ethernet
Ch. 17 - GPS part I
Ch. 18 - RGB matrix
Ch. 19 - GPS part II
Ch. 20 - I2C bus part I
Ch. 21 - I2C bus part II
Ch. 22 - AREF pin
Ch. 23 - Touch screen
Ch. 24 - Monochrome LCD
Ch. 25 - Analog buttons
Ch. 26 - Arduino + GSM - part I
Ch. 27 - Arduino + GSM - part II
Ch. 28 - Colour LCD
Ch. 29 - TFT LCD
Ch. 30 - Arduino + twitter
Ch. 31 - Inbuilt EEPROM
Ch. 32 - Infra-red control
Ch. 33 - Control AC via SMS
Ch. 34 - SPI bus part I
Ch. 35 - Video-out
Ch. 36 - SPI bus part II
Ch. 37 - Timing with millis()
Ch. 38 - Thermal Printer
Ch. 39 - NXP SAA1064
Ch. 40 - Push wheel switches
Ch. 40a - Wheel switches II
Ch. 41 - More digital I/O
Ch. 42 - Numeric keypads
Ch. 42a - Keypads II
Ch. 43 - Port Manipulation
Ch. 44 - ATtiny+Arduino
Ch. 45 - Ultrasonic Sensor
Ch. 46 - Analog + buttons II
Ch. 47 - Internet-controlled relays
Ch. 48 - MSGEQ7 Spectrum Analyzer
Arduino Due - first look
Ch. 49 - KTM-S1201 LCD modules
Ch. 50 - ILI9325 colour TFT LCD modules
Ch. 51 - MC14489 LED display driver IC
Search
RSS Feeds
Categories
Previous posts
Archives
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- October 2012
- September 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
Contact information
email - john at tronixstuff dot com
Google Group
Australian Electronics!
Buy and support Silicon Chip - Australia's only Electronics Magazine.Creative Commons
All the original material in this website, unless noted otherwise, is covered under a Creative Commons Attribution-Non Commercial-Share Alike v3.0 license. Please email me if you see any mis-attributions or would like to use my content in different circumstances.on twitter…
- Arduino IDE v1.0.5 has been released - arduino.cc/en/Main/Softwa… 1 day ago
- Interesting new website to show and share electronics projects - knickknack.co.nz 1 day ago
- Gorgeous Black-and-White Photos of Vintage NASA Facilities - brainpickings.org/index.php/2013… 1 day ago
- RT @nathanknz Look what arrived today! Teleduino can be found from page 344. #ArduinoWorkshop #Teleduino #IoT http://t.co/u4HdHhwB9W 1 day ago
- RT @nicegear John Boxall writer of loads of fantastic tutorials, wrote a book about Arduino. Go and check it out! nostarch.com/arduino 1 day ago
Flickr Photos



More PhotosFind me on…
Interesting Sites
David L. Jones' eev blog
Freetronics Arduino Geniuses!
Silicon Chip magazine Always a great read!
Amazing Arduino Shield Directory
The Amp Hour podcast
EEWeb Elec Engineering Forum
Superhouse.tv High-tech home renovation
Mr Dick Smith OANuclear weapons = global suicide
In a war with nuclear weapons, everybody loses. Please check these out:
Count Down to Zero
The War Game
Threads











Does anyone know what would need to be changed to make this work correctly with the latest Arduino software (at the time of posting, 1.0.3)?
You’re fine now, the GPS tutorials have been updated.
John,
I’m using a EM406A, but using a Sparkfun CAN-bus shield (https://www.sparkfun.com/products/10039). When I try to run your example sketch, nothing is returned… how do I fix this?
See the CANbus shield schematic: http://www.sparkfun.com/datasheets/DevTools/Arduino/canbus_shield-v12.pdf
Looks like you might need to close some pads on the PCB to get the data out via digital 4 and 5. Might want to probe it out with a continuity tester to double-check.
I’m trying to do this using an EB-85A receiver (https://www.sparkfun.com/products/8266), but I’m stuck. I put my setup out on my windowsill and later took it into the middle of a park; I tried your sketch along with two others I found, and it just never locks on no matter how long I wait. There were no tall buildings around, and the sky was mostly clear. The code compiles and uploads fine and the switches are all thrown in the right direction, but the red light just stays solid. Do I need to do something different since I’m using a different receiver? Any other ideas? The EM-406A seems to be the overwhelming choice for this kind of project, so I’m almost ready to order one and give up on this model. Thanks!
No idea – haven’t used that receiver. Try cranking the baud rate down to 4800 bps and the refresh rate to 1Hz. Not much help as Sparkfun have retired the EB-85A. My tutorial was written for the EM-406A which is somewhat different to your unit.
How or where can we get the math that converts the GPS data to points on a map or (more importantly) pixels on an LCD screen?
The code demonstrated in the tutorials gives out latitude and longitude – so there’s points on a map. You can use some maths to convert to pixel positions for your own screen.
If I wanted to get altitude , is that possible ?
Example 17.2
Hi John,
I tried using the GPS with the Colour LCD shield here
http://tronixstuff.wordpress.com/2011/02/07/tutorial-arduino-and-colour-lcd/
and it wouldn’t work. The GPS was getting data but was not printing to the LCD. Are there any conflicts between the GPS shield and the colour lcd shield ?
The LCD shield uses D3 for one of the buttons, and the GPS shield uses D3 for data TX. Bend out the D3 pin on the LCD shield to isolate it and try again.
Thanks John, that did the trick.