Hi guys,
This is my first time posting on here, but i have used these forums for years to help. I am in the middle of a project using a V.KEL GPS and Arduino mega. I want to use this chip to show current speed as well as current time. Also, I am trying to get it to show my course and lat and long. But i would much rather have it read speed and time first. I have code that i gathered together over the years trying to make this work but have never gotten it to work. I am just trying to have it simply write into the serial monitor.
GPS Module: Connect VK2828U7G5LF GPS Module to an Arduino or Raspberry Pi to retrieve geographic coordinates
code below:
#include <TinyGPS.h>
#include <SoftwareSerial.h>
TinyGPS gps;
const int rxPin=3;
const int txPin=4;
int led=13;
SoftwareSerial mySerial(rxPin, txPin);
long lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;
//int year;
//byte month, day, hour, minute, second, hundredths;
void setup()
{
Serial.begin(9600); //Set the GPS baud rate.
pinMode(led, OUTPUT);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
mySerial.begin(9600);
digitalWrite(2,HIGH);
Serial.println("Setup completed");
delay(2000);
}
void loop()
{
while (Serial.available())
{
digitalWrite(led, HIGH);
int c = Serial.read(); // Read the GPS data
if (gps.encode(c)) // Check the GPS data
{
// process new gps info here
}
}
digitalWrite(led, LOW);
gps.get_position(&lat, &lon, &fix_age); // retrieves +/- lat/long in 100000ths of a degree
gps.get_datetime(&date, &time, &fix_age); // time in hhmmsscc, date in ddmmyy
//gps.crack_datetime(&year, &month, &day, //Date/time cracking
//&hour, &minute, &second, &hundredths, &fix_age);
LAT();
Serial.println("");
LON();
Serial.println("");
TIME();
Serial.println("");
SPEED();
Serial.println("");
COURSE();
}
void COURSE(){
course=gps.course()/100;
Serial.print("COURSE: ");
Serial.println(course);
}
void SPEED(){
speed=gps.speed()*0.0115078;
Serial.print("SPEED: ");
Serial.println(speed);
}
void TIME(){
Serial.print("TIME: ");
Serial.print(((time/1000000)+16)%12);
Serial.print(":");
if(((time%1000000)/10000)<10){
Serial.print("0");
}
Serial.print((time%1000000)/10000);
Serial.print(":");
Serial.print((time%10000)/100);
}
void LAT(){
// DEG=lat/1000000;
// MIN1=(lat/10000)%100;
// MIN2=lat%10000;
int a=lat/1000000;
int c=lat%1000000;
Serial.print("LAT:");
Serial.print(a);
Serial.print(".");
if(c<100000){
Serial.print("0");
if(c<10000){
Serial.print("0");
if(c<1000){
Serial.print("0");
if(c<100){
Serial.print("0");
if(c<10){
Serial.print("0");
}
}
}
}
}
Serial.print(c);
// Serial.print(DEG);
// Serial.prin(",");
// Serial.print(MIN1);
// Serial.print(".");
// Serial.print(MIN2);
// Serial.print("' ");
}
void LON(){ //Longitude state
// DEG=lon/1000000;
// MIN1=(lon/10000)%100;
// MIN2=lon%10000;
int b=lon/1000000;
int d=lon%1000000;
Serial.print("LON:");
Serial.print(b);
Serial.print(".");
if(d<100000){
Serial.print("0");
if(d<10000){
Serial.print("0");
if(d<1000){
Serial.print("0");
if(d<100){
Serial.print("0");
if(d<10){
Serial.print("0");
}
}
}
}
}
Serial.print(d);
// Serial.print(DEG);
// Serial.prin(",");
// Serial.print(MIN1);
// Serial.print(".");
// Serial.print(MIN2);
// Serial.print("' ");
}