Input: Adafruit Ultimate GPS (TinyGPS++)
Output: 1.5" SPI OLED display (U8G2)
Processor: Teensy LC
My sketch basically report ( nbr sats, direction, altitude, course to home, distance to home).
If I never issue the U8G2 "Send Buffer", TinyGPS shows/updates (Serial.print), as an example, 'direction'.
Once I issue the "SendBuffer", TinyGPS always returns zero.
`// Date Written: May 5,2019
// Author: Dave Garner
// Base code is from Yvan @ https://Brainy-Bits.com
// Processor: Teensy LC
// Input Adafruit Ultimate GPS
// Output: 1.5" SPI OLED display
// This code resides in my '36 Chevy Street rod and is used to display the following
// information on a 1.5" OLED display mounted above the interior rear view mirror.
// Direction of travel
// Elevation
// Direction and distance to my home.
#include <U8g2lib.h> // U8g2 Library for Oled https://github.com/olikraus/u8g2
#include <Math.h>
#include <TinyGPS++.h>
TinyGPSPlus gps;
char CSats[3] ="00";
char CAlt[5];
char CDis[5];
char CAngle[4] ="xxx";
long IAngle ;
long IAlt;
const char *cardinalHeading ;
int StringPixilLength ;
char HomeString[10];
// static const double Home_LAT = 38.896565, Home_LON = -121.07689; // test (Aubrun CA)
static const double Home_LAT = 38.652807, Home_LON = -121.153539; // my home location
// U8g2 Library SPI, Software Serial, Full Frame Buffer mode
// rotation, clock, data, cs, dc [, reset])
U8G2_SSD1327_MIDAS_128X128_F_4W_SW_SPI u8g2(U8G2_R0 , 5, 6, 4, 3 , 2) ;
void setup()
{
Serial.begin(9600);
Serial.println("---- Fire this Baby up! 2------");
Serial1.begin(9600);
u8g2.begin();
u8g2.setContrast(200); // 0 to 255
// delay (5000) ;
}
void loop()
{
//---------------------------------------- Grab and format the satellite info -----------------------------
// Serial.print("Serial1.available() "); Serial.println(Serial1.available());
while (Serial1.available())
gps.encode(Serial1.read());
//---------------------------------------- Wait till there are at least 4 sats -----------------------------
/*
if (gps.satellites.value() < 4)
{
sprintf(CSats, "%02lu",gps.satellites.value());
// Serial.print("satellites.value--"); Serial.println(CSats);
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_fub14_tr);
u8g2.drawStr(00, 30, CSats);
u8g2.setFont(u8g2_font_fub25_tr);
u8g2.drawStr(10, 100, "No Fix!");
u8g2.sendBuffer();
}
else
//---------------------------------------- Got 4+?, grab 'em -----------------------------
{
*/
if (gps.satellites.value() > 4 )
{
sprintf(CSats, "%02lu",gps.satellites.value());
Serial.print("satellites.value--"); Serial.println(CSats);
//---------------------------------------- Grab current heading -----------------------------
IAngle = gps.course.deg();
itoa(IAngle,CAngle,10) ;
Serial.println(CAngle);
const char *cardinalHeading = TinyGPSPlus::cardinal(gps.course.deg());
Serial.println(cardinalHeading);
//---------------------------------------- Grab current elevation -----------------------------
IAlt = gps.altitude.feet();
//---------------------------------------- Grab distance, course to "home" -----------------------------
unsigned long distanceKmToHome =
(unsigned long)TinyGPSPlus::distanceBetween(
gps.location.lat(),
gps.location.lng(),
Home_LAT,
Home_LON) / 1000;
distanceKmToHome = distanceKmToHome * 0.621371;
itoa(distanceKmToHome,CDis,10) ;
double courseToHome =
TinyGPSPlus::courseTo(
gps.location.lat(),
gps.location.lng(),
Home_LAT,
Home_LON);
//---------------------------------------- Format the OLED Display -----------------------------
//----------------------------------------- number of satellites ----------------------------
u8g2.setFont(u8g2_font_fub14_tr);
u8g2.drawStr(00, 35, CSats);
u8g2.drawStr(99, 35, CAngle);
u8g2.sendBuffer();
}
}
`