NMEA to Yaesu VX-8 Arduino Sketch

// Include TimedAction library to send GPS output every x milliseconds
#include 
 
// Include and initialise TinyGPS
#include <TinyGPS++.h>
static const uint32_t GPSBaud = 4800;
TinyGPSPlus gps;
 
//This initializes a TimedAction class that will perform the NMEAout function every 2 seconds.
TimedAction timedAction = TimedAction(2000,NMEAout);
 
// Setup software serial port - select which line to use depending on whether you want bit inversion...
#include 
 
// Include the following SoftwareSerial line if you do not require serial port bit inversion
// (e.g. you're using the Arduino Uno as in the prototype setup)
//SoftwareSerial ss(2, 3); //pins are (RXpin GPS, TXpin PC)
 
// Include the following SoftwareSerial line if you do require serial port bit inversion
// (e.g. you're using the Arduino Pro Mini at 3.3VDC TTL)
SoftwareSerial ss(2, 3, true); //pins are (RXpin GPS, TXpin PC)
// Note: must add the ", true" to SoftwareSerial on Pro Mini to implement RS-232/TTL bit inversion
 
void setup() {
  // Open serial communications:
  Serial.begin(9600);  // 9600 baud rate for PC monitor and VX-8 radio interface
  ss.begin(GPSBaud);   // 4800 baud rate for NMEA GPS interface
}
 
void loop() {
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      timedAction.check();
}
 
void NMEAout()
{
  printGPGGA();
  printGPRMC();
  printGPZDA();
}
 
void printGPGGA()
{
  Serial.print("$GPGGA,");
 
  if (gps.time.isValid())
  {
    // hhmmss.sss
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
    Serial.print(F("0"));
    Serial.print(F(","));
 
    // Latitude (ddmm.mmmm format)
    float absLatitude = sqrt(sq(gps.location.lat()));
    if (absLatitude < 10) Serial.print(F("0"));
    Serial.print(int(absLatitude)); //dd
    if ((60*(absLatitude-(int(absLatitude)))) < 10) Serial.print(F("0"));
    Serial.print(60*(absLatitude-(int(absLatitude))), 4);
    Serial.print(",");
 
    // N or S
    Serial.print(gps.location.rawLat().negative ? "S," : "N,");
 
    // Longitude (dddmm.mmmm format)
    float absLongitude = sqrt(sq(gps.location.lng()));
    if (absLongitude < 100) Serial.print(F("0"));
    if (absLongitude < 10) Serial.print(F("0"));
    Serial.print(int(absLongitude)); //dd
    if ((60*(absLongitude-(int(absLongitude)))) < 10) Serial.print(F("0"));
    Serial.print(60*(absLongitude-(int(absLongitude))), 4);
    Serial.print(",");
 
    // E or W
    Serial.print(gps.location.rawLng().negative ? "W," : "E,");
 
    // x = GPS Quality indicator (0=no fix, 1=GPS fix, 2=Dif. GPS fix)
    Serial.print("1,");
 
    // xx = number of satellites in use
    if (gps.satellites.value() < 10) Serial.print(F("0"));
    Serial.print(gps.satellites.value());
    Serial.print(",");
 
    // x.x = horizontal dilution of precision (ignored)
    // if (gps.hdop.value() < 10) Serial.print(F("0"));
    // Serial.print(gps.hdop.value());
    Serial.print("00.0,");
 
    // x.x = Antenna altitude above mean-sea-level
    if (gps.altitude.meters() < 10000) Serial.print(F("0"));
    if (gps.altitude.meters() < 1000) Serial.print(F("0"));
    if (gps.altitude.meters() < 100) Serial.print(F("0"));
    if (gps.altitude.meters() < 10) Serial.print(F("0"));
    Serial.print(int(gps.altitude.meters()));
    Serial.print(".0,");
 
    // M = units of antenna altitude, meters
    Serial.print("M,");
 
    // x.x = Geoidal separation (ignored)
    Serial.print("0000.0,");
 
    // M = units of geoidal separation, meters
    Serial.print("M,");
 
    // x.x = Age of Differential GPS data (seconds)
    Serial.print("000.0,");
 
    // xxxx = Differential reference station ID 
    Serial.print("0000,");
 
    // End Of Message and "00" checksum
    Serial.print(F("*00"));
 
    // Carriage return and line feed
    Serial.println();
  }
} 
 
void printGPRMC()
{
  Serial.print("$GPRMC,");
 
  if (gps.time.isValid())
  {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
    Serial.print(F("0"));
    Serial.print(F(","));
 
    // Validity
    Serial.print(F("A,"));
 
    // Latitude (ddmm.mmmm format)
    float absLatitude = sqrt(sq(gps.location.lat()));
    if (absLatitude < 10) Serial.print(F("0"));
    Serial.print(int(absLatitude)); //dd
    if ((60*(absLatitude-(int(absLatitude)))) < 10) Serial.print(F("0"));
    Serial.print(60*(absLatitude-(int(absLatitude))), 4);
    Serial.print(",");
 
    // N or S
    Serial.print(gps.location.rawLat().negative ? "S," : "N,");
 
    // Longitude (dddmm.mmmm format)
    float absLongitude = sqrt(sq(gps.location.lng()));
    if (absLongitude < 100) Serial.print(F("0"));
    if (absLongitude < 10) Serial.print(F("0"));
    Serial.print(int(absLongitude)); //dd
    if ((60*(absLongitude-(int(absLongitude)))) < 10) Serial.print(F("0"));
    Serial.print(60*(absLongitude-(int(absLongitude))), 4);
    Serial.print(",");
 
    // E or W
    Serial.print(gps.location.rawLng().negative ? "W," : "E,");
 
    // Speed in knots
    if (gps.speed.knots() < 1000) Serial.print(F("0"));
    if (gps.speed.knots() < 100) Serial.print(F("0"));
    if (gps.speed.knots() < 10) Serial.print(F("0"));
    Serial.print(gps.speed.knots());
    Serial.print(F(","));
 
    // Course in degrees true
    if (gps.course.deg() < 100) Serial.print(F("0"));
    if (gps.course.deg() < 10) Serial.print(F("0"));
    Serial.print(gps.course.deg());
    Serial.print(F(","));
 
    // Date of fixe, ddmmyy
    if (gps.date.day() < 10) Serial.print(F("0"));
    Serial.print(gps.date.day());
    if (gps.date.month() < 10) Serial.print(F("0"));
    Serial.print(gps.date.month());
    int yy = (gps.date.year() - 2000);
    if (yy < 10) Serial.print(F("0"));
    Serial.print(yy);
 
    //End Of Message and 00 checksum
    Serial.print(F(",,*00"));
 
    // Carriage return and line feed
    Serial.println();
  }
} 
 
void printGPZDA()
{
  Serial.print("$GPZDA,");
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
    Serial.print(F("0"));
    Serial.print(F(","));
    if (gps.date.day() < 10) Serial.print(F("0"));
    Serial.print(gps.date.day());
    Serial.print(F(","));
    if (gps.date.month() < 10) Serial.print(F("0"));
    Serial.print(gps.date.month());
    Serial.print(F(","));
    Serial.print(gps.date.year());
    Serial.print(F(",,*00"));
 
    // Carriage return and line feed
    Serial.println();
}

Leave a Reply

Your email address will not be published. Required fields are marked *