So I'm working with a Teensy 3.2, it has three serial ports. I'm using SoftwareSerial. I read on other topics that if you want to use two ports, SoftwareSerial won't be that good, which is true. Because the data of both GPS modules are mixed together when I run my code.
So my question is: How can I properly receive data from both GPS modules in one program?
And I am not sure if this has any added importance, but I'll be experimenting with the data and create a new NMEA sentence to send it elsewhere. If I'm right, this wouldn't affect the receiving piece of the code, right?
My cheat card for Teensy 3.2 says that the hardware serial ports are Serial1, Serial2 and Serial3. I'd use two and three for your GPS units and use Serial1 for debugging
wildbill:
My cheat card for Teensy 3.2 says that the hardware serial ports are Serial1, Serial2 and Serial3. I'd use two and three for your GPS units and use Serial1 for debugging
What do you mean with debugging by using Serial1? I'm currently using RX0 and TX0 for GPS1. RX3 and TX3 for GPS2. But how should I write this in my code?
Your code will be the same as it was using a software serial instance except you'll use Serial1 and Serial3 and you won't need to specify the RX, TX pins because the teensy already knows which is which.
As for debugging, usually you will want to see stuff on the serial monitor while you figure out why your code isn't working. I suspect Serial1 does that, so you might want to move the GPS to Serial2.
wildbill:
Your code will be the same as it was using a software serial instance except you'll use Serial1 and Serial3 and you won't need to specify the RX, TX pins because the teensy already knows which is which.
As for debugging, usually you will want to see stuff on the serial monitor while you figure out why your code isn't working. I suspect Serial1 does that, so you might want to move the GPS to Serial2.
Thank you for your clear explanation, I'll check it out soon!
I used Serial2 and Serial3, they both work perfect when I test them seperately. The problem is that I receive data very very very slowly when I let both of the gps print out data. How can I still receive both of the data with their usual speed?
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
TinyGPSPlus gps;
void setup() {
// Serial1.begin(4800);
Serial2.begin(4800);
Serial3.begin(4800);
}
void loop() {
while (Serial2.available() > 0)
if (gps.encode(Serial2.read()))
displayInfo1();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
while (Serial3.available() > 0)
if (gps.encode(Serial3.read()))
displayInfo2();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
}
void displayInfo1()
{
Serial.print(F("GPS1: "));
Serial.print(F("Locatie: "));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}
if (gps.speed.isValid())
{
Serial.print(F(" Knopen="));
Serial.print(gps.speed.knots());
Serial.print(F(" m/s="));
Serial.print(gps.speed.mps());
Serial.print(F(" km/h="));
Serial.print(gps.speed.kmph());
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" TIJD "));
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour());
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.print(gps.time.centisecond());
}
else
{
Serial.print(F("INVALID"));
}
Serial.println();
}
void displayInfo2()
{
Serial.print(F("GPS2: "));
Serial.print(F("Locatie: "));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}
if (gps.speed.isValid())
{
Serial.print(" Knopen=");
Serial.print(gps.speed.knots());
Serial.print(" m/s=");
Serial.print(gps.speed.mps());
Serial.print(" km/h=");
Serial.print(gps.speed.kmph());
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(" TIJD ");
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print("0");
Serial.print(gps.time.hour());
Serial.print(":");
if (gps.time.minute() < 10) Serial.print("0");
Serial.print(gps.time.minute());
Serial.print(":");
if (gps.time.second() < 10) Serial.print("0");
Serial.print(gps.time.second());
Serial.print(".");
if (gps.time.centisecond() < 10) Serial.print("0");
Serial.print(gps.time.centisecond());
}
else
{
Serial.print(F("INVALID"));
}
Serial.println();
}