GPS test code not working?

Hi,

I'm trying to make "something" that will use GPS receiver and parse NMEA data, putting some of it on a small TFT display. Being a n00b I wrote simplest piece of code I could come up with, to simply display "fix/no fix" on TFT. But it does not seem to work. Regardless of the state of the GPX I only get "Fix Error" on TFT.

#include <Wire.h>
#include <Adafruit_GPS.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>


#define TFT_CS    10
#define TFT_DC    9


Adafruit_GPS GPS(&Wire);

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, -1);

void setup() {
  
  Wire.begin();
  GPS.begin(0x10);  
  
  tft.init(240, 240);
  tft.setRotation(90); 
  tft.fillScreen(ST77XX_BLACK);
  
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PGCMD_ANTENNA);

  delay(1000);
}

bool lastFix = false;

void loop() {
  
  char c = GPS.read();
  
  if (GPS.newNMEAreceived()) {
    if (!GPS.parse(GPS.lastNMEA())) 
      return;
  }
  
  if (GPS.fix) {
    if (!lastFix) {
      tft.fillScreen(ST77XX_WHITE);
      lastFix = true;
    }
    tft.setTextColor(ST77XX_BLACK);
    tft.setTextSize(4);
    tft.setCursor(10, 10);
    tft.print("Fix Achieved"); 
    
  } else {
    if (lastFix) {
      tft.setCursor(0, 0);
      tft.fillScreen(ST77XX_BLACK);
      lastFix = false;
    }
    tft.setTextColor(ST77XX_WHITE);
    tft.setTextSize(3);
    tft.setCursor(10, 10);
    tft.print("Fix Error");
  }

  delay(1000);
}

You will have better luck if you state what you expected to happen and what happened instead,

The very best way to get started with a new library is to run one of the library examples. Studying the example, and perhaps even the library docs, you will notice one or two major errors, starting here:

  char c = GPS.read();
  
  if (GPS.newNMEAreceived()) {
1 Like

Thank you.

The examples did run without issues and GPS data is parsed.

I did write what was the expected outcome: on fix display "Fix Achieved" otherwise "Fix Error".

Much appreciate the suggestion to read documents again, I'm sure it will be very informative. This forum has already proven a boon of information and friendly to boot.

@Admin, if any - you can close this thread, the kind man resolved the question by stating "it does not work because there are error". I had zero idea it was the case.

Topics usually don't get closed (1)(2). You can mark your topic as solved by clicking the little checkbox under @jremington's post to indicate that it gave the solution.

(1) Topics get automatically closed after 6 months.
(2) Topics can get closed if they run out of hand (insults etc) although they usually get cleaned up in an attempt to keep this community friendly.

1 Like

In fact, the code is working perfectly, exactly as written. It will not report a fix because it does not process any GPS data.

If you can't take any time to study the example code and library documentation, you aren't likely to find much sympathy on this forum.

How unsurprising to, once again, in the expanse of WWW see a snide know-it-all chime in as a first-responder, without anything sensible to say and an attitude of "I know better than anyone else" to boot. Another booming echo in a chamber, but as the great author wrote ""It is a tale told by an idiot, full of sound and fury, signifying nothing."

I sincerely hope next time you go to a doctor, or call a plumber, or just go into a building supplies store and ask for opinion, help or advice you will be responded with the same smug "OH!!! but it's OBVIOUS! if only you... "fill in the blank" duh...!!!"

Please accept my utmost apology for disturbing your peace of mind and inducing a feeling of such righteous indignation in your soul, jremingron. I will tirelessly work to improve myself and I have only you to thank for opening my eyes to the this fault of my character - actually daring to ask a question and then attracting attention of a twat.

I sincerely hope rest of you days will be just as productive and contributing to community as the recent ones, although one may hold doubts - a brief read of your history reveals nothing but a carefully curtailed selection of snide, mockery and generally unhelpful replies that on any forum with decent moderation would get you told off - which in essence says a lot about this one! But then it is the essence of internet - a place where everyone and find an accepting community. So I won't in the least begrudge this.

With this, I bid you Adieu! but please, don't let this stop you from having a last word - I'm sure it will give you a warm and fuzzy feeling and good night's sleep.