Hello,
I got my GPS modules (Neo-7M and 6M) recently to work and am now trying to get my project to the next level. I want to replace a Compass (well not replace, just simulate one, as I do not have one) with a GPS.
My idea was to basically wait for the GPS to get the coordinates, then read those and store them: Then the GPS should move in some direction. After a short while (like 10-20 seconds) the Arduino should read the new coordinates and from there calculate the direction the object is heading.
I am using the NeoGPS library with the standard NMEA sketch.
#include <NMEAGPS.h>
#if defined( UBRR1H ) | defined( ID_USART0 )
//#include <NeoHWSerial.h>
#else
//#include <NeoICSerial.h>
//#include <AltSoftSerial.h>
#include <NeoSWSerial.h>
#endif
#include "GPSport.h"
#include "Streamers.h"
#ifdef NeoHWSerial_h
#define DEBUG_PORT NeoSerial
#else
#define DEBUG_PORT Serial
#endif
static NMEAGPS gps;
static gps_fix fix_data;
static void doSomeWork()
{
trace_all( DEBUG_PORT, gps, fix_data );
}
static void GPSloop()
{
while (gps.available( gps_port )) {
fix_data = gps.read();
doSomeWork();
}
}
void setup()
{
DEBUG_PORT.begin(9600);
while (!DEBUG_PORT)
;
DEBUG_PORT.print( F("NMEA.INO: started\n") );
DEBUG_PORT.print( F(" fix object size = ") );
DEBUG_PORT.println( sizeof(gps.fix()) );
DEBUG_PORT.print( F(" gps object size = ") );
DEBUG_PORT.println( sizeof(gps) );
DEBUG_PORT.println( F("Looking for GPS device on " USING_GPS_PORT) );
#ifndef NMEAGPS_RECOGNIZE_ALL
#error You must define NMEAGPS_RECOGNIZE_ALL in NMEAGPS_cfg.h!
#endif
#ifdef NMEAGPS_INTERRUPT_PROCESSING
#error You must *NOT* define NMEAGPS_INTERRUPT_PROCESSING in NMEAGPS_cfg.h!
#endif
#if !defined( NMEAGPS_PARSE_GGA ) & !defined( NMEAGPS_PARSE_GLL ) & \
!defined( NMEAGPS_PARSE_GSA ) & !defined( NMEAGPS_PARSE_GSV ) & \
!defined( NMEAGPS_PARSE_RMC ) & !defined( NMEAGPS_PARSE_VTG ) & \
!defined( NMEAGPS_PARSE_ZDA ) & !defined( NMEAGPS_PARSE_GST )
DEBUG_PORT.println( F("\nWARNING: No NMEA sentences are enabled: no fix data will be displayed.") );
#else
if (gps.merging == NMEAGPS::NO_MERGING) {
DEBUG_PORT.print ( F("\nWARNING: displaying data from ") );
DEBUG_PORT.print ( gps.string_for( LAST_SENTENCE_IN_INTERVAL ) );
DEBUG_PORT.print ( F(" sentences ONLY, and only if ") );
DEBUG_PORT.print ( gps.string_for( LAST_SENTENCE_IN_INTERVAL ) );
DEBUG_PORT.println( F(" is enabled.\n"
" Other sentences may be parsed, but their data will not be displayed.") );
}
#endif
DEBUG_PORT.print ( F("\nGPS quiet time is assumed to begin after a ") );
DEBUG_PORT.print ( gps.string_for( LAST_SENTENCE_IN_INTERVAL ) );
DEBUG_PORT.println( F(" sentence is received.\n"
" You should confirm this with NMEAorder.ino\n") );
trace_header( DEBUG_PORT );
DEBUG_PORT.flush();
gps_port.begin( 9600 );
}
void loop()
{
GPSloop();
}
My plan was to somehow only access the GPS values (so latitude and longtitude) and (as I said) store them. However, my coding experience is rather little and I am unsure how to get there.
Right now I am stuck at just accessing the coordinates, storing them and also (not really needed, but for monitoring purposes) send them to the serial monitor).
Another question: How can I print something to the serial monitor with this sketch. I found out that the "trace_all()" command sends the data to the monitor (I hope I am right with that assumption), but not sure how exactly that works and if there is any other way of sending stuff to the serial Monitor.
Thanks for all ideas and answers!