Go Down

Topic: Interfacing problems with Dual Adafruit Ultimate GPS modules @10Hz with Teensy 3 (Read 391 times) previous topic - next topic

churay

May 18, 2018, 11:32 pm Last Edit: May 18, 2018, 11:53 pm by churay Reason: Clarification and addition of program behaviour description, typos
Hello everyone,

Excuse the crudity of this question but I'm having quite the trouble trying to run the two Adafruit Ultimate GPS v3 modules at 10Hz on the Teensy 3.2 board. The modules are connected over the hardware serial ports 1 and 3. There is also an IMU (MPU6050) connected over the I2C interface

Issues:

-By default, the GPS modules only run at 1Hz and at 9600 baud. I'm sending the required PMTK commands over their respective serial ports 1 and 3 to increase those to 10Hz and 115200 baud. I'm using Hardware Serial because the SoftwareSerial library was messing up the interrupts for the I2C interface and was unreliable at the baud rate required for 10Hz.

-When using the TinyGPS++ library, it seems that the received chars for the GPS 1 and 2 modules were the same, which led me to believe that it was behaving incorrectly, and I was getting no fixes. Since I also need to run a Kalman filter for each GPS module at 10Hz (which might not work at that speed on the Teensy), I switched to the NeoGPS library, which I'm told, requires much less system resources and is much faster.

-The NeoGPS library also does not return any successful fix messages due to possibly being misconfigured (I'm using the default configuration files)

Below is the code I'm using with the TinyGPS++ library (sans the IMU parts)

I begin and end each GPS serial port depending on which of them I want to read data from. This is probably causing some sort of data loss, or the gps object is retaining the data from previous reads, but I have no intuition on how to solve this.

With this, I'm only getting stars (*), and the same number of received characters for both GPS 1 and 2, hence my assumption that it is faulty;

Code: [Select]
#include <TinyGPS++.h>

    static const uint32_t GPSBaud = 115200;

    // The TinyGPS++ object
    TinyGPSPlus gps;

    void setup()
    {
      // The serial connection to the GPS device
      #define GPS_1_Serial Serial1
      #define GPS_2_Serial Serial3
      GPS_1_Serial.begin(9600);
      GPS_1_Serial.write("$PMTK220,100*2F\r\n");
     //switch the GPS baud rate to 115200
      GPS_1_Serial.write("$PMTK251,115200*27\r\n");
     //change baud rate of serial port to 38400
      GPS_1_Serial.flush();
      delay(10);
      GPS_1_Serial.end();

      GPS_2_Serial.begin(9600);
      GPS_2_Serial.write("$PMTK220,100*2F\r\n");
     //switch the GPS baud rate to 115200
      GPS_2_Serial.write("$PMTK251,115200*27\r\n");
     //change baud rate of serial port to 38400
      GPS_2_Serial.flush();
      delay(10);
      GPS_2_Serial.end();

      Serial.begin(115200);

      while (!Serial);
      Serial.println(TinyGPSPlus::libraryVersion());
      Serial.println();
      Serial.println(F("   Fix  Date       Time     Date    Course Speed Card  Chars Sentences Checksum"));
      Serial.println(F("   Age                      Age     --- from GPS ----  RX    RX        Fail"));
      Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------------"));


    }

    void loop()
    {
      static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
    //GPS________________________________________________________GPS_1___________________________________________________________________
      GPS_1_Serial.begin(GPSBaud);
      Serial.println("Listening to GPS_1");

      printDateTime(gps.date, gps.time);

      printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
      printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
      printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.deg()) : "*** ", 6);



      printInt(gps.charsProcessed(), true, 6);
      printInt(gps.sentencesWithFix(), true, 10);
      printInt(gps.failedChecksum(), true, 9);
      Serial.println();



      if (millis() > 5000 && gps.charsProcessed() < 10)
        Serial.println(F("No GPS data received: check wiring"));
      smartDelay(100);
      GPS_1_Serial.end();
    // ---------------------------------GPS_2----------------------------


      GPS_2_Serial.begin(GPSBaud);

      Serial.println("Listening to GPS_2");

      printDateTime1(gps.date, gps.time);

      printFloat1(gps.course.deg(), gps.course.isValid(), 7, 2);
      printFloat1(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
      printStr1(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.deg()) : "*** ", 6);



      printInt1(gps.charsProcessed(), true, 6);
      printInt1(gps.sentencesWithFix(), true, 10);
      printInt1(gps.failedChecksum(), true, 9);
      Serial.println();



      if (millis() > 5000 && gps.charsProcessed() < 10)
        Serial.println(F("No GPS data received: check wiring"));

      smartDelay1(100);
      GPS_2_Serial.end();


    }

    }


The printing and delay function declarations of the TinyGPS++ library were excluded for conciseness.

The NeoGPS library version I've attempted can also be found below, outputs blank lines with an if statement, when checking for valid time and location;



The complete sketch files using said libraries can be found below

Thank you for reading

Yours faithfully,
Cem Huray

churay

Hi guys,

I'm having some trouble trying to figure out how to duplicate an "instance", so to speak, of fix objects and how to switch between serial ports to read from each Adafruit Ultimate GPS module at 10Hz. I can't figure out if I have to have two fix objects or something similar to that.

When using TinyGPS++, I begin and end each serial port to read from the modules and parse the data. However, TinyGPS++ seems to buffer the data and use that instead of displaying the "Check GPS wiring" message.

I'm running on a Teensy 3.2 at 57600 baud over two hardware serials for GPS, and figured out the order of the PMTK commands I needed to send over their serial ports

Is there a way to purge the buffer? If not, how do I run two NeoGPS instances at once?

Thank you


-dev

Quote
how do I run two NeoGPS instances at once?
NeoGPS is the only library that can do this:

Code: [Select]
#include <NMEAGPS.h>

NMEAGPS gps1, gps2;
gps_fix fix1, fix2;
bool    fix1ready, fix2ready;

#define gps1port Serial1
#define gps2port Serial2

void setup()
{
  Serial.begin( 9600 );
  gps1port.begin( 9600 );
  gps2port.begin( 9600 );
}

void loop()
{
  if (gps1.available( gps1port )) {
    fix1      = gps1.read();
    fix1ready = true;
  }

  if (gps2.available( gps2port )) {
    fix2      = gps2.read();
    fix2ready = true;
  }

  if (fix1ready and fix2ready) {
    // compare fix1 and fix2?

    if (fix1.valid.time and fix2.valid.time) {
      Serial.print( fix1.dateTime.seconds );
      Serial.print( ' ' );
      Serial.println( fix2.dateTime.seconds );
    }

    fix1ready =
    fix2ready = false;
  }
}

You didn't post your sketch, so I don't know what baud rates you were using.  Change the above 9600 baud rates if necessary.
Really, I used to be /dev.  :(

surbyte


Go Up