Wow, that sketch was pretty old. The new way of getting a fix from the gps object is to call gps.read()
, not gps.fix()
. With the old code, it was always using just the RMC, which does not have the fix.satellites
value.
Here is your sketch with that mod:
/*
Motorcycle (GPS) Speedometer
*/
#include <TinyWireM.h>
#include <USI_TWI_Master.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSerif9pt7b.h>
#include <Fonts/FreeSansBold18pt7b.h>
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <NeoSWSerial.h>
NeoSWSerial gps_port(4, 3); // ASSIGNS PINS 3, 4 FOR GPS RX/TX
#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);
void setup() {
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.setFont(&FreeSerif9pt7b);
//display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(27, 22);
display.println( F("Mini-GPS"));
display.display(); // SEND SPLASH SCREEN
delay(2000); // WAIT 2 SECONDS
display.clearDisplay();
display.setFont(&FreeSerif9pt7b);
//display.setTextSize(0.8);
display.setCursor(55, 12);
display.print( F("By"));
display.setTextSize(0.8);
display.setCursor(15, 26);
display.print( F("Nick Sebring"));
display.display(); // SEND SPLASH SCREEN
delay(5000); // WAIT 10 SECONDS
// Insert text when no GPS signal received... ***********************
//display.clearDisplay();
//display.setCursor(2, 50);
//display.print( F("Serching satellites."));
//display.display(); // SEND SPLASH SCREEN
}
void loop()
{
if (gps.available( gps_port )) {
gps_fix fix = gps.read();
display.clearDisplay(); //CLEAR THE OLED BUFFER, THUS CLEARING THE SCREEN: GOT IT!
// construct data to be sent to the OLED *****************************
display.setFont(); //reset font to default
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.print( F("Sat: "));
if (fix.valid.satellites) {
display.setCursor(60, 20);
display.println( fix.satellites );
}
if (fix.valid.date && fix.valid.time) {
NeoGPS::clock_t seconds = (NeoGPS::clock_t) fix.dateTime; // convert pieces to seconds
// Calculate DST changeover times just once per year
static NeoGPS::clock_t springTime, fallTime;
static NeoGPS::time_t changeover;
if ((springTime == 0) || (changeover.year != fix.dateTime.year)) {
changeover.year = fix.dateTime.year;
changeover.month = 3;
changeover.date = 14; // latest 2nd Sunday
changeover.hours = 2;
changeover.minutes = 0;
changeover.seconds = 0;
changeover.set_day();
// Step back to the 2nd Sunday, if day != SUNDAY
changeover.date -= (changeover.day - NeoGPS::time_t::SUNDAY);
springTime = (NeoGPS::clock_t) changeover;
changeover.month = 11;
changeover.date = 7; // latest 1st Sunday
changeover.set_day();
// Step back to the 1st Sunday, if day != SUNDAY
changeover.date -= (changeover.day - NeoGPS::time_t::SUNDAY);
fallTime = (NeoGPS::clock_t) changeover;
}
NeoGPS::clock_t tz = 5; // THIS IS WHERE YOU PUT IN YOUR LOCAL TIME ZONE
if ((springTime <= seconds) && (seconds < fallTime))
tz--;
seconds -= tz * 60 * 60; // offset seconds to local timezone, including DST
NeoGPS::time_t localTime( seconds ); // convert seconds back to pieces
display.setCursor(95, 0);
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.setFont(&FreeSansBold18pt7b);
display.setTextSize(1);
display.setCursor(38, 30);
display.println( fix.speed_mph(), 0);
}
// display.setTextSize(1);
// display.setCursor(10, 57);
// if (fix.valid.location) {
// display.print(fix.latitude(), 4);
// display.print( F(", ") );
// display.print(fix.longitude(), 4);
display.display();
}
}
It compiles for me, but I could only test a version without the display code.
Cheers,
/dev