In my previous article, GPS Bee Kit (Part 1), I have shown a few methods how to read NMEA messages directly from your computer without an Arduino. In this post, I will explain some basics of the NMEA message and how to make a simple interface with Arduino and GPE Bee Kit.

gps8

NMEA stands for National Marine Electronics Association. For GPS Bee Kit, it uses NMEA 0183 protocol. Let us look at the message received from Hyperterminal previously.

hyp5
Received data from GPS at Hyperterminal

Notice that all the message starts with a dollar sign, ‘$’. The next two characters after $ identifies the talker and the next three characters after talker identifies the type of message. After the identifier, you will get the data with respect to the type of message. Each different data are separated by comma sign, ‘,’. At the end of NMEA string you will see an aterisk, ‘*’ follow by two digits of hexadecimal number which represents the checksum. The NMEA string actually ends after the checksum with , carriage return and line feed.

gps7
NMEA sentence and description

An example on getting the informations from NMEA message:

$GPGGA,144528.00,0509.11823,N,10029.71011,E,1,06,1.41,24.4,M,-14.4,M,,*47

UTC time (hhmmss.ss) – 1445528.00

Latitude of position – 0509.11823

North/South – N

Longitude of position – 10029.71011

East/West – E

Fix Quality – 1

Number of Satellites in use – 06

Horizontal dilution of precision – 1.41

Antenna altitude above mean-sea-level – 24.4

Units of antenna altitude – M (meter)

Geoidal seperation – -14.4

Units of geoidal seperation – M (meter)

Checksum – *47

For more details on GPS NMEA sentence, visit here. This link explained very detail for each NMEA sentence, highly recommended.

When you get all the geographic coordinate data, which is the latitude and longitude, how can you verify it? If you are unclear with geographic coordinate system, Wiki has a good explanation on it. Now, I am going to show you how to verify your location with Google Map. Go to https://maps.google.com/

gm2First, search for your location on Google Map.

gm3Next, right click on the point you would like to get the location. Click on “What’s Here?”.

gm1Finally you will have the latitude and longitude coordinate on top of the search bar.

Before this, I have shown how to test GPS data with several software. Now, I am going to show you how you can test and read the NMEA messages with an Arduino.

Sample sketch:

#include <SoftwareSerial.h>

SoftwareSerial ss(2,3);

void setup()
{
 Serial.begin(9600);
 ss.begin(9600);
}

void loop()
{
 while(ss.available()>0)
 {
 Serial.print(char(ss.read()));
 }
}

argps1

Code explanation:

First I used software serial to read data from GPS, then I used the built in serial port on Arduino to display the data through serial monitor.

You need to include SoftwareSerial.h library in order to use it. It works almost the same as Serial in Arduino.

At the beginning of your program, you need to initialize which pins are you going to use for software serial. Then in your setup() function, you need to declare the baud rate of serial communication. Then you can read data just like how you used in Serial function.

SoftwareSerial ss(rx,tx)

– Initialize SoftwareSerial with pins associated for receiver (Rx) and transmitter (Tx).

ss.begin(baudrate)

– Initialize the baud rate for software serial communication

ss.available()

– Check if received any data

ss.read()

– Reads incoming serial data

For the next part, I am going to use one of the library available for Arduino, which is TinyGPS. You can download TinyGPS library here. This library ease your job to get all the information from GPS data.

Sample sketch on using TinyGPS library.

#include <SoftwareSerial.h>

#include <TinyGPS.h>

TinyGPS gps;
SoftwareSerial ss(2,3);

boolean newData=false;
float flat,flon,velocity;
int year;byte month,day,hour,minute,second;
char lat_dir,long_dir;
unsigned long speed,course;

void setup()
{
 Serial.begin(9600);
 ss.begin(9600);
}

void loop()
{
 while(ss.available())
 {
 char c=ss.read();
 if(gps.encode(c))
 {
 newData=true;
 gps.f_get_position(&flat,&flon);
 gps.crack_datetime(&year,&month,&day,&hour,&minute,&second);
 velocity=gps.f_speed_kmph();
 hour=hour+8;
 }

 }
 if(newData)
 {
 if(flat>0)lat_dir='N';else lat_dir='S';
 if(flon>0)long_dir='E';else long_dir='W';
 Serial.print("Lat: ");Serial.print(flat);Serial.print(lat_dir);Serial.print("\t");
 Serial.print("Long: ");Serial.print(flon);Serial.print(long_dir);Serial.print("\t");
 Serial.print("Date: ");Serial.print(day);Serial.print("/");Serial.print(month);
 Serial.print("/");Serial.print(year);Serial.print("\t");
 Serial.print("Time: ");Serial.print(hour);Serial.print(":");Serial.print(minute);
 Serial.print(":");Serial.print(second);Serial.print("\t");
 Serial.print("Velocity: ");Serial.print(velocity);Serial.print(" m/s");Serial.print("\t");
 Serial.println();
 newData=false;
 delay(100);
 }

}

Code explanation:

To get all the information with the library, you need to read from the software serial first. Therefore, a char c is used to store the data received in serial pin. Then you need to encode the data received. It will return TRUE if the sentence received is valid. After the encode part is done, you can extract all the informations from the GPS.

gps.encode(c)

– Encode the serial data and returns true if the sentence is valid.

gps.get_position(&lat,&lon)

– Retrieves latitude and longitude information.

gps.crack_datetime(&year,&month,&day,&hour,&minute,&second)

– Retrieves each data and time informations in separate variables.

gps.get_datetime(&date,&time)

– Retrieves date in the format of ddmmyy, and time in the format of hhmmsscc.

gps.f_speed()

– Retrieves the speed information from GPS. Some other available speed information with conversion:

gps.f_speed_knots()  -> speed in knots

gps.f_speed_kmph()   -> speed in km/hr

gps.f_speed_mps()    -> speed in m/s

gps.f_speed_mph()    -> speed in miles/hr

argps2
My first test without velocity details
argps3
Velocity added.
Still in stationary.
argps4
Moving along with GPS, velocity increased

I was actually cycling with one hand controlling the bicycle and the other hand holding my laptop together with GPS to test the velocity. That was tough! I should consider making all the data display on LCD perhaps, instead of serial monitor next time.

Some images of my final set up on Arduino:

DSC07123
GPS Bee switched on. Power LED lights up.
DSC07124
The breadboard and Arduino are fitted in a box
DSC07125
GPS Bee kit
DSC07126
Antenna attached on the outer layer of box, to ease the GPS receiving
DSC07127
Arduino and GPS Bee Kit on breadboard

Basically the Part 1 and Part 2 will provide sufficient information to understand how a GPS module works and how to use it with Arduino. I hope that all the information provided can help your understanding on GPS. If there is any suggestion or information to add on, or even any questions, kindly drop me a comment below. Of course, you can also share your GPS experience and ideas too.

Enjoy Arduino!

Advertisements