Hi,
the same sketch upload to Arduino UNO got output data even not full (why just got CHARS? )? and got nothing from a MEGA2560, why?
Thanks
Adam
#include <SoftwareSerial.h>
#include <TinyGPS.h>
/* This sample code demonstrates the normal use of a TinyGPS object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
TinyGPS gps;
SoftwareSerial ss(6, 7);
void setup()
{
Serial.begin(115200);
ss.begin(4800);
Serial.print("Simple TinyGPS library v. "); Serial.println(TinyGPS::library_version());
Serial.println("by Mikal Hart");
Serial.println();
}
void loop()
{
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (ss.available())
{
char c = ss.read();
// Serial.write(c); // uncomment this line if you want to see the GPS data flowing
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
if (newData)
{
float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
Serial.print("LAT=");
Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
Serial.print(" LON=");
Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
Serial.print(" SAT=");
Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
Serial.print(" PREC=");
Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
}
gps.stats(&chars, &sentences, &failed);
Serial.print(" CHARS=");
Serial.print(chars);
Serial.print(" SENTENCES=");
Serial.print(sentences);
Serial.print(" CSUM ERR=");
Serial.println(failed);
if (chars == 0)
Serial.println("** No characters received from GPS: check wiring **");
}
You have posted enough times to know by now that you MUST STATE which GPS module you have. If the GPS works on the Uno but not on the Mega, you have made a wiring mistake.
On the Mega, use one of the other hardware serial ports, not software serial.
Thanks.
The GPS: GY-NEO6MV2 and the link below.
The reason posted here is because of I have tried all MEGA2560 TX1/2/3.
All no reading, that's why I was thing maybe something special in code?
Hello HillmanImp.
May I guess that the MEGA2560's multi-serial ports is just a gimmick?
I've used an empty sketch tested MEGA+GPS, got outputs on pin0/1 mean both devices all good. but non of the serial1.2.3 works.
That will come as a major surprise to all the folks using those 3 hardware serial ports on the Mega. Occam's Razor suggests there's a different explanation.
// multi-serial test
void setup() {
// 9600 is the baud rate to use. The baud rate determines how
// fast the communication goes.
Serial.begin(9600);
Serial1.begin(9600);
Serial2.begin(9600);
Serial3.begin(9600);
}
void loop() {
Serial.println("test Serial!");
Serial1.println("test Serial1!");
Serial2.println("test Serial2!");
Serial3.println("test Serial3!");
delay(100);
}
Thanks.
So now I got output of raw data from Serial1, and other call failed.
in the sketch below, the paragraph p1 does output, the paragraph p2 doesn't, why?
//Connect with pin 18 and 19
#include <TinyGPS.h>
#define GPSSerial Serial1
//long lat,lon; // create variable for latitude and longitude object
float lat,lon;
TinyGPS gps; // create gps object
void setup(){
Serial.begin(57600); // connect serial
Serial.println("The GPS Received Signal:");
Serial1.begin(9600); // connect gps sensor
}
void loop(){
/*
if (Serial.available()) { //////// p1
char c = Serial.read();
GPSSerial.write(c);
}
if (GPSSerial.available()) {
char c = GPSSerial.read();
Serial.write(c);
}
*/
while(Serial1.available()){ // check for gps data p2
if(gps.encode(Serial1.read()))// encode gps data
{
gps.f_get_position(&lat,&lon); // get latitude and longitude
Serial.print("Position: ");
//Latitude
Serial.print("Latitude: ");
Serial.print(lat,6);
Serial.print(",");
//Longitude
Serial.print("Longitude: ");
Serial.println(lon,6);
}
}
}