NEO-6M GPS Library

In order to learn how to create a lightweight interface with GPS devices I wrote a library to work with my NEO-6M GPS module.

With this library you can set the baud, sample rate, turn on/off individual NMEA sentences, and parse NMEA data. The source code is hosted on GitHub here.

Please take a look, critique it (I can use the constructive criticism :wink: ), and use it for your own projects if you want to.

Here is an example sketch that shows how to use the library:

#include "neo6mGPS.h"




neo6mGPS myGPS;




void setup()
{
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  
  Serial.begin(115200);
  while(!Serial);
  
  myGPS.begin(Serial1);
}




void loop()
{
  if(myGPS.available())
  {
    Serial.print(myGPS.utc);       Serial.print(" | ");
    Serial.print(myGPS.navStatus); Serial.print(" | ");
    Serial.print(myGPS.lat);       Serial.print(" | ");
    Serial.print(myGPS.latDir);    Serial.print(" | ");
    Serial.print(myGPS.lon);       Serial.print(" | ");
    Serial.print(myGPS.lonDir);    Serial.print(" | ");
    Serial.print(myGPS.sog_knots); Serial.print(" | ");
    Serial.print(myGPS.cog_true);  Serial.print(" | ");
    Serial.println();
  }
}

Thanks for your contribution to the Arduino project Power_Broker!

What is the purpose of these lines of your example sketch?:

  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);

pert:
What is the purpose of these lines of your example sketch?:

  pinMode(13, OUTPUT);

digitalWrite(13, HIGH);

I use Teensy 3.5 boards that do not have power leds like normal Arduinos. To work around this, all of my sketches use the pin 13 led as a makeshift power led.

It seems unnecessary in the example even for the Teensy, since you’re going to be able to tell it’s on from the Serial Monitor output.

If you are going to leave them in the example, I recommend adding a comment to explain their purpose.

thank you for your library, I will try it soon !

Hello,

i have an error when i try to compile the exemple ExampleLatLon

Arduino\libraries\NEO-6M_GPS/neo6mGPS.h:157:13: error: 'usb_serial_class' has not been declared

on arduino 33 ble sense

i don't understand where this error come from do you have any idea?

Idk why an Arduino 33 BLE Sense would not have the class usb_serial_class in it's core. Maybe someone with more experience with such an Arduino can help. While I might take a look at adjusting the library, you're probably better off using NeoGPS.h instead.

ok thanks for your answer i will check this lib

Hi all

I have tested this library on a Nano, Uno and on a Mega2560. None of these works with your example sketch :frowning:

On the Nano and Uno the errormessage tells that Serial1 was not defined and on the Mega2560 it screams error: ‘usb_serial_class’ does not name a type

So… yeah… anybody has an idea what to do to make it work on a Nano? What I’m trying is to print the coordinates from the GPS to a SSD1306 OLED display (128x32) with the u8g2 library. I have a Neo-6M GPS module. Here my code:

#include "neo6mGPS.h"
#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif



neo6mGPS myGPS;

U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);  // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED

#define INFO_SCREEN_DELAY 3000


void setup()
{
  // turn on power led
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
    u8g2.begin();
  Serial.begin(115200);
  while(!Serial);
  
  myGPS.begin(Serial1);
}




void loop()
{
  if(myGPS.available())
  {
    Serial.print(myGPS.utc_year);  Serial.print(" | ");
    Serial.print(myGPS.utc_month); Serial.print(" | ");
    Serial.print(myGPS.utc_day);   Serial.print(" | ");
    Serial.print(myGPS.utc_hour);  Serial.print(" | ");
    Serial.print(myGPS.utc_min);   Serial.print(" | ");
    Serial.print(myGPS.utc_sec);   Serial.print(" | ");
    Serial.print(myGPS.lat_dd);    Serial.print(" | ");
    Serial.print(myGPS.lon_dd);    Serial.print(" | ");
    Serial.print(myGPS.sog_knots); Serial.print(" | ");
    Serial.print(myGPS.cog_true);  Serial.print(" | ");
    Serial.print(myGPS.navStatus);
    Serial.println();
    char mylat=myGPS.lat_dd;
    char mylon=myGPS.lon_dd;
      u8g2.clearBuffer();

  u8g2.setFontMode(1);
  u8g2.setFont(u8g2_font_cu12_tr);    

  u8g2.setCursor(0,15);
  u8g2.print("Link: ");
  u8g2.setCursor(0,30);
  u8g2.print(mylat);
  u8g2.setCursor(20,30);
  u8g2.print(mylon);  
  u8g2.sendBuffer();
  delay(1000);
  }
}

Thanks and kind regards

delf

Yeah, the lib was written for Teensy MCUs only and was honestly more of a personal academic exercise that I figured others might find useful. I suggest using NeoGPS.h instead.