how can I express gps ground speed in km / h?

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
trenanc
 
Posts: 7
Joined: Mon Jul 07, 2014 12:59 pm

how can I express gps ground speed in km / h?

Post by trenanc »

Hi, I am not sure about the unit of measurement of my gps ground speed, I believe it is expressed as knots per hour.

And how I change it to km/h?

Thank you!
Thiago Renan da Costa.

Code: Select all

  #include <Ethernet.h>

  #include <SPI.h>
  #include "plotly_streaming_ethernet.h"
  #include <Adafruit_GPS.h>
  #include <SoftwareSerial.h>
  
  SoftwareSerial mySerial(3, 2);
  Adafruit_GPS GPS(&mySerial);
  
  #define GPSECHO  true
  boolean usingInterrupt = false;
  void useInterrupt(boolean); 
  // Sign up to plotly here: https://plot.ly
  // View your API key and streamtokens here: https://plot.ly/settings
  #define nTraces 2
  // View your tokens here: https://plot.ly/settings
  // Supply as many tokens as data traces
  // e.g. if you want to ploty A0 and A1 vs time, supply two tokens
  char *tokens[nTraces] = {"sjhdc32erp", "rsv9z5vewu"};
  // arguments: username, api key, streaming token, filename
  plotly graph = plotly("trenanc", "9c8e5ydnyf", tokens, "Arduino", nTraces);
  
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  byte my_ip[] = { 189, 6, 135, 133 }; // google will tell you: "public ip address"
  
  void startEthernet(){
      Ethernet.begin(mac);
      Serial.println("... Initializing ethernet");
      if(Ethernet.begin(mac) == 0){
          Serial.println("... Failed to configure Ethernet using DHCP");
          // no point in carrying on, so do nothing forevermore:
          // try to congifure using IP address instead of DHCP:
          Ethernet.begin(mac, my_ip);
      }
      Serial.println("... Done initializing ethernet");
      delay(1000);
  }
  
  
  void setup() {
  
    // Open serial communications and wait for port to open:
    Serial.begin(9600);
    while (!Serial) {
      ; // wait for serial port to connect. Needed for Leonardo only
    }
  
    startEthernet();
    graph.fileopt="overwrite"; // See the "Usage" section in https://github.com/plotly/arduino-api for details
    bool success;
    success = graph.init();
    if(!success){while(true){}}
    graph.openStream();
    
    GPS.begin(9600);  
    GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
    GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
    GPS.sendCommand(PGCMD_ANTENNA);
    useInterrupt(true);
    delay(1000);
    mySerial.println(PMTK_Q_RELEASE);
  }
  
  SIGNAL(TIMER0_COMPA_vect) {
    char c = GPS.read();
    // if you want to debug, this is a good time to do it!
  #ifdef UDR0
    if (GPSECHO)
      if (c) UDR0 = c;  
      // writing direct to UDR0 is much much faster than Serial.print 
      // but only one character can be written at a time. 
  #endif
  }
  
  void useInterrupt(boolean v) {
    if (v) {
      // Timer0 is already used for millis() - we'll just interrupt somewhere
      // in the middle and call the "Compare A" function above
      OCR0A = 0xAF;
      TIMSK0 |= _BV(OCIE0A);
      usingInterrupt = true;
    } else {
      // do not call the interrupt function COMPA anymore
      TIMSK0 &= ~_BV(OCIE0A);
      usingInterrupt = false;
    }
  }
  
  uint32_t timer = millis();
  
  unsigned long x;
  int y;
  
  void loop() {
      if (! usingInterrupt) {
      char c = GPS.read();
    }
      if (GPS.newNMEAreceived()) {
    
      if (!GPS.parse(GPS.lastNMEA()))
        return;
    }
    if (timer > millis())  timer = millis();
  
    graph.plot(millis(), GPS.geoidheight, tokens[0]);
    graph.plot(millis(), GPS.speed, tokens[1]);
    
    delay(50);
  
  }

User avatar
Renate
 
Posts: 291
Joined: Tue Nov 13, 2012 3:21 pm

Re: how can I express gps ground speed in km / h?

Post by Renate »

GPS over NMEA 0183 (from the National Marine Electronics Association) uses knots.
A knot is exactly 1.852 kilometers per hour.
Take your number and multiply by 1.852

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”