Tuesday, September 16, 2014

Intermediate: u-blox Neo-6M GPS Module (Revisited)

Previously, I've posted about this module which you can find here. This time around I'm going to share with you another library that I wrote specifically for this module.

If you've tried my code from the tutorial, you might notice that sometimes it is hard to change the baud rate of the module. Most of the time, the module failed to change the baud rate to 9600. Note that the module runs by default, at 38400 baud rate. I notice that it is easier to change to this baud rate, but the Arduino Uno or Nano that I'm using can't keep up with the speed, thus, loosing some bytes. However, it still managed to give you some of the important information. I manage to get about 63 bytes of data for each reading. This data is actually enough to extract the location data, latitude, longitude, altitude and the UTC. You won't get to verify this data however, of cause, due to the missing checksum, but still, for me it is fine. Unless your project requires you to be extremely cautious, you might want to try out this library.

You may download the library here.

The sketch could end up pretty huge, but can be reduced if you remove all the Serial print statements in the library. I just leave it there so that we can see what happen. The following is the short code to print the available information.


#include <CustomUBlox.h>
#include <SoftwareSerial.h>

CustomUBlox gps(2, 3); // RX, TX, Baudrate, mode, datarate

void setup() {
  Serial.begin(19200);
  Serial.println("Initializing...");

  gps.init();
}

void loop() {
  gps.processData();
  
  if(gps.available() && gps.isFixed()) {
    Serial.print("\nLocal time : ");
    Serial.println(gps.getLocalTime());
    Serial.print("Latitude : ");
    Serial.print(gps.getLatitude(), 4);
    Serial.println(gps.getLatitudeHeading());
    Serial.print("Longitude : ");
    Serial.print(gps.getLongitude(), 4);
    Serial.println(gps.getLongitudeHeading());
    Serial.print("MSL Altitude : ");
    Serial.print(gps.getAltitude(), 4);
    Serial.println("m");
    delay(1000);
  }
}

The functions available in the library are as follows:
Constructor:
CustomUBlox(int rx, int tx, int baudrate = 38400, int mode = 2, int rate = 3)
  • Baud rate can be: 4800, 9600, 19200, 38400 (default), 57600, 115200 or 230400
  • Mode: 0 (Portable), 1 (Stationary), 2 (Pedestrian - Default), 3 (Automotive), 4 (Sea), 5 (<1G), 6 (<2G), 7 (<4G)
  • Data rate: 0 (1Hz), 1 (2Hz), 2 (3.33Hz), 3 (4Hz)
Functions:
void init() : to initialize the GPS module.
void showStatus(bool status) : Show Serial messages (true - default) or hide Serial messages (false)
void processData() : Checks and updates new data from the GPS.
double getLatitude() : Return the latitude.
char getLatitudeHeading() : Return 'N' for North or 'S' for South.
double getLongitude() : Return the longitude.
char getLongitudeHeading() : Return 'W' for West or 'E' for East.
double getAltitude() : Return the altitude.
bool available() : Return true if new data is available. Otherwise, false.
bool isFixed() : Return true if the GPS got a fix.
String getLocalTime(byte offset = 8) : Return UTC time + offset (default=8) in form of HH:MM:SS
byte getHour() : Return hour.
byte getMinute() : Return minute.
byte getSecond() : Return second.

No comments :

Post a Comment