Try this....
#include <TinyWireM.h>
#include <USI_TWI_Master.h>
#include <Wire.h>
#include <NeoGPS_cfg.h>
#include <NMEAGPS_cfg.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <NeoSWSerial.h>
NeoSWSerial gps_port(4, 3);
#include "NMEAGPS.h"
static NMEAGPS gps; // This parses the GPS characters
// If using software SPI (the default case):
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
uint32_t timer;
void setup() {
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
Serial.begin(115200);
Serial.println( F("Acquiring a GPS signal") );
gps_port.begin(9600);
// request RMC and GGA only
gps_port.println( F("$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28") );
display.begin(SSD1306_SWITCHCAPVCC);
display.clearDisplay();
display.setTextSize(2.5);
display.setTextColor(WHITE);
display.setCursor(15, 10);
display.println( F("Mini-GPS"));
display.setTextSize(1.8);
display.setCursor(60, 35);
display.print( F("By"));
display.setTextSize(1.8);
display.setCursor(31, 50);
display.print( F("Nick Sebring"));
display.display(); // SEND SPLASH SCREEN
delay(5000); // WAIT 5 SECONDS
timer = millis();
}
void loop() // run over and over again
{
while (gps_port.available()) {
timer = millis(); // reset the timer
if (gps.decode( gps_port.read() ) == NMEAGPS::DECODE_COMPLETED) {
if (gps.nmeaMessage == NMEAGPS::NMEA_RMC) {
// If your device emits a GGA then an RMC each second,
// change the above GGA to RMC. Or if you don't get all
// the attributes (e.g., alt, heading, speed and satellites)
// try changing the above test. NMEAorder.ino can be
// used to determine which one is last (should be used above).
// BTW, this is the safest place to do any time-consuming work,
// like updating the display. Doing it elsewhere will cause GPS
// characters to be lost, and some fix data won't be available/valid.
// And if you take too long here, you could still lose characters.
uint32_t displayTime = micros(); // use this later, to figure out how long the display process takes.
display.clearDisplay(); //CLEAR THE OLED BUFFER, THUS CLEARING THE SCREEN: GOT IT!
const gps_fix & fix = gps.fix();
// construct data to be sent to the OLED *****************************
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.print( F("Satellites: "));
if (fix.valid.satellites) {
display.setCursor(70, 0);
display.println( fix.satellites );
}
if (fix.valid.date && fix.valid.time) {
display.setCursor(95, 0);
NeoGPS::clock_t seconds = (NeoGPS::clock_t) fix.dateTime; // convert pieces to seconds
seconds -= 4 * 60 * 60; // offset seconds
NeoGPS::time_t localTime( seconds ); // convert seconds back to pieces
if (localTime.hours < 10) {
display.print( '0' );
}
display.print( localTime.hours ); display.print( ':' ); // use pieces
if (localTime.minutes < 10) {
display.print( '0' );
}
display.print( localTime.minutes);
}
if (fix.valid.speed) {
display.setCursor(0, 10);
display.print( F("Speed: ")); display.print(fix.speed_mph(), 0);
display.print( F(" MPH"));
}
if (fix.valid.altitude) {
display.setCursor(0, 20);
display.print( F("Altitude: ")); display.print(fix.altitude(), 0 );
display.print( F(" FT"));
}
if (fix.valid.heading) {
display.setCursor(0, 30);
display.print( F("Heading:")); display.print(fix.heading(), 0);
}
if (fix.valid.location) {
display.setCursor(10, 40);
display.println( F("Lat/Lon (Degrees)"));
display.setCursor(10, 50);
display.print(fix.latitude(), 4);
display.print( F(", ") );
display.print(fix.longitude(), 4);
}
display.display();
Serial.print( F("dt = ") );
Serial.print( micros() - displayTime ); // How long did all that take?
Serial.println( F(" us") );
}
}
}
display.setCursor(10, 57);
display.println( F("Acquiring a GPS signal...") );
// Until we get sentences, print a dot every 2 seconds or so
if (millis() - timer > 2000) {
timer = millis(); // reset the timer
// **************************************************
Serial.print( '.' );
}
}