Original Topic: NEO-GPS sketch no-longer displays number of satellites..
I have two sketches; One displays the # of satellites, and the other does not.
The second sketch also does not display "Altitude" either. Very frustrating. The sketches pretty much look the same to me with the exception of a timer added by Slash Dev. And of course, the second sketch includes more GPS readings.
MY APOLOGIES up front: I started learning Arduino and shortly after got into building and flying drones. It is the most amazing hobby! Next to this of course.
Sketch 1 which displays the # of satellites:
/*
Motorcycle (GPS) Speedometer
*/
#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);
//SPLASH SCREEN
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 5 SECONDS
}
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(25, 0);
display.println( fix.satellites );
}
//TIME
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);
}
// Speed
if (fix.valid.speed) {
display.setFont(&FreeSansBold18pt7b);
// display.setTextSize(1);
display.setCursor(37, 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();
}
}
And the second one does not display # of satellited or Altitude Not even the text "ALT"
/*
Aircraft (GPS) Speedometer
*/
#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);
uint32_t timer;
void setup() {
gps_port.begin(9600);
// 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") );
// 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") );
bool parseDDDMM( int32_t & val, char chr );
display.begin(SSD1306_SWITCHCAPVCC);
//SPLASH SCREEN
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 5 SECONDS
}
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.
const gps_fix & fix = gps.fix();
// construct data to be sent to the OLED *****************************
display.clearDisplay();
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(25, 0);
display.println( fix.satellites );
}
//TIME
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);
}
// Speed
if (fix.valid.speed) {
display.setCursor(0, 8);
display.print( F("MPH: "));
display.println(fix.speed_mph(), 0);
}
// Heading
if (fix.valid.heading) {
display.setCursor(78, 8);
display.print( F("HDG: ")); display.print(fix.heading(), 0);
}
// Altitude
if (fix.valid.altitude) {
display.setCursor(0, 16);
display.print( F("Alt: "));
display.print(fix.altitude(), 0 );
display.print( F(" FT"));
}
//LAT
if (fix.valid.location) {
display.setCursor(0, 24);
display.print( F(""));
display.println(fix.latitude(), 6);
}
//LON
if (fix.valid.location) {
display.setCursor(70, 24);
display.print( F(" "));
display.println(fix.longitude(), 6);
}
display.display();
}
}
}
}
Thanks again as always!
NICK