tinyGPS - trying to output status
i got code working nicely, gps needs reset , cannot tell.
in code below, tried adding either of 2 commented else statements, made output stuck in state, though gps outputting valid data.
i'd print on lcd "wait gps fix" time of waiting, , status of wheather gps sending data @ (this bool variable added feedgps function @ bottom.
maybe need make first else statement if (gpsdata = 0) statement?
in code below, tried adding either of 2 commented else statements, made output stuck in state, though gps outputting valid data.
i'd print on lcd "wait gps fix" time of waiting, , status of wheather gps sending data @ (this bool variable added feedgps function @ bottom.
maybe need make first else statement if (gpsdata = 0) statement?
code: [select]
#include <newsoftserial.h>
#include <tinygps.h>
#include <string.h>
#include <ctype.h>
/* sample code demonstrates normal use of tinygps object.
requires use of newsoftserial, , assumes have a
4800-baud serial gps device hooked on pins 2(rx) , 3(tx).
*/
tinygps gps;
newsoftserial nss(2, 3);
void gpsdump(tinygps &gps);
bool feedgps();
void printfloat(double f, int digits = 2);
int tzone = -7;
bool gpsdata = false;
//connect lcd
#define rxlcdpin 4 // rxpin immaterial - not used - make unused arduino pin number
#define txlcdpin 14 // pin 14 analog pin 0, on bbb use servo cable :), see reference pinmode
//softwareserial lcd = softwareserial(rxlcdpin, txlcdpin);
newsoftserial lcd = newsoftserial(rxlcdpin, txlcdpin);
int ledpin=13; //led test pin
void setup()
{
serial.begin(115200);
nss.begin(4800);
serial.print("testing tinygps library v. "); serial.println(tinygps::library_version());
serial.println("by mikal hart");
serial.println();
serial.print("sizeof(gpsobject) = "); serial.println(sizeof(tinygps));
serial.println();
//set lcd
pinmode(txlcdpin, output);
lcd.begin(9600); // 9600 baud chip comm speed
lcd.print("?g216"); // set display geometry, 2 x 16 characters in case
delay(500); // pause allow lcd eeprom program
lcd.print("?b50"); // set backlight 00 ff hex (minimum maximum brightness)
delay(1000); // pause allow lcd eeprom program
lcd.print("?s05"); // set tabs 5 spaces
delay(1000); // pause allow lcd eeprom program
lcd.print("?c0"); // set cursor style, 0= none 2= blinking 3=underline
delay(5);
lcd.print("?f"); // clear lcd
delay(5);
lcd.print("hello gps");
delay(1000);
lcd.print("?f"); // clear lcd
lcd.print("wait gps fix");
}
void loop()
{
// gpsdata = false;
digitalwrite(ledpin, high);
bool newdata = false;
unsigned long start = millis();
// every 5 seconds print update
//while (millis() - start < 5000) {
if (feedgps()) {
newdata = true;
digitalwrite(ledpin, low);
}
/********************************
else {
lcd.print("?x00?y0wait gps fix");
lcd.print("?x00?y1"); lcd.print(millis() / 1000);
lcd.print("?x11?y1"); lcd.print(gpsdata);
}
********************************/
if (newdata) {
serial.println("acquired data");
serial.println("-------------");
gpsdump(gps);
serial.println("-------------");
serial.println();
wait = 0;
}
/**********************
else {
lcd.print("?x00?y0wait gps fix");
lcd.print("?x00?y1"); lcd.print(millis() / 1000);
lcd.print("?x11?y1"); lcd.print(gpsdata);
}
// ************************/
}
void printfloat(double number, int digits) {
// handle negative numbers
if (number < 0.0) {
serial.print('-');
number = -number;
}
// round correctly print(1.999, 2) prints "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;
number += rounding;
// extract integer part of number , print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
serial.print(int_part);
// print decimal point, if there digits beyond
if (digits > 0)
{
serial.print(".");
}
// extract digits remainder 1 @ time
while (digits-- > 0)
{
remainder *= 10.0;
int toprint = int(remainder);
serial.print(toprint);
remainder -= toprint;
}
}
void lcdprintfloat(double number, int digits)
{
// handle negative numbers
if (number < 0.0)
{
lcd.print("-");
number = -number;
}
// round correctly print(1.999, 2) prints "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;
number += rounding;
// extract integer part of number , print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
lcd.print(int_part);
// print decimal point, if there digits beyond
if (digits > 0)
lcd.print(".");
// extract digits remainder 1 @ time
while (digits-- > 0)
{
remainder *= 10.0;
int toprint = int(remainder);
lcd.print(toprint);
remainder -= toprint;
}
}
void gpsdump(tinygps &gps)
{
long lat, lon;
float flat, flon;
unsigned long age, date, time, chars;
int year;
byte month, day, hour, minute, second, hundredths;
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.");
//lcd.print("?x00?y0"); lcd.print(lat);
//lcd.print("?x00?y1"); lcd.print(lon);
feedgps(); // if don't feed gps during long routine, may drop characters , checksum errors
gps.f_get_position(&flat, &flon, &age);
serial.print("lat/long(float): "); printfloat(flat, 5); lcd.print("?x00?y0"); lcdprintfloat(flat, 5); serial.print(", "); printfloat(flon, 5); lcd.print("?x00?y1"); lcdprintfloat(flon, 5);
serial.print(" fix age: "); serial.print(age); serial.println("ms.");
//lcd.print("?x00?y0"); lcd.print(flat);
//lcd.print("?x00?y1");lcd.print(flon);
feedgps();
gps.get_datetime(&date, &time, &age);
serial.print("date(ddmmyy): "); serial.print(date); serial.print(" time(hhmmsscc): "); serial.print(time);
serial.print(" fix age: "); serial.print(age); serial.println("ms.");
//lcd.print("?x08?y0"); lcd.print(time);
lcd.print("?x10?y1");lcd.print(date);
feedgps();
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
if (hour > 7)
hour = hour + tzone;
if (hour < 8)
hour = hour + (tzone + 24);
serial.print("date: "); serial.print(static_cast<int>(month)); serial.print("/"); serial.print(static_cast<int>(day)); serial.print("/"); serial.print(year);
serial.print(" time: "); serial.print(static_cast<int>(hour)); serial.print(":"); serial.print(static_cast<int>(minute)); serial.print(":"); serial.print(static_cast<int>(second)); serial.print("."); serial.print(static_cast<int>(hundredths));
serial.println(millis());
lcd.print("?x08?y0");
if ((static_cast<int>(hour)) < 10)
lcd.print("0");
lcd.print(static_cast<int>(hour));
lcd.print("?x10?y0"); lcd.print(":");
if ((static_cast<int>(minute)) < 10)
lcd.print("0");
lcd.print(static_cast<int>(minute));
lcd.print("?x13?y0"); lcd.print(":");
if ((static_cast<int>(second)) < 10)
lcd.print("0");
lcd.print(static_cast<int>(second));
serial.println(millis());
serial.print(" fix age: "); serial.print(age); serial.println("ms.");
feedgps();
serial.print("alt(cm): "); serial.print(gps.altitude()); serial.print(" course(10^-2 deg): "); serial.print(gps.course()); serial.print(" speed(10^-2 knots): "); serial.println(gps.speed());
serial.print("alt(float): "); printfloat(gps.f_altitude()); serial.print(" course(float): "); printfloat(gps.f_course()); serial.println();
serial.print("speed(knots): "); printfloat(gps.f_speed_knots()); serial.print(" (mph): "); printfloat(gps.f_speed_mph());
serial.print(" (mps): "); printfloat(gps.f_speed_mps()); serial.print(" (kmph): "); printfloat(gps.f_speed_kmph()); serial.println();
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 (nss.available()) {
if (gps.encode(nss.read()))
// gpsdata = true;
return true;
}
return false;
// gpsdata = false;
}
i tried couple of other things, no combination of if statements think would.
code: [select]
void loop()
{
// gpsdata = false;
digitalwrite(ledpin, high);
bool newdata = false;
unsigned long start = millis();
// every 5 seconds print update
//while (millis() - start < 5000) {
if (feedgps()) {
newdata = true;
digitalwrite(ledpin, low);
}
/********************************
if (gpsdata == 1 && feedgps == 0) {
lcd.print("?x00?y0wait gps fix");
lcd.print("?x00?y1"); lcd.print(millis() / 1000);
lcd.print("?x11?y1"); lcd.print(gpsdata);
}
// ********************************/
/********************************
if (gpsdata == 0 && feedgps == 0) {
lcd.print("?x00?y0no gps data!!!!!");
lcd.print("?x00?y1"); lcd.print(millis() / 1000);
lcd.print("?x11?y1"); lcd.print(gpsdata);
}
********************************/
if (newdata) {
serial.println("acquired data");
serial.println("-------------");
gpsdump(gps);
serial.println("-------------");
serial.println();
}
/********************************
if (gpsdata == 1 && newdata == 0) {
lcd.print("?x00?y0wait gps fix");
lcd.print("?x00?y1"); lcd.print(millis() / 1000);
lcd.print("?x11?y1"); lcd.print(gpsdata);
}
// ********************************/
/********************************
if (gpsdata == 0 && newdata == 0) {
lcd.print("?x00?y0no gps data!!!!!");
lcd.print("?x00?y1"); lcd.print(millis() / 1000);
lcd.print("?x11?y1"); lcd.print(gpsdata);
}
********************************/
}
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > tinyGPS - trying to output status
arduino
Comments
Post a Comment