
282
|
Chapter 5, Mapping with Gadgets
#62 Build a Car Computer
HACK
Regardless of what operating system you choose, you can always have fun
writing custom code to integrate with your mobile computer. When start-
ing on a project like this, some of the newer high-level languages can make
for a rapid and painless development experience. Python is a perfect exam-
ple of this and, as you will see in the following examples, can be used to
build a visual GPS plotter with only a few pages of code.
Connecting a GPS to Your Car Computer
If you have access to a GPS with a serial interface, it is quite easy to extract
latitude and longitude into your computer. Just about all GPS devices sup-
port a protocol called NMEA-0183 (National Marine Electronics Associa-
tion), which is streamed over the serial port at 4800 baud. The NMEA-0183
protocol is text-based and quite easy to parse. You can use the following
Python code to connect with a GPS or explore gpsd, which provides a server
interface to the GPS. gpsd is described in
“Connect to Your GPS from
Multiple Applications”
[Hack #57]. NMEA consists of various sentences with
data fields separated by commas. Each line of a NMEA sentence starts with
a
$ and a sentence type. Each sentence type provides different information in
the fields that follow the sentence-type designator. Here is what a typical
stream looks like:
$GPVTG,269.6,T,250.8,M,019.9,N,0036.8,K*76
$GPRMC,011106,A,4742.1321,N,12221.2108,W,021.0,270.5,240804,018.9,E*67 ...