Good evening, greetings from Thailand...
I am trying to build a GPS time/date/day display... and therefore, I have been reading many posts regarding GPS, possible libraries, how to write Sketches, what does the job, what does not work, ... and I have built a few sketches (by copying other's works and by trying things by myself) and ... finally I came up with a sketch which seems to suit my wishes...
BUT... (as in every story there is always something which does not work correctly), I am facing a little problem which I am not able to solve by myself...
Hence, I beg good willing Arduino wizards to rescue me...
First ... my code...
#include "LiquidCrystal_I2C.h"
#include <NMEAGPS.h>
NMEAGPS gps;
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address which is 0x27 for my LCD
#include <AltSoftSerial.h>
AltSoftSerial gpsPort; //( 8, 9) currently using
//#include <NeoSWSerial.h> //(for testing)
//NeoSWSerial gpsPort( 8, 9 ); //(for testing)
//SoftwareSerial gpsPort( 4, 3 ); //(for testing)
char daysOfTheWeek[7][9] = { "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
void setup() {
lcd.init(); //initialize lcd
lcd.backlight(); //open backlight //
Serial.begin(115200);
gpsPort.begin(9600);
}
void loop() {
// Dispatch incoming characters
while (gps.available(gpsPort)) {
gps_fix fix = gps.read();
if (fix.valid.date && fix.valid.time) {
// Shift the date/time to local time
NeoGPS::clock_t localSeconds;
NeoGPS::time_t localTime;
{
using namespace NeoGPS;
localSeconds = (clock_t)fix.dateTime; // convert structure to a second count
localSeconds += 7 * SECONDS_PER_HOUR + 0 * SECONDS_PER_MINUTE; // shift timezone to Thailand, Chiang Mai
localTime = localSeconds; // convert back to a structure
}
char sz1[20];
char sz2[20];
sprintf(sz1, "%02d:%02d:%02d %02d", localTime.hours, localTime.minutes, localTime.seconds, fix.satellites);
sprintf(sz2, "%02d/%02d/20%02d", localTime.date, localTime.month, localTime.year);
lcd.setCursor(1, 0); // move cursor to (0, 0)
lcd.print("Thai Time -- S Fix"); // print message at (0, 0)
lcd.setCursor(1, 1); // move cursor to (2, 1)
lcd.print(sz1); // print message at (2, 1)
lcd.setCursor(1, 2); // move cursor to (3, 2)
lcd.print(" Date:"); // print message at (3, 0)
lcd.setCursor(8, 2); // move cursor to (0, 3)
lcd.print(sz2); // print message at (0, 1)
lcd.setCursor(5, 3); // move cursor to (0, 3)
lcd.print(daysOfTheWeek[localTime.day]);
}
}
}
My problem is that somehow the Satellite counter does not seem to work correctly.
It works when I power up the NANO... for a couple of seconds I get 5 or 6 or 7 satellites inside my office (indoors, not really near a window) ... and then it quickly shows "0".
All what I want the LCD to show gets done correctly.
The red LED on the NEO board is happily blinking along (I guess 1x per second), meaning that it gets feed from satellites.
I tried to check if the NEO board was ok, and indeed, it is receiving a lot, as it should be.
The lines are well formed and look like any other "working" example I could see around.
--- below, the Sketch I used for testing the NEO board.
#include <SoftwareSerial.h>
SoftwareSerial ss(8, 9);
void setup()
{
Serial.begin(115200);
ss.begin(9600);
}
void loop() {
if (ss.available()) {
char c = ss.read();
Serial.write(c);
}
}
Therefore, could somebody please help me to get the satellite counter showing the real number of satellites...
Thank you in advance,
Eric
additional info...
NeoSWSerial.h has the same effect... (shows 4-7 satellites for a few seconds and then "0")
and SoftwareSerial does the same.