I'm having an interesting problem with what appears to be an odd interaction with U8GLIB and TinyGPS++ on a Teensy 3.1. Here is the code:
With the code as it is, I get the following output on Serial, and the display is updated when it does get good GPS data. Notice all the failed checksums.
If I comment out the UpdateDisplay() call in loop() I get the following on Serial (and of course the display isn't updated.) Note there are no failed checksums.
For some reason, the call to the U8GLIB picture loop (UpdateDisplay() function) is affecting the reading of the GPS data on Serial1.
Any ideas?
Code:
// SPI library
#include <SPI.h>
// GPS library
#include <TinyGPS++.h>
// Display library
#include <U8glib.h>
// Debugging statements to serial monitor
#define DEBUG
// Display
//U8GLIB_NHD27OLED_2X_GR u8g(10, 15); // U8GLIB_NHD27OLED_GR(cs, a0 [, reset]) - Hardware SPI 2x speed
//U8GLIB_NHD27OLED_GR u8g(10, 15); // U8GLIB_NHD27OLED_GR(cs, a0 [, reset]) - Hardware SPI
U8GLIB_NHD27OLED_GR u8g(13, 11, 10, 15); // U8GLIB_NHD27OLED_GR(sck, mosi, cs, a0 [, reset]) - Software SPI
// digital pin definitions
const int GPS_RX_PIN = 0; // GPS serial receive data
const int GPS_TX_PIN = 1; // GPS serial transmit data
const int OLEDdata = 15; // Data to OLED
// GPS/Trip
TinyGPSPlus gps;
unsigned long last = 0UL;
float latitude, longitude;
int speed, course, altitude;
// Time
int yr;
byte mo, dy, hr, mn, sc;
// End Global Variables
//
// Start setup
//
void setup() {
Serial.begin(115200);
Serial1.begin(115200); // GPS
#ifdef DEBUG
delay(4000); // testing delay
Serial.println(F("Begin setup"));
#endif
#ifdef DEBUG
Serial.println(F("Display start"));
#endif
// Start the display
u8g.begin();
u8g.setColorIndex(10); // 15 = max intensity for GR display, 1 = on for BW
u8g.setContrast(63); // 0-127
#ifdef DEBUG
Serial.println(F("Pin init"));
#endif
pinMode(OLEDdata, OUTPUT); // Data out to OLED display - SPI2_SI on NHD display
#ifdef DEBUG
Serial.println(F("End setup"));
#endif
} // End setup()
void UpdateDisplay() {
// picture loop
u8g.firstPage();
do {
DisplayDateTime();
DisplayGPS();
}
while(u8g.nextPage());
}
void loop() {
UpdateGPS();
UpdateDisplay();
}
void UpdateGPS() {
while (Serial1.available() > 0)
gps.encode(Serial1.read());
if (gps.location.isUpdated())
{
Serial.print(F("LOCATION Fix Age="));
Serial.print(gps.location.age());
Serial.print(F(" Lat="));
Serial.print(gps.location.lat(), 6);
Serial.print(F(" Long="));
Serial.println(gps.location.lng(), 6);
latitude = gps.location.lat();
longitude = gps.location.lng();
}
else if (gps.date.isUpdated())
{
Serial.print(F("DATE Fix Age="));
Serial.print(gps.date.age());
Serial.print(F(" Year="));
Serial.print(gps.date.year());
Serial.print(F(" Month="));
Serial.print(gps.date.month());
Serial.print(F(" Day="));
Serial.println(gps.date.day());
dy = gps.date.day();
mo = gps.date.month();
yr = gps.date.year();
}
else if (gps.time.isUpdated())
{
Serial.print(F("TIME Fix Age="));
Serial.print(gps.time.age());
Serial.print(F(" Hour="));
Serial.print(gps.time.hour());
Serial.print(F(" Minute="));
Serial.print(gps.time.minute());
Serial.print(F(" Second="));
Serial.println(gps.time.second());
hr = gps.time.hour();
mn = gps.time.minute();
sc = gps.time.second();
}
else if (gps.speed.isUpdated())
{
Serial.print(F("SPEED Fix Age="));
Serial.print(gps.speed.age());
Serial.print(F(" MPH="));
Serial.println(gps.speed.mph());
speed = gps.speed.mph();
}
else if (gps.course.isUpdated())
{
Serial.print(F("COURSE Fix Age="));
Serial.print(gps.course.age());
Serial.print(F(" Deg="));
Serial.println(gps.course.deg());
course = gps.course.deg();
}
else if (gps.altitude.isUpdated())
{
Serial.print(F("ALTITUDE Fix Age="));
Serial.print(gps.altitude.age());
Serial.print(F(" Feet="));
Serial.println(gps.altitude.feet());
altitude = gps.altitude.feet();
}
else if (millis() - last > 5000)
{
Serial.println();
if (gps.location.isValid())
Serial.print(F("DIAGS Chars="));
Serial.print(gps.charsProcessed());
Serial.print(F(" Sentences-with-Fix="));
Serial.print(gps.sentencesWithFix());
Serial.print(F(" Failed-checksum="));
Serial.print(gps.failedChecksum());
Serial.print(F(" Passed-checksum="));
Serial.println(gps.passedChecksum());
if (gps.charsProcessed() < 10)
Serial.println(F("WARNING: No GPS data. Check wiring."));
last = millis();
Serial.println();
}
}
void DisplayGPS() {
// Print the MPH
if (speed < 2) { // Show the speed as 0 if < 2 due to GPS error
speed = 0;
}
u8g.setFont(u8g_font_ncenR24n);
if (speed < 10 ) {
u8g.setPrintPos(56, 40);
}
else if (speed < 100 && speed >= 10 ) {
u8g.setPrintPos(49, 40);
}
else {
u8g.setPrintPos(42, 40);
}
u8g.print(speed);
// Print the heading
u8g.setFont(u8g_font_10x20r);
u8g.setPrintPos(53, 13);
u8g.print(course);
u8g.setFont(u8g_font_tpssr);
// Print the altitude
u8g.setPrintPos(48, 53);
u8g.print(altitude,0);
// Print the lat/long
u8g.setPrintPos(0, 63);
u8g.print(latitude,6);
u8g.setPrintPos(65, 63);
u8g.print(longitude,6);
}
void DisplayDateTime() {
u8g.setFont(u8g_font_tpssr);
// display the time
if ( hr < 10 ) {
u8g.setPrintPos(6, 33);
}
else {
u8g.setPrintPos(0, 33);
}
u8g.print(hr);
u8g.setPrintPos(13, 31);
u8g.print(":");
if (mn < 10 ) {
u8g.setPrintPos(18, 33);
u8g.print("0");
u8g.setPrintPos(24, 33);
}
else {
u8g.setPrintPos(18, 33);
}
u8g.print(mn);
// display the date
if ( mo < 10 ) {
u8g.setPrintPos(6, 45);
}
else {
u8g.setPrintPos(0, 45);
}
u8g.print(mo);
u8g.setPrintPos(11, 45);
u8g.print("/");
if (dy < 10 ) {
u8g.setPrintPos(18, 45);
u8g.print("0");
u8g.setPrintPos(24, 45);
}
else {
u8g.setPrintPos(18, 45);
}
u8g.print(dy);
}
With the code as it is, I get the following output on Serial, and the display is updated when it does get good GPS data. Notice all the failed checksums.
Begin setup
Display start
Pin init
End setup
126 Sentences-with-Fix=0 Failed-checksum=0 Passed-checksum=0
634 Sentences-with-Fix=0 Failed-checksum=3 Passed-checksum=1
949 Sentences-with-Fix=0 Failed-checksum=3 Passed-checksum=1
LOCATION Fix Age=0 Lat=44.065125 Long=-121.167236
DATE Fix Age=171 Year=2014 Month=9 Day=15
TIME Fix Age=342 Hour=5 Minute=3 Second=58
SPEED Fix Age=513 MPH=0.00
COURSE Fix Age=684 Deg=0.00
DIAGS Chars=1450 Sentences-with-Fix=1 Failed-checksum=4 Passed-checksum=3
DIAGS Chars=1895 Sentences-with-Fix=1 Failed-checksum=5 Passed-checksum=3
DIAGS Chars=2277 Sentences-with-Fix=1 Failed-checksum=6 Passed-checksum=3
DIAGS Chars=2659 Sentences-with-Fix=1 Failed-checksum=6 Passed-checksum=3
LOCATION Fix Age=0 Lat=44.065129 Long=-121.167241
DATE Fix Age=171 Year=2014 Month=9 Day=15
TIME Fix Age=342 Hour=5 Minute=4 Second=18
SPEED Fix Age=513 MPH=0.01
COURSE Fix Age=684 Deg=0.00
DIAGS Chars=3070 Sentences-with-Fix=2 Failed-checksum=8 Passed-checksum=4
LOCATION Fix Age=0 Lat=44.065132 Long=-121.167240
DATE Fix Age=171 Year=2014 Month=9 Day=15
TIME Fix Age=342 Hour=5 Minute=4 Second=25
SPEED Fix Age=513 MPH=0.02
COURSE Fix Age=684 Deg=0.00
DIAGS Chars=3504 Sentences-with-Fix=3 Failed-checksum=9 Passed-checksum=6
DIAGS Chars=3886 Sentences-with-Fix=3 Failed-checksum=10 Passed-checksum=6
DIAGS Chars=4264 Sentences-with-Fix=3 Failed-checksum=11 Passed-checksum=6
If I comment out the UpdateDisplay() call in loop() I get the following on Serial (and of course the display isn't updated.) Note there are no failed checksums.
Begin setup
Display start
Pin init
End setup
LOCATION Fix Age=0 Lat=44.065073 Long=-121.167252
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=44
SPEED Fix Age=0 MPH=0.08
COURSE Fix Age=0 Deg=0.00
LOCATION Fix Age=0 Lat=44.065073 Long=-121.167252
TIME Fix Age=1 Hour=5 Minute=23 Second=44
ALTITUDE Fix Age=1 Feet=3487.86
DIAGS Chars=622 Sentences-with-Fix=2 Failed-checksum=0 Passed-checksum=9
LOCATION Fix Age=0 Lat=44.065075 Long=-121.167251
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=45
SPEED Fix Age=0 MPH=0.05
COURSE Fix Age=1 Deg=0.00
LOCATION Fix Age=0 Lat=44.065075 Long=-121.167251
TIME Fix Age=0 Hour=5 Minute=23 Second=45
ALTITUDE Fix Age=0 Feet=3488.19
LOCATION Fix Age=0 Lat=44.065077 Long=-121.167250
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=46
SPEED Fix Age=0 MPH=0.02
COURSE Fix Age=0 Deg=0.00
LOCATION Fix Age=0 Lat=44.065077 Long=-121.167250
TIME Fix Age=0 Hour=5 Minute=23 Second=46
ALTITUDE Fix Age=0 Feet=3488.52
LOCATION Fix Age=0 Lat=44.065078 Long=-121.167249
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=47
SPEED Fix Age=0 MPH=0.01
COURSE Fix Age=0 Deg=0.00
LOCATION Fix Age=0 Lat=44.065078 Long=-121.167249
TIME Fix Age=1 Hour=5 Minute=23 Second=47
ALTITUDE Fix Age=1 Feet=3488.85
LOCATION Fix Age=0 Lat=44.065080 Long=-121.167249
DATE Fix Age=1 Year=2014 Month=9 Day=15
TIME Fix Age=1 Hour=5 Minute=23 Second=48
SPEED Fix Age=1 MPH=0.02
COURSE Fix Age=1 Deg=0.00
LOCATION Fix Age=0 Lat=44.065080 Long=-121.167249
TIME Fix Age=0 Hour=5 Minute=23 Second=48
ALTITUDE Fix Age=0 Feet=3489.17
LOCATION Fix Age=0 Lat=44.065082 Long=-121.167249
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=49
SPEED Fix Age=0 MPH=0.01
COURSE Fix Age=0 Deg=0.00
LOCATION Fix Age=0 Lat=44.065082 Long=-121.167249
TIME Fix Age=0 Hour=5 Minute=23 Second=49
ALTITUDE Fix Age=0 Feet=3489.17
DIAGS Chars=3417 Sentences-with-Fix=12 Failed-checksum=0 Passed-checksum=54
LOCATION Fix Age=0 Lat=44.065083 Long=-121.167248
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=50
SPEED Fix Age=0 MPH=0.01
COURSE Fix Age=0 Deg=0.00
LOCATION Fix Age=0 Lat=44.065083 Long=-121.167248
TIME Fix Age=1 Hour=5 Minute=23 Second=50
ALTITUDE Fix Age=1 Feet=3489.50
LOCATION Fix Age=0 Lat=44.065085 Long=-121.167248
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=51
SPEED Fix Age=0 MPH=0.01
COURSE Fix Age=0 Deg=0.00
LOCATION Fix Age=0 Lat=44.065085 Long=-121.167248
TIME Fix Age=0 Hour=5 Minute=23 Second=51
ALTITUDE Fix Age=0 Feet=3489.83
LOCATION Fix Age=0 Lat=44.065087 Long=-121.167248
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=52
SPEED Fix Age=0 MPH=0.01
COURSE Fix Age=0 Deg=0.00
LOCATION Fix Age=0 Lat=44.065087 Long=-121.167248
TIME Fix Age=0 Hour=5 Minute=23 Second=52
ALTITUDE Fix Age=0 Feet=3489.83
LOCATION Fix Age=0 Lat=44.065088 Long=-121.167249
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=53
SPEED Fix Age=0 MPH=0.01
COURSE Fix Age=0 Deg=0.00
LOCATION Fix Age=0 Lat=44.065088 Long=-121.167249
TIME Fix Age=1 Hour=5 Minute=23 Second=53
ALTITUDE Fix Age=1 Feet=3490.16
LOCATION Fix Age=0 Lat=44.065089 Long=-121.167249
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=54
SPEED Fix Age=0 MPH=0.03
COURSE Fix Age=0 Deg=0.00
LOCATION Fix Age=0 Lat=44.065089 Long=-121.167249
TIME Fix Age=0 Hour=5 Minute=23 Second=54
ALTITUDE Fix Age=0 Feet=3490.16
DIAGS Chars=6212 Sentences-with-Fix=22 Failed-checksum=0 Passed-checksum=99
LOCATION Fix Age=0 Lat=44.065090 Long=-121.167249
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=55
SPEED Fix Age=0 MPH=0.01
COURSE Fix Age=0 Deg=0.00
LOCATION Fix Age=0 Lat=44.065090 Long=-121.167249
TIME Fix Age=0 Hour=5 Minute=23 Second=55
ALTITUDE Fix Age=0 Feet=3490.49
LOCATION Fix Age=0 Lat=44.065092 Long=-121.167248
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=56
SPEED Fix Age=0 MPH=0.01
COURSE Fix Age=0 Deg=0.00
LOCATION Fix Age=0 Lat=44.065092 Long=-121.167248
TIME Fix Age=0 Hour=5 Minute=23 Second=56
ALTITUDE Fix Age=0 Feet=3490.49
LOCATION Fix Age=0 Lat=44.065090 Long=-121.167251
DATE Fix Age=1 Year=2014 Month=9 Day=15
TIME Fix Age=1 Hour=5 Minute=23 Second=57
SPEED Fix Age=1 MPH=1.27
COURSE Fix Age=1 Deg=221.07
LOCATION Fix Age=0 Lat=44.065090 Long=-121.167251
TIME Fix Age=0 Hour=5 Minute=23 Second=57
ALTITUDE Fix Age=0 Feet=3491.14
LOCATION Fix Age=0 Lat=44.065090 Long=-121.167252
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=58
SPEED Fix Age=0 MPH=0.05
COURSE Fix Age=0 Deg=221.07
LOCATION Fix Age=0 Lat=44.065090 Long=-121.167252
TIME Fix Age=0 Hour=5 Minute=23 Second=58
ALTITUDE Fix Age=0 Feet=3491.80
LOCATION Fix Age=0 Lat=44.065092 Long=-121.167252
DATE Fix Age=0 Year=2014 Month=9 Day=15
TIME Fix Age=0 Hour=5 Minute=23 Second=59
SPEED Fix Age=0 MPH=0.05
COURSE Fix Age=0 Deg=221.07
LOCATION Fix Age=0 Lat=44.065092 Long=-121.167252
TIME Fix Age=0 Hour=5 Minute=23 Second=59
ALTITUDE Fix Age=0 Feet=3492.13
DIAGS Chars=9031 Sentences-with-Fix=32 Failed-checksum=0 Passed-checksum=144
For some reason, the call to the U8GLIB picture loop (UpdateDisplay() function) is affecting the reading of the GPS data on Serial1.
Any ideas?