One of the fundamental technologies of modern gadgets is the Global Positioning System (GPS). Using signals from satellites orbiting the earth, a GPS receiver can pin down its location with remarkable accuracy: the latest generation of Civilian Navigation Signals (CNAV) sent by the US GPS system has an accuracy of less than half a meter (about 3 feet). These signals also contain the time, accurate to within milliseconds, which makes it perfect for off-line dataloggers and systems that require very accurate timing. That’s a powerful combination that has made GPS one of the main technologies behind the mobile revolution, because it lets gadgets know where (and when) they are.
The Origin of GPS
The idea of GPS dates back a long way. The very first GPS system went live in 1964: using five satellites, the TRANSIT system was created by the US Navy to help Polaris missile subs navigate. The modern GPS system was developed starting in 1973, and went live with the first satellites in 1978. Although the military built and ran these systems (the US Air Force now runs the GPS system) they were designed to be used by civilians as well as the military. The first civilian handheld GPS receiver was the Magellan NAV 1000, sold in 1989 for a cool $3000. Initially, the civilian signals were encrypted using a system called Selective Availability (SA) that restricted their accuracy for civilian users, but this was removed in 2000 after a Korean airliner wandered into Russian airspace thanks to a faulty navigation system and was shot down.
Over the years since, the GPS system has been upgraded repeatedly to replace old satellites and add new signals and technologies. Now, the GPS system is composed of 24 active satellites (and a few spares), 11 of which are the latest generation models (called Block IIF). The next generation of them is due to be launched starting in 2016.
The US is no longer the only game in town, though: the Russians have created their own system (called GLONASS) which has 24 satellites. The Chinese are also rolling out their own navigation system called BeiDou, which currently has 10 satellites in orbit. The European Union is also building another system called Galileo, which will offer a similar location service.
This is a bonus for users: by using multiple GPS systems, you can pin down the location even more accurately, or still navigate if one is not available. Many modern GPS receivers can use both the GPS and GLONASS networks, and ones that use the other networks will be coming out soon, because they all work in much the same way: by measuring the time the signal takes to reach the receiver.
How GPS Works
The modern GPS system sends out a number of signals on different frequencies for different users and redundancy, but they all work on the same basic principle. The original signals were on two frequencies (L1 at 1575.42MHz, and L2, at 1227.6MHz) but other frequencies (L3 at 1381.05MHz, L4 at 1379.913MHz and L5 at 1176.45MHz) have been added since. These newer ones are used for things like analyzing the atmosphere to see how that affects the signal, further increasing the accuracy on devices that can receive them. Most single-chip systems only use the L1 signal.
Each satellite encodes streams of data into these signals, created from an onboard atomic clock and an individual code number for each satellite. This encoding creates a pseudo-random stream of data: it looks random, unless you know the code numbers for each satellite (called the gold code). With this, you can decode the various streams of data, which include the Coarse/Acquisition (C/A) stream, the L1 Civilian (L1C) and the Military (M) stream. Each of these streams of data contains about 50 bits per second of data. As the name suggests, the C/A stream is a short, frequently repeated batch of data for coarse navigation. The other streams contain more detailed data that allows for more precise location, but which takes longer to receive. These streams contain a lot of data, but the most useful part is the time, taken from the very accurate atomic clock onboard the satellite. The GPS receiver uses this precise time data to determine the location by looking at the difference between the signals of several satellites.
Imagine this scenario: one GPS satellite is overhead, about 12,000 miles above you. Another is lower on the horizon from your point of view, meaning it is in another orbit and is further away: it could be up to 30,000 miles away. The signal from the horizon satellite will have further to travel, so it will take longer to reach you. If you know that both satellites have clocks that are set at the same time, you can determine the distance between the two satellites by measuring the difference between the time signals the two send. The difference will be small (less than 90 milliseconds), but it is measurable. Add in a third satellite in another location, and you’ve got another distance, forming a triangle. The receiver also knows the orbit of the satellites (called the ephemeris), so by combining the time and the distance between at least three satellites, it can work out its location. Add in a fourth satellite to provide more data and it can also calculate its altitude.
The signals from the GPS satellites also contain lots of other data, such as the updated ephemeris for all of the satellites, and information on how the atmosphere is affecting the signals. The GPS receiver receives and stores this data, using it to update its list of satellites. That’s why a GPS receiver that hasn’t been used for some time often takes a long time to fix the location (called a cold fix): if there have been new satellites launches or other changes it doesn’t know about, it can take some time to spot the signals and capture the new info.
These days, all of this complex signal processing and mathematics is usually wrapped up into a single chip: a GPS receiver that receives the signals, processes them and runs the numbers. How many satellites they can keep track of at any one time depends on the type, but a receiver that can keep track of a lot will be better placed to keep figuring out the location as satellites drop below the horizon, and new ones come into view. The motion of the satellites also changes the frequency (because of the doppler effect), so a receiver may need to listen on multiple frequencies to pick up satellites that are moving towards and away from the receiver. The ability to track an individual signal is called a channel, and most modern receivers have lots of these: the Mediatek MTK3339 GPS chip on the Adafruit Ultimate GPS Breakout board, for instance, has 66 channels, so it can track multiple satellites on multiple frequencies.
The end result of all of this is that the GPS receiver finds the location, and then feeds this out to the device. For most GPS chips, this is sent in the form of a serial output that sends the data in a format called NMEA 0183 (NMEA means the National Marine Electronics Association, who set standards for electronic systems on ships). This data can contain the current time, location, speed and other information, sent in plain text. Information on the signal strength of the various satellites is also sent, so the device processing the data can display it.
How To Use GPS
The easiest way to add GPS to a device you are building is to add in a GPS package. These include the antenna, the receiver and enough smarts to do the calculations. You simply power the chip, give it a view of the sky, and it outputs the time, location and other information. Thanks to the years of development on GPS and mobile devices, these are cheap: Adafruit offers a breakout board that includes the Mediatek MTK3339 GPS chip for less than $40. Other similar devices are available from Sparkfun, who also have a good guide to the different types. These devices have a built-in antenna, but they are small and may not receive the signals well. For better performance, add an external antenna that can receive more of these weak signals.
The particularly masochistic among you might want to try building your own GPS receiver. It is possible, although it does require some expensive equipment. You will need a Software Defined Radio (SDR) that can receive the 1.5GHz frequency, and some software to decode the signals. In the video below, [Taroz] is using a BladeRF SDR and the GNSS-SDRLIB software that he wrote.