The code below works fine. Every second, it displays the current time. What I am not sure is whether I can pick timing at a faster rate, because “fix.dateTime_cs”, displays 0 all the time. Is there a way I can increase the frequency to 2 times a second? Now, I would want to add an interrupt, such that when AS3935_PIN is RISING, it picks the GPS, timing to an accuracy of Microseconds (or better Millisecond). How do I make changes to the code below to achieve that?
#include "NeoSWSerial.h"
#define RX_PIN 7
#define TX_PIN 8
#define AS3935_PIN 9
NeoSWSerial gpsPort( RX_PIN, TX_PIN );
// Since it's hooked to a GPS, try NeoGPS for parsing...
#include <NMEAGPS.h>
NMEAGPS gps;
gps_fix fix;
void gpsPortISR()
{
NeoSWSerial::rxISR( *portInputRegister( digitalPinToPort( RX_PIN ) ) );
// This is uglier than passing PIND, but it works for any RX_PIN you choose.
}
void setup()
{
Serial.begin( 9600 );
gpsPort.begin( 9600 );
enableInterrupt( RX_PIN, gpsPortISR, CHANGE);
enableInterrupt(AS3935_PIN,GPSdata,CHANGE);
}
void loop()
{
GPSdata();
}
void GPSdata()
{
if (gps.available( gpsPort )) {
fix = gps.read();
if (fix.valid.time ) {
Serial.print("Date:");
Serial.print(fix.dateTime.year);
Serial.print("/");
Serial.print(fix.dateTime.month,10);
Serial.print("/");
Serial.print(fix.dateTime.date,10);
Serial.print(", Time(UTC):");
Serial.print(fix.dateTime.hours,10);
Serial.print(":");
Serial.print(fix.dateTime.minutes,10);
Serial.print(":");
Serial.print(fix.dateTime.seconds);
Serial.print(".");
Serial.print(fix.dateTime_cs);
Serial.print(" - Week Day:");
Serial.print(fix.dateTime.day,10);
Serial.println();
}
}
}