GPS Module Interfacing with MSP-EXP430G2 TI Launchpad

Overview of GPS

NEO-6M GPS Receiver Module
NEO-6M GPS Receiver Module

 

Global Positioning System (GPS) makes use of signals sent by satellites in space and ground stations on Earth to accurately determine its position on Earth.

The NEO-6M GPS receiver module uses USART communication to communicate with a microcontroller or PC terminal.

It receives information like latitude, longitude, altitude, UTC time, etc. from the satellites in the form of NMEA string. This string needs to be parsed to extract the information that we want to use.

For more information about GPS and how to use it, refer to the topic GPS Receiver Module in the sensors and modules section.

 

Connection Diagram of GPS Module with MSP-EXP430G2 TI Launchpad

Interfacing NEO-6M GPS Receiver Module With MSP-EXP430G2 TI Launchpad
Interfacing NEO-6M GPS Receiver Module With MSP-EXP430G2 TI Launchpad

 

Note: For the TI Launchpad board, P1.1 is the Rx pin and P1.2 is the Tx pin when the jumpers are positioned for using Hardware Serial. Here, we are using, Hardware Serial, hence P1.1 is the Rx pin.

When jumpers are positioned for software serial, P1.1 acts as the Tx pin, and P1.2 acts as the Rx pin. 

 

Get GPS Location using MSP-EXP430G2 TI Launchpad

We are going to display data(latitude, longitude, altitude, and time) received by the GPS receiver module on the serial monitor of Energia.

 

Here, we will be using Mikal Hart’s TinyGPSPlus library from GitHub. This library is for Arduino but works for MSP -EXP430G2 TI Launchpad as well.

Download this library from here

Extract the library and add it to the libraries folder path of Energia IDE.

For information about how to add a custom library to the Energia IDE and use examples from it, refer to Adding Library To Energia IDE in the Basics section.

Here, we have created a simplified sketch using the functions and header file provided by the author of this library.

 

Note: If you see most of the data in ***** format, take the GPS connected to Energia in an open space (balcony for example). The GPS may require some time to lock on to satellites. Give it around 20-30 seconds so that it can start giving you the correct data. It usually takes no more than 5 seconds to lock on to satellites if you are in an open space, but occasionally it may take more time (for example if 3 or more satellites are not visible to the GPS receiver).

 

Tread Carefully: MSP-EXP430G2 TI Launchpad board has a RAM of 512 bytes which is easily filled, especially while using different libraries. There are times when you need the Serial buffer to be large enough to contain the data you want and you will have to modify the buffer size for the Serial library. While doing such things, we must ensure that the code does not utilize more than 70% RAM. This could lead to the code working in an erratic manner, working well at times, and failing miserably at others. 

There are times when the RAM usage may exceed 70% and the codes will work absolutely fine, and times when the code will not work even when the RAM usage is 65%. 

In such cases, a bit of trial and error with the buffer size and/or variables may be necessary.

 

Code for Displaying GPS Parameters On Serial Monitor

#include <TinyGPS++.h>
/* Create an object named gps of the class TinyGPSPlus */
TinyGPSPlus gps;			

volatile float minutes, seconds;
volatile int degree, secs, mins;

void setup() {
  Serial.begin(9600);	/* Define baud rate for serial communication */
}

void loop() {
        smartDelay(1000);	/* Generate precise delay of 1ms */
        if (!gps.location.isValid())
        {          
          Serial.print("Latitude : ");
          Serial.println("*****");
          Serial.print("Longitude : ");
          Serial.println("*****");
        }
        else
        {
          //DegMinSec(gps.location.lat());
          Serial.print("Latitude in Decimal Degrees : ");
          Serial.println(gps.location.lat(), 6);
//          Serial.print("Latitude in Degrees Minutes Seconds : ");
//          Serial.print(degree);
//          Serial.print("\t");
//          Serial.print(mins);
//          Serial.print("\t");
//          Serial.println(secs);
          //DegMinSec(gps.location.lng());	/* Convert the decimal degree value into degrees minutes seconds form */
          Serial.print("Longitude in Decimal Degrees : ");
          Serial.println(gps.location.lng(), 6);
//          Serial.print("Longitude in Degrees Minutes Seconds : ");
//          Serial.print(degree);
//          Serial.print("\t");
//          Serial.print(mins);
//          Serial.print("\t");
//          Serial.println(secs);
        }
        if (!gps.altitude.isValid())
        {
          Serial.print("Altitude : ");
          Serial.println("*****");
        }
        else
        {
          Serial.print("Altitude : ");
          Serial.println(gps.altitude.meters(), 6);    
        }
        if (!gps.time.isValid())
        {
          Serial.print("Time : ");
          Serial.println("*****");
        }
        else
        {
          char time_string[32];
          sprintf(time_string, "Time : %02d/%02d/%02d \n",gps.time.hour(), gps.time.minute(), gps.time.second());
          Serial.print(time_string);    
        }
}

static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (Serial.available())	/* Encode data read from GPS while data is available on serial port */
      gps.encode(Serial.read());
	  /* Encode basically is used to parse the string received by the GPS and to store it in a buffer so that information can be extracted from it */
  } while (millis() - start < ms);
}

//void DegMinSec( double tot_val)		/* Convert data in decimal degrees into degrees minutes seconds form */
//{  
//  degree = (int)tot_val;
//  minutes = tot_val - degree;
//  seconds = 60 * minutes;
//  minutes = (int)seconds;
//  mins = (int)minutes;
//  seconds = seconds - minutes;
//  seconds = 60 * seconds;
//  secs = (int)seconds;
//}

Components Used

TI Launchpad MSP-EXP430G2
TI Launchpad MSP-EXP430G2
1
Ublox NEO-6m GPS
Ublox Neo 6m GPS
1

Downloads

GPS_Interfacing_With_TI_Launchpad_INO Download
TinyGPSPlus Library Download
Ad