GPS Not Providing data via TX RX Pins

I have a Photon connected to my GPS Mini NEO-7N Satellite Positioning Module. Ive connected to the 3.3v power supply, GND and GPS RX -> Photon TX and GPS TX -> Photon RX.

I had it working last night however it isn’t now. I’ve used the GPS module on my Arduino and it works so I know its functioning as well it working on my Photon last night, however no longer does it seem to. Here is my code:


#include <TinyGPS++.h>
#include "Particle.h"

void displayInfo(); 

const unsigned long PUBLISH_PERIOD = 120000;

TinyGPSPlus gps;
unsigned long lastPublish = 0;

void setup()
{
	Serial.begin(9600);
	Serial1.begin(9600);
}

void loop()
{
    char buf[128];
	while (Serial1.available() > 0) {
	    Particle.publish("DEBUG", "Serial is Available");
	    snprintf(buf, sizeof(buf), "Latitude: %f,Longitude: %f", gps.location.lat(), gps.location.lng());
	    Particle.publish("gps", buf);
	    delay(1000);
		if (gps.encode(Serial1.read())) {
			displayInfo();
		}
	}

}

void displayInfo()
{
			char buf[128];
			Particle.publish("DEBUG", "DisplayInfoFunc");
			if (gps.location.isValid()) {
			    Particle.publish("DEBUG", "GPS VALID");
				snprintf(buf, sizeof(buf), "Latitude: %f,Longitude: %f", gps.location.lat(), gps.location.lng());
				Particle.publish("gps", "GPS DATA");
				Particle.publish("gps", buf);
			}
			else {
				Particle.publish("gps", "no location");
			}
}

if (gps.encode(Serial1.read())) is there an obvious reason what would cause this line to return false?

You can look into the implementation of the library you are using, but most likely that’s because there wasn’t a full NMEA sencence found yet.
After all Serial1.read() only reads one single byte.

I joined your other thread with this, since there is no need to open a new thread for this one-liner question - and it’s realated to the origianl GPS question anyway.

1 Like

Yes, what ScruffR said.

This block of code is not good:

	    Particle.publish("DEBUG", "Serial is Available");
	    snprintf(buf, sizeof(buf), "Latitude: %f,Longitude: %f", gps.location.lat(), gps.location.lng());
	    Particle.publish("gps", buf);
	    delay(1000);

Data arrives one byte of time from the GPS, and you’re reading one byte every second at most. Since many of the GPS sentences are 50+ bytes each, the serial buffer will overflow and you’ll never get valid data from the GPS. Also, you’re exceeding the publish rate by 2x.

Just delete that entire block of code. It’s already publishing the complete result in displayInfo, where it should be.

3 Likes