Hello,
I'm having lots of trouble using SoftwareSerial to communicate with my GPS module (Locosys LS20031). I'm running the example script from the Arduiniana TinyGPS site:
#include <TinyGPS.h>
#include <SoftwareSerial.h>
TinyGPS gps;
SoftwareSerial mySerial(4,5); // RX, TX
long lat, lon;
unsigned long fix_age, time, date, speed, course;
void setup()
{
Serial.begin(57600);
mySerial.begin(57600);
}
void loop()
{
while (mySerial.available())
{
int c = mySerial.read();
if (gps.encode(c))
{
// process new gps info here
// retrieves +/- lat/long in 100000ths of a degree
gps.get_position(&lat, &lon, &fix_age);
// course in 100ths of a degree
course = gps.course();
//Output info via USB
Serial.print("Latitude=");
Serial.println(lat);
Serial.print("Longitude=");
Serial.println(lon);
Serial.print("Age=");
Serial.println(fix_age);
Serial.print("Course=");
Serial.println(course);
}
}
}
The Serial monitor shows blank. The gps.encode() never returns true meaning I'm not getting good sentences. However if I remove the SoftwareSerial class and just listen to the GPS on pin 0 and print with the Serial class it works fine:
#include <TinyGPS.h>
//#include <SoftwareSerial.h>
TinyGPS gps;
//SoftwareSerial mySerial(4,5); // RX, TX
long lat, lon;
unsigned long fix_age, time, date, speed, course;
void setup()
{
Serial.begin(57600);
// mySerial.begin(57600);
}
void loop()
{
while (Serial.available())
{
int c = Serial.read();
if (gps.encode(c))
{
// process new gps info here
// retrieves +/- lat/long in 100000ths of a degree
gps.get_position(&lat, &lon, &fix_age);
// course in 100ths of a degree
course = gps.course();
//Output info via USB
Serial.print("Latitude=");
Serial.println(lat);
Serial.print("Longitude=");
Serial.println(lon);
Serial.print("Age=");
Serial.println(fix_age);
Serial.print("Course=");
Serial.println(course);
}
}
}
Before this project is complete I'm going to want to send some control bits back to the GPS, so I can't get by without SoftwareSerial or some other solution. Does anyone have suggestions?