Need Help: Simple code for GPS positioning using TinyGps doesn't work

Hi people, 

I'm trying to read Gps data using Tinygps librarie but It doesn't work.

I am using a APM1(2560) with a MTK3329. I think there is an error in RXPin and TXPin. When I run the program the console shows: [uart_gps.available() is always false] 

*___ Mi primer Gps ___* 

Andres Lopez
Iniciando Gps...
RxPin no disponible.
RxPin no disponible.
RxPin no disponible.
RxPin no disponible.
RxPin no disponible.
RxPin no disponible.

Could anyone give me comments on it? I need help.

 

--------------------------------------------------------------------------------------------------------------------------------------------------

 

// necessary libraries
#include <NewSoftSerial.h>
#include <TinyGPS.h>

#define RXPIN 4 // GPS TX pin connects to Arduino D0 (thankfully by default)
#define TXPIN 3 // GPS RX pin connects to Arduino D1. You could change these if making your own hardware
#define GPSBAUD 38400 // baud rate of our EM-406 GPS module. Change for your GPS module if different

// Create an instance of the TinyGPS object
TinyGPS gps;
// Initialize the NewSoftSerial library to the pins you defined above
NewSoftSerial uart_gps(RXPIN, TXPIN);


void getgps(TinyGPS &gps);

void setup()
{
Serial.begin(115200);

uart_gps.begin(GPSBAUD);

Serial.print("*___ Mi primer Gps ___* \r\n");
Serial.print("Andres Lopez\r\n");
delay(2000);
Serial.print("Iniciando Gps...\r\n"); 
delay(3000);
}

void loop()
{
while(uart_gps.available()) // While there is data on the RX pin...
{
Serial.print("RxPin disponible");
int c = uart_gps.read(); // load the data into a variable...
if(gps.encode(c)) // if there is a new valid sentence...
{
getgps(gps); // then grab the data, and display on LCD
}
}
Serial.print("RxPin no disponible.\r\n");
}


// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps)
{
// Define the variables that will be used
float latitude, longitude;
// Then call this function
gps.f_get_position(&latitude, &longitude);

Serial.print("Latitud: ");
Serial.print(latitude,5);
Serial.print("Longitud: ");
Serial.print(longitude,5);


// Same goes for date and time
int year;
byte month, day, hour, minute, second, hundredths;
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);

Serial.print(hour, DEC);
Serial.print(":");

if (minute<10)
{
Serial.print("0");
Serial.print(minute, DEC);
} else if (minute>=10)
{
Serial.print(minute, DEC);
}

Serial.print(":");


if (second<10)
{
Serial.print("0");
Serial.print(second, DEC);
} else if (second>=10)
{
Serial.print(second, DEC);
}

Serial.print(" ");
Serial.print(day, DEC);
Serial.print("/");
Serial.print(month, DEC);
Serial.print("/");
Serial.print(year, DEC);
Serial.print(gps.f_altitude());
Serial.print("m ");
Serial.print(gps.f_speed_kmph());
Serial.print("km/h");

// Here you can print statistics on the sentences.
unsigned long chars;
unsigned short sentences, failed_checksum;
gps.stats(&chars, &sentences, &failed_checksum);

}

 

Tags: APM, APM1, MTK3329, RXTX, arduino, gps, problem, tinygps

Views: 483

Reply to This

Social Networking

Contests

Season Two of the Trust Time Trial (T3) Contest has now begun. The fourth round is an accuracy round for multicopters, which requires contestants to fly a cube. The deadline is April 14th.

A list of all T3 contests is here

Groups

Advertisement

© 2013   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service