Gps wing helpppp!

So i am currently using this code to detect lat and long from my adafruit gps (https://blog.particle.io/2019/05/17/learn-how-to-build-this-cellular-asset-tracker-with-a-particle-boron/). However the current code has OLED. for my use case i do not need an OLED on my tracker. Can someone help and tell me which code to remove just to keep the necessary code to get updates on my Lat and long. -ps: i tried editing the code and removing anything related to the OLED but i did not work! it flashed but i can find the lat or long in my events console!!


// dependencies.AssetTrackerRK=0.1.7
// dependencies.oled-wing-adafruit=0.0.5


// Port of TinyGPS for the Particle AssetTracker
// https://github.com/mikalhart/TinyGPSPlus
#include "TinyGPS++.h"

#include "oled-wing-adafruit.h"

SYSTEM_THREAD(ENABLED);

/*
   This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object directly.
 */

void displayInfo(); // forward declaration

const unsigned long PUBLISH_PERIOD = 15000;
const unsigned long SERIAL_PERIOD = 5000;
const unsigned long MAX_GPS_AGE_MS = 10000; // GPS location must be newer than this to be considered valid

// The TinyGPS++ object
TinyGPSPlus gps;
unsigned long lastSerial = 0;
unsigned long lastPublish = 0;
unsigned long startFix = 0;
bool gettingFix = false;

OledWingAdafruit display;


void setup()
{
    Serial.begin(9600);
    
    // The GPS module on the AssetTracker is connected to Serial1 and D6
    Serial1.begin(9600);

    // Settings D6 LOW powers up the GPS module
    pinMode(D6, OUTPUT);
    digitalWrite(D6, LOW);
    startFix = millis();
    gettingFix = true;

    display.setup();
    display.clearDisplay();
    display.display();
}

void loop()
{
    display.loop();

    while (Serial1.available() > 0) {
        if (gps.encode(Serial1.read())) {
            displayInfo();
        }
    }

}

void displayInfo()
{
    if (millis() - lastSerial >= SERIAL_PERIOD) {
        lastSerial = millis();

        char buf[128];
        char pubbuf[120];
        if (gps.location.isValid() && gps.location.age() < MAX_GPS_AGE_MS) {


            display.clearDisplay();
            display.setTextSize(2);
            display.setTextColor(WHITE);
            display.setCursor(0,0);
            snprintf(buf, sizeof(buf), "%f", gps.location.lat());
            display.println(buf);
            snprintf(buf, sizeof(buf), "%f", gps.location.lng());
            display.println(buf);
            display.display();

            snprintf(buf, sizeof(buf), "%f,%f,%f", gps.location.lat(), gps.location.lng(), gps.altitude.meters());
            snprintf(pubbuf, sizeof(pubbuf), "{\"position\": {\"value\":1, \"context\":{\"lat\": \"%f\", \"lng\": \"%f\"}}}", gps.location.lat(), gps.location.lng());
            
            Serial.println(pubbuf);
            
            if (gettingFix) {
                gettingFix = false;
                unsigned long elapsed = millis() - startFix;
                Serial.printlnf("%lu milliseconds to get GPS fix", elapsed);
            }
        }
        else {
            strcpy(buf, "no location");
            if (!gettingFix) {
                gettingFix = true;
                startFix = millis();
            }
            display.clearDisplay();
            display.setTextSize(1);
            display.setTextColor(WHITE);
            display.setCursor(0,0);
            display.println("no fix");
            display.display();
        }
        Serial.println(buf);

        if (Particle.connected()) {
            if (millis() - lastPublish >= PUBLISH_PERIOD) {
                lastPublish = millis();
                Particle.publish("gps", pubbuf, PRIVATE);
            }
        }
    }

}

Hmm, the request begs the question: How much coding experience do you have to start with?
And: Have you tried to read the code and figure what the commands may be meant to do?

Sure, we could provide a stripped down version, but then you’d still not really know what the rest does and this is not what we want to incentivise on this forum. We want to enable people to do it themselves.

Having said that, one way to approach your target would be: Anything that contains oled and display. would obviously have something to do with displaying something on an OLED. Consequently that would be a good candidate for stripping out and the rest would most likely be what you want to keep.

I really appreciate the fact that you want me to learn, for the past 2 weeks i have been learning arduino and particle references to understand the code. I finally got what setup and loop does along with functions and variables.

So thats what i did, i removed anything that mentioned OLED and which i thought wont affect the gps but it did. The code compiled and flashed without any errors however i dont see lat and long anymore in my console

/* Project GPS */


#include "Particle.h"
#include "TinyGPS++.h"
// Exectuting Setup before connecting to cloud
SYSTEM_THREAD(ENABLED); 


/*
   This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object directly.
 */

void displayInfo(); // forward declaration

const unsigned long PUBLISH_PERIOD = 15000;
const unsigned long SERIAL_PERIOD = 5000;
const unsigned long MAX_GPS_AGE_MS = 10000; // GPS location must be newer than this to be considered valid

// The TinyGPS++ object
TinyGPSPlus gps;
unsigned long lastSerial = 0;
unsigned long lastPublish = 0;
unsigned long startFix = 0;
bool gettingFix = false;

void setup()
{
    Serial.begin(9600);
    
    // The GPS module on the AssetTracker is connected to Serial1 and D6
    Serial1.begin(9600);

    // Settings D6 LOW powers up the GPS module
    pinMode(D6, OUTPUT);
    digitalWrite(D6, LOW);
    startFix = millis();
    gettingFix = true;
}
void loop(){
    while (Serial1.available() > 0) {
        if (gps.encode(Serial1.read())) {
            displayInfo();
        }
    }

}

void displayInfo()
{
    if (millis() - lastSerial >= SERIAL_PERIOD) {
        lastSerial = millis();

        char buf[128];
        char pubbuf[120];
        if (gps.location.isValid() && gps.location.age() < MAX_GPS_AGE_MS) {
            snprintf(buf, sizeof(buf), "%f,%f,%f", gps.location.lat(), gps.location.lng(), gps.altitude.meters());
            snprintf(pubbuf, sizeof(pubbuf), "{\"position\": {\"value\":1, \"context\":{\"lat\": \"%f\", \"lng\": \"%f\"}}}", gps.location.lat(), gps.location.lng());
            
            Serial.println(pubbuf);
            
            if (gettingFix) {
                gettingFix = false;
                unsigned long elapsed = millis() - startFix;
                Serial.printlnf("%lu milliseconds to get GPS fix", elapsed);
            }
        }
        else {
            strcpy(buf, "no location");
            if (!gettingFix) {
                gettingFix = true;
                startFix = millis();
            }
        Serial.println(buf);

        if (Particle.connected()) {
            if (millis() - lastPublish >= PUBLISH_PERIOD) {
                lastPublish = millis();
                Particle.publish("gps", pubbuf, PRIVATE);
            }
        }
        }
    }
}

Do you get anything via Serial (e.g. particle serial monitor --follow)?

noo so when i run ( e.g. particle serial monitor --follow ) it just shows me this, ‘Polling for available serial device…’ i tried running it multiple times and its the same outcome

Then you should get the basics straight before moving on.
Not having a serial connection with your device will make debugging of any firmware much more complicated.

So some basic questions:

  • what OS are you running on your host machine?
  • have you tried a different USB cable and port?
  • what Particle device are you using?
  • what device OS version have you got on your device?
  • what IDE are you using?
  • what does the RGB LED on your device do?

I’ll offer another hint. Your loop() never exits when Serial1 is available. loop() is called repeatedly by DeviceOS, so it should exit as quickly as possible. Your while statement should really be an if.

Since there is now a new thread (for whatever reason :confused:) this gets locked and the discussion should continue there