Hi everyone
I hope somebody here can help me. I don't know why but I'm not able to see any output for this stripped down GPS parsing program? Except for "Test" which I put in setup function to make sure I'm not crazy. I'm using the Arduino Due so I commented out all the software serial stuff and connected up my GPS module to the Serial1 (pins 18 and 19 on Due) UART pins.
Here is the code:
//#include <NewSoftSerial.h>
#include <TinyGPS.h>
TinyGPS gps;
//NewSoftSerial nss(2, 3);
void gpsdump(TinyGPS &gps);
bool feedgps();
void printFloat(double f, int digits = 2);
void setup()
{
// Serial.begin(115200);
Serial.begin(9600);
// Serial1.begin(4800);
Serial1.begin(115200);
Serial.println("Test");
}
void loop()
{
bool newdata = false;
unsigned long start = millis();
// Every fourth of a second we print an update
while (millis() - start < 250)
{
if (feedgps())
newdata = true;
}
if (newdata)
{
Serial.println("Acquired Data");
Serial.println("-------------");
gpsdump(gps);
Serial.println("-------------");
Serial.println();
}
}
void printFloat(double number, int digits)
{
// Handle negative numbers
if (number < 0.0)
{
Serial.print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
Serial.print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0)
Serial.print(".");
// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
int toPrint = int(remainder);
Serial.print(toPrint);
remainder -= toPrint;
}
}
void gpsdump(TinyGPS &gps)
{
long lat, lon;
float flat, flon;
unsigned long age, date, time, chars;
unsigned short sentences, failed;
gps.get_position(&lat, &lon, &age);
Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon);
Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
gps.f_get_position(&flat, &flon, &age);
Serial.print("Lat/Long(float): "); printFloat(flat, 5); Serial.print(", "); printFloat(flon, 5);
Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
feedgps();
gps.stats(&chars, &sentences, &failed);
Serial.print("Stats: characters: ");
Serial.print(chars); Serial.print(" sentences: "); Serial.print(sentences); Serial.print(" failed checksum: "); Serial.println(failed);
}
bool feedgps()
{
while (Serial1.available())
{
if (gps.encode(Serial1.read()))
return true;
}
return false;
}
Somebody please help, this is sooo frustrating. I'm only in High School so please take that into account when explaining stuff to me, I'm definitely not an expert by any means.